Skip to content

Commit

Permalink
Reformat Python code with black, and enforce it in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaine committed Oct 30, 2023
1 parent 1f991fa commit d2e750f
Show file tree
Hide file tree
Showing 25 changed files with 1 addition and 76 deletions.
2 changes: 0 additions & 2 deletions examples/basics/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@
codec = av.CodecContext.create("h264", "r")

while True:

chunk = fh.read(1 << 16)

packets = codec.parse(chunk)
print("Parsed {} packets from {} bytes:".format(len(packets), len(chunk)))

for packet in packets:

print(" ", packet)

frames = codec.decode(packet)
Expand Down
1 change: 0 additions & 1 deletion examples/basics/remux.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
out_stream = output.add_stream(template=in_stream)

for packet in input_.demux(in_stream):

print(packet)

# We need to skip the "flushing" packets that `demux` generates.
Expand Down
1 change: 0 additions & 1 deletion examples/basics/save_keyframes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
stream.codec_context.skip_frame = "NONKEY"

for frame in container.decode(stream):

print(frame)

# We use `frame.pts` as `frame.index` won't make must sense with the `skip_frame`.
Expand Down
1 change: 0 additions & 1 deletion examples/numpy/barcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

columns = []
for frame in container.decode(video=0):

print(frame)
array = frame.to_ndarray(format="rgb24")

Expand Down
1 change: 0 additions & 1 deletion examples/numpy/generate_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
stream.pix_fmt = "yuv420p"

for frame_i in range(total_frames):

img = np.empty((480, 320, 3))
img[:, :, 0] = 0.5 + 0.5 * np.sin(2 * np.pi * (0 / 3 + frame_i / total_frames))
img[:, :, 1] = 0.5 + 0.5 * np.sin(2 * np.pi * (1 / 3 + frame_i / total_frames))
Expand Down
1 change: 0 additions & 1 deletion examples/numpy/generate_video_with_pts.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
block_h2 = int(0.5 * height / 4)

for frame_i in range(total_frames):

# move around the color wheel (hue)
nice_color = colorsys.hsv_to_rgb(frame_i / total_frames, 1.0, 1.0)
nice_color = (np.array(nice_color) * 255).astype(np.uint8)
Expand Down
2 changes: 1 addition & 1 deletion scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ istest() {
}

if istest black; then
$PYAV_PYTHON -m black av examples tests
$PYAV_PYTHON -m black --check av examples tests
fi

if istest flake8; then
Expand Down
5 changes: 0 additions & 5 deletions tests/test_audiofifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

class TestAudioFifo(TestCase):
def test_data(self):

container = av.open(fate_suite("audio-reference/chorusnoise_2ch_44kHz_s16.wav"))
stream = container.streams.audio[0]

Expand All @@ -31,7 +30,6 @@ def test_data(self):
self.assertTrue(input_[:min_len] == output[:min_len])

def test_pts_simple(self):

fifo = av.AudioFifo()

iframe = av.AudioFrame(samples=1024)
Expand Down Expand Up @@ -61,7 +59,6 @@ def test_pts_simple(self):
self.assertRaises(ValueError, fifo.write, iframe)

def test_pts_complex(self):

fifo = av.AudioFifo()

iframe = av.AudioFrame(samples=1024)
Expand All @@ -79,7 +76,6 @@ def test_pts_complex(self):
self.assertEqual(fifo.pts_per_sample, 2.0)

def test_missing_sample_rate(self):

fifo = av.AudioFifo()

iframe = av.AudioFrame(samples=1024)
Expand All @@ -96,7 +92,6 @@ def test_missing_sample_rate(self):
self.assertEqual(oframe.time_base, iframe.time_base)

def test_missing_time_base(self):

fifo = av.AudioFifo()

iframe = av.AudioFrame(samples=1024)
Expand Down
3 changes: 0 additions & 3 deletions tests/test_audioresampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def test_matching_passthrough(self):
self.assertEqual(len(oframes), 0)

def test_pts_assertion_same_rate(self):

resampler = AudioResampler("s16", "mono")

# resample one frame
Expand Down Expand Up @@ -115,7 +114,6 @@ def test_pts_assertion_same_rate(self):
self.assertEqual(len(oframes), 0)

def test_pts_assertion_new_rate(self):

resampler = AudioResampler("s16", "mono", 44100)

# resample one frame
Expand Down Expand Up @@ -144,7 +142,6 @@ def test_pts_assertion_new_rate(self):
self.assertEqual(oframe.samples, 16)

def test_pts_missing_time_base(self):

resampler = AudioResampler("s16", "mono", 44100)

# resample one frame
Expand Down
10 changes: 0 additions & 10 deletions tests/test_codec_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,13 @@ def test_encoder_pix_fmt(self):
self.assertEqual(ctx.pix_fmt, "yuv420p")

def test_parse(self):

# This one parses into a single packet.
self._assert_parse("mpeg4", fate_suite("h264/interlaced_crop.mp4"))

# This one parses into many small packets.
self._assert_parse("mpeg2video", fate_suite("mpeg2/mpeg2_field_encoding.ts"))

def _assert_parse(self, codec_name, path):

fh = av.open(path)
packets = []
for packet in fh.demux(video=0):
Expand All @@ -137,7 +135,6 @@ def _assert_parse(self, codec_name, path):
full_source = b"".join(bytes(p) for p in packets)

