Skip to content

Commit

Permalink
black tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Oct 15, 2023
1 parent a36ab58 commit 8e86ab3
Show file tree
Hide file tree
Showing 20 changed files with 7 additions and 83 deletions.
8 changes: 6 additions & 2 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ def assertIs(self, a, b, msg=None):

def assertIsNot(self, a, b, msg=None):
if a is b:
self.fail(msg or "both are {!r} at 0x{:x}; {!r}".format(type(a), id(a), a))
self.fail(
msg or "both are {!r} at 0x{:x}; {!r}".format(type(a), id(a), a)
)

def assertIsNone(self, x, msg=None):
if x is not None:
Expand All @@ -193,7 +195,9 @@ def assertNotIn(self, a, b, msg=None):

def assertIsInstance(self, instance, types, msg=None):
if not isinstance(instance, types):
self.fail(msg or "not an instance of {!r}; {!r}".format(types, instance))
self.fail(
msg or "not an instance of {!r}; {!r}".format(types, instance)
)

def assertNotIsInstance(self, instance, types, msg=None):
if isinstance(instance, types):
Expand Down
5 changes: 1 addition & 4 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
autopep8
Cython
editorconfig
flake8
isort
numpy
Pillow
sphinx < 4.4
Pillow
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 @@ -117,15 +117,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 @@ -134,7 +132,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 @@ -159,7 +156,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 @@ -184,7 +180,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 @@ -246,7 +241,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 @@ -277,9 +271,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 @@ -323,7 +315,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 @@ -358,7 +349,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:

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 @@ -7,9 +7,7 @@


def fix_doctests(suite):

for case in suite._tests:

# Add some more flags.
case._dt_optionflags = (
(case._dt_optionflags or 0)
Expand All @@ -24,14 +22,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
12 changes: 0 additions & 12 deletions tests/test_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def define_foobar(self, **kwargs):
)

def test_basics(self):

cls = self.define_foobar()

self.assertIsInstance(cls, EnumType)
Expand All @@ -36,7 +35,6 @@ def test_basics(self):
self.assertNotIsInstance(foo, PickleableFooBar)

def test_access(self):

cls = self.define_foobar()
foo1 = cls.FOO
foo2 = cls["FOO"]
Expand All @@ -58,7 +56,6 @@ def test_access(self):
self.assertIs(cls.get("not a foo"), None)

def test_casting(self):

cls = self.define_foobar()
foo = cls.FOO

Expand All @@ -77,7 +74,6 @@ def test_iteration(self):
self.assertEqual(list(cls), [cls.FOO, cls.BAR])

def test_equality(self):

cls = self.define_foobar()
foo = cls.FOO
bar = cls.BAR
Expand All @@ -94,7 +90,6 @@ def test_equality(self):
self.assertRaises(TypeError, lambda: foo == ())

def test_as_key(self):

cls = self.define_foobar()
foo = cls.FOO

Expand All @@ -104,7 +99,6 @@ def test_as_key(self):
self.assertIs(d.get(1), None)

def test_pickleable(self):

cls = PickleableFooBar
foo = cls.FOO

Expand All @@ -115,15 +109,13 @@ def test_pickleable(self):
self.assertIs(foo, foo2)

def test_create_unknown(self):

cls = self.define_foobar()
baz = cls.get(3, create=True)

self.assertEqual(baz.name, "FOOBAR_3")
self.assertEqual(baz.value, 3)

def test_multiple_names(self):

cls = define_enum(
"FFooBBar",
__name__,
Expand All @@ -147,7 +139,6 @@ def test_multiple_names(self):
self.assertRaises(ValueError, lambda: cls.F == "x")

def test_flag_basics(self):

cls = define_enum(
"FoobarAllFlags",
__name__,
Expand Down Expand Up @@ -178,7 +169,6 @@ def test_flag_basics(self):
self.assertIs(x, cls.FOO)

def test_multi_flags_basics(self):

cls = self.define_foobar(is_flags=True)

foo = cls.FOO
Expand All @@ -202,7 +192,6 @@ def test_multi_flags_basics(self):
self.assertEqual(list(cls), [foo, bar])

def test_multi_flags_create_missing(self):

cls = self.define_foobar(is_flags=True)

foobar = cls[3]
Expand All @@ -212,7 +201,6 @@ def test_multi_flags_create_missing(self):
self.assertRaises(KeyError, lambda: cls[7]) # FOO and BAR and missing flag.

def test_properties(self):

Flags = self.define_foobar(is_flags=True)
foobar = Flags.FOO | Flags.BAR

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

class TestErrorBasics(TestCase):
def test_stringify(self):

for cls in (av.ValueError, av.FileNotFoundError, av.DecoderNotFoundError):
e = cls(1, "foo")
self.assertEqual(str(e), "[Errno 1] foo")
Expand All @@ -34,7 +33,6 @@ def test_stringify(self):
)

def test_bases(self):

self.assertTrue(issubclass(av.ValueError, ValueError))
self.assertTrue(issubclass(av.ValueError, av.FFmpegError))

Expand Down
Loading

0 comments on commit 8e86ab3

Please sign in to comment.