Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Oct 24, 2023
1 parent f43fefd commit a5b49d9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 111 deletions.
2 changes: 0 additions & 2 deletions av/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


def main():

parser = argparse.ArgumentParser()
parser.add_argument("--codecs", action="store_true")
parser.add_argument("--version", action="store_true")
Expand All @@ -11,7 +10,6 @@ def main():
# ---

if args.version:

import av
import av._core

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


def iter_data_dirs(check_writable=False):

try:
yield os.environ["PYAV_TESTDATA_DIR"]
except KeyError:
Expand Down Expand Up @@ -45,7 +44,6 @@ def iter_data_dirs(check_writable=False):


def cached_download(url, name):

"""Download the data at a URL, and cache it under the given name.
The file is stored under `pyav/test` with the given name in the directory
Expand Down
86 changes: 38 additions & 48 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import errno
import functools
import os
import sys
import types

from av.datasets import fate as fate_suite
Expand Down Expand Up @@ -147,7 +146,7 @@ def assertNdarraysEqual(self, a, b):
a[it.multi_index],
b[it.multi_index],
)
self.fail("ndarrays contents differ\n%s" % msg)
self.fail(f"ndarrays contents differ\n{msg}")

def assertImagesAlmostEqual(self, a, b, epsilon=0.1, *args):
self.assertEqual(a.size, b.size, "sizes dont match")
Expand All @@ -156,49 +155,40 @@ def assertImagesAlmostEqual(self, a, b, epsilon=0.1, *args):
for i, ax, bx in zip(range(len(a)), a, b):
diff = sum(abs(ac / 256 - bc / 256) for ac, bc in zip(ax, bx)) / 3
if diff > epsilon:
self.fail(
"images differed by %s at index %d; %s %s" % (diff, i, ax, bx)
)

# Add some of the unittest methods that we love from 2.7.
if sys.version_info < (2, 7):

def assertIs(self, a, b, msg=None):
if a is not b:
self.fail(
msg
or "%r at 0x%x is not %r at 0x%x; %r is not %r"
% (type(a), id(a), type(b), id(b), a, b)
)

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)
)

def assertIsNone(self, x, msg=None):
if x is not None:
self.fail(msg or "is not None; %r" % x)

def assertIsNotNone(self, x, msg=None):
if x is None:
self.fail(msg or "is None; %r" % x)

def assertIn(self, a, b, msg=None):
if a not in b:
self.fail(msg or "{!r} not in {!r}".format(a, b))

def assertNotIn(self, a, b, msg=None):
if a in b:
self.fail(msg or "{!r} in {!r}".format(a, b))

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)
)

def assertNotIsInstance(self, instance, types, msg=None):
if isinstance(instance, types):
self.fail(msg or "is an instance of {!r}; {!r}".format(types, instance))
self.fail(f"images differed by {diff} at index {i}; {ax} {bx}")

def assertIs(self, a, b, msg=None):
if a is not b:
self.fail(
msg
or "%r at 0x%x is not %r at 0x%x; %r is not %r"
% (type(a), id(a), type(b), id(b), a, b)
)

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

def assertIsNone(self, x, msg=None):
if x is not None:
self.fail(msg or f"is not None; {x!r}")

def assertIsNotNone(self, x, msg=None):
if x is None:
self.fail(msg or f"is None; {x!r}")

def assertIn(self, a, b, msg=None):
if a not in b:
self.fail(msg or f"{a!r} not in {b!r}")

def assertNotIn(self, a, b, msg=None):
if a in b:
self.fail(msg or f"{a!r} in {b!r}")

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

def assertNotIsInstance(self, instance, types, msg=None):
if isinstance(instance, types):
self.fail(msg or f"is an instance of {types!r}; {instance!r}")
59 changes: 0 additions & 59 deletions tests/test_doctests.py

This file was deleted.

0 comments on commit a5b49d9

Please sign in to comment.