for size in 1024, 8192, 65535:

ctx = Codec(codec_name).create()
packets = []

Expand All @@ -162,7 +159,6 @@ def test_encoding_tiff(self):
self.image_sequence_encode("tiff")

def image_sequence_encode(self, codec_name):

try:
codec = Codec(codec_name, "w")
except UnknownCodecError:
Expand All @@ -187,7 +183,6 @@ def image_sequence_encode(self, codec_name):
frame_count = 1
path_list = []
for frame in iter_frames(container, video_stream):

new_frame = frame.reformat(width, height, pix_fmt)
new_packets = ctx.encode(new_frame)

Expand Down Expand Up @@ -249,7 +244,6 @@ def test_encoding_dnxhd(self):
self.video_encoding("dnxhd", options)

def video_encoding(self, codec_name, options={}, codec_tag=None):

try:
codec = Codec(codec_name, "w")
except UnknownCodecError:
Expand Down Expand Up @@ -280,9 +274,7 @@ def video_encoding(self, codec_name, options={}, codec_tag=None):
frame_count = 0

with open(path, "wb") as f:

for frame in iter_frames(container, video_stream):

new_frame = frame.reformat(width, height, pix_fmt)

# reset the picture type
Expand Down Expand Up @@ -326,7 +318,6 @@ def test_encoding_mp2(self):
self.audio_encoding("mp2")

def audio_encoding(self, codec_name):

try:
codec = Codec(codec_name, "w")
except UnknownCodecError:
Expand Down Expand Up @@ -361,7 +352,6 @@ def audio_encoding(self, codec_name):

with open(path, "wb") as f:
for frame in iter_frames(container, audio_stream):

resampled_frames = resampler.resample(frame)
for resampled_frame in resampled_frames:
samples += resampled_frame.samples
Expand Down
5 changes: 0 additions & 5 deletions tests/test_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class TestDecode(TestCase):
def test_decoded_video_frame_count(self):

container = av.open(fate_suite("h264/interlaced_crop.mp4"))
video_stream = next(s for s in container.streams if s.type == "video")

Expand Down Expand Up @@ -40,7 +39,6 @@ def test_decode_audio_corrupt(self):
self.assertEqual(frame_count, 0)

def test_decode_audio_sample_count(self):

container = av.open(fate_suite("audio-reference/chorusnoise_2ch_44kHz_s16.wav"))
audio_stream = next(s for s in container.streams if s.type == "audio")

Expand All @@ -58,7 +56,6 @@ def test_decode_audio_sample_count(self):
self.assertEqual(sample_count, total_samples)

def test_decoded_time_base(self):

container = av.open(fate_suite("h264/interlaced_crop.mp4"))
stream = container.streams.video[0]

Expand All @@ -71,7 +68,6 @@ def test_decoded_time_base(self):
return

def test_decoded_motion_vectors(self):

container = av.open(fate_suite("h264/interlaced_crop.mp4"))
stream = container.streams.video[0]
codec_context = stream.codec_context
Expand All @@ -88,7 +84,6 @@ def test_decoded_motion_vectors(self):
return

def test_decoded_motion_vectors_no_flag(self):

container = av.open(fate_suite("h264/interlaced_crop.mp4"))
stream = container.streams.video[0]

Expand Down
2 changes: 0 additions & 2 deletions tests/test_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def foo(self, a, b):

def test_renamed_attr(self):
class Example(object):

new_value = "foo"
old_value = deprecation.renamed_attr("new_value")

Expand All @@ -35,7 +34,6 @@ def new_func(self, a, b):
obj = Example()

with warnings.catch_warnings(record=True) as captured:

self.assertEqual(obj.old_value, "foo")
self.assertIn(
"Example.old_value is deprecated", captured[0].message.args[0]
Expand Down
1 change: 0 additions & 1 deletion tests/test_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

class TestDictionary(TestCase):
def test_basics(self):

d = Dictionary()
d["key"] = "value"

Expand Down
4 changes: 0 additions & 4 deletions tests/test_doctests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@


def fix_doctests(suite):

for case in suite._tests:

# Add some more flags.
case._dt_optionflags = (
(case._dt_optionflags or 0)
Expand All @@ -25,14 +23,12 @@ def fix_doctests(suite):
)

for example in case._dt_test.examples:

# Remove b prefix from strings.
if example.want.startswith("b'"):
example.want = example.want[1:]


def register_doctests(mod):

if isinstance(mod, str):
mod = __import__(mod, fromlist=[""])

Expand Down
3 changes: 0 additions & 3 deletions tests/test_encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


def write_rgb_rotate(output):

if not Image:
raise SkipTest()

Expand All @@ -29,7 +28,6 @@ def write_rgb_rotate(output):
stream.pix_fmt = "yuv420p"

for frame_i in range(DURATION):

frame = VideoFrame(WIDTH, HEIGHT, "rgb24")
image = Image.new(
"RGB",
Expand Down Expand Up @@ -64,7 +62,6 @@ def write_rgb_rotate(output):


def assert_rgb_rotate(self, input_, is_dash=False):

# Now inspect it a little.
self.assertEqual(len(input_.streams), 1)
if is_dash:
Expand Down
Loading

0 comments on commit d2e750f

Please sign in to comment.