Skip to content

Commit

Permalink
modernized unittest assertions (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
reinecke authored and ssteinbach committed Nov 8, 2016
1 parent e1fd7eb commit 4ee8aa1
Show file tree
Hide file tree
Showing 12 changed files with 322 additions and 313 deletions.
34 changes: 18 additions & 16 deletions tests/test_adapter_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class TestPluginAdapters(unittest.TestCase):
def test_plugin_adapter(self):
jsn = baseline_reader.json_baseline_as_string(ADAPTER_PATH)
adp = otio.adapters.otio_json.read_from_string(jsn)
self.assertEquals(adp.name, "example")
self.assertEquals(adp.execution_scope, "in process")
self.assertEquals(adp.filepath, "example.py")
self.assertEquals(adp.suffixes, ["EXAMPLE"])
self.assertEqual(adp.name, "example")
self.assertEqual(adp.execution_scope, "in process")
self.assertEqual(adp.filepath, "example.py")
self.assertEqual(adp.suffixes, ["EXAMPLE"])

def test_load_adapter_module(self):
jsn = baseline_reader.json_baseline_as_string(ADAPTER_PATH)
Expand All @@ -34,9 +34,9 @@ def test_load_adapter_module(self):
target = os.path.join(baseline_reader.MODPATH,
"baseline", "example.py")

self.assertEquals(adp.module_abs_path(), target)
self.assertEqual(adp.module_abs_path(), target)
self.assertTrue(hasattr(adp.module(), "read_from_file"))
self.assertEquals(adp.module().read_from_file("foo").name, "foo")
self.assertEqual(adp.module().read_from_file("foo").name, "foo")

MAN_PATH = '/var/tmp/test_otio_manifest'

Expand All @@ -56,26 +56,28 @@ class TestPluginManifest(unittest.TestCase):
def test_plugin_manifest(self):
man = test_manifest()

self.assertEquals(man.source_files, [MAN_PATH])
self.assertEqual(man.source_files, [MAN_PATH])

self.assertNotEquals(man.adapters, [])
self.assertNotEqual(man.adapters, [])

def test_find_adapter_by_suffix(self):
man = test_manifest()
self.assertEquals(man.from_filepath("EXAMPLE").name, "example")
self.assertRaises(lambda: man.from_filepath("BLARG"))
self.assertEqual(man.from_filepath("EXAMPLE").name, "example")
with self.assertRaises(Exception):
man.from_filepath("BLARG")
adp = man.from_filepath("EXAMPLE")
self.assertEquals(adp.module().read_from_file("path").name, "path")
self.assertEquals(man.adapter_module_from_suffix(
self.assertEqual(adp.module().read_from_file("path").name, "path")
self.assertEqual(man.adapter_module_from_suffix(
"EXAMPLE").read_from_file("path").name, "path")

def test_find_adapter_by_name(self):
man = test_manifest()
self.assertEquals(man.from_name("example").name, "example")
self.assertRaises(lambda: man.from_name("BLARG"))
self.assertEqual(man.from_name("example").name, "example")
with self.assertRaises(Exception):
man.from_name("BLARG")
adp = man.from_name("example")
self.assertEquals(adp.module().read_from_file("path").name, "path")
self.assertEquals(man.adapter_module_from_name(
self.assertEqual(adp.module().read_from_file("path").name, "path")
self.assertEqual(man.adapter_module_from_name(
"example").read_from_file("path").name, "path")

if __name__ == '__main__':
Expand Down
59 changes: 30 additions & 29 deletions tests/test_builtin_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,83 +26,83 @@ def test_disk_io(self):
otiotmp = tempfile.mkstemp(suffix=".otio", text=True)[1]
otio.adapters.write_to_file(timeline, otiotmp)
decoded = otio.adapters.read_from_file(otiotmp)
self.assertEquals(timeline, decoded)
self.assertEqual(timeline, decoded)

def test_edl_read(self):
edl_path = SCREENING_EXAMPLE_PATH
timeline = otio.adapters.read_from_file(edl_path)
self.failUnless(timeline is not None)
self.assertEquals(len(timeline.tracks), 1)
self.assertEquals(len(timeline.tracks[0]), 9)
self.assertEquals(
self.assertTrue(timeline is not None)
self.assertEqual(len(timeline.tracks), 1)
self.assertEqual(len(timeline.tracks[0]), 9)
self.assertEqual(
timeline.tracks[0][0].name,
"ZZ100_501 (LAY3)"
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][0].source_range.duration,
otio.opentime.from_timecode("00:00:01:07")
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][1].name,
"ZZ100_502A (LAY3)"
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][1].source_range.duration,
otio.opentime.from_timecode("00:00:02:02")
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][2].name,
"ZZ100_503A (LAY1)"
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][2].source_range.duration,
otio.opentime.from_timecode("00:00:01:04")
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][3].name,
"ZZ100_504C (LAY1)"
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][3].source_range.duration,
otio.opentime.from_timecode("00:00:04:19")
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][4].name,
"ZZ100_504B (LAY1)"
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][4].source_range.duration,
otio.opentime.from_timecode("00:00:04:05")
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][5].name,
"ZZ100_507C (LAY2)"
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][5].source_range.duration,
otio.opentime.from_timecode("00:00:06:17")
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][6].name,
"ZZ100_508 (LAY2)"
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][6].source_range.duration,
otio.opentime.from_timecode("00:00:07:02")
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][7].name,
"ZZ100_510 (LAY1)"
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][7].source_range.duration,
otio.opentime.from_timecode("00:00:05:16")
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][8].name,
"ZZ100_510B (LAY1)"
)
self.assertEquals(
self.assertEqual(
timeline.tracks[0][8].source_range.duration,
otio.opentime.from_timecode("00:00:10:17")
)
Expand Down Expand Up @@ -147,14 +147,14 @@ def test_edl_round_trip(self):
otio.adapters.write_to_string(new_otio, adapter_name="otio_json"),
otio.adapters.write_to_string(tl, adapter_name="otio_json")
)
self.assertEquals(new_otio, tl)
self.assertEqual(new_otio, tl)

def test_read_cmx(self):
tl = otio.adapters.read_from_file(SCREENING_EXAMPLE_PATH, "cmx_3600")

baseline_json = otio.adapters.otio_json.write_to_string(tl)

self.assertEquals(tl.name, "Example_Screening.01")
self.assertEqual(tl.name, "Example_Screening.01")

otio.adapters.otio_json.write_to_file(tl, "/var/tmp/test.otio")
new = otio.adapters.otio_json.read_from_file(
Expand All @@ -164,7 +164,7 @@ def test_read_cmx(self):
new_json = otio.adapters.otio_json.write_to_string(new)

self.assertMultiLineEqual(baseline_json, new_json)
self.assertEquals(tl, new)
self.assertEqual(tl, new)

def test_edl_disk_vs_string(self):
""" Writing to disk and writing to a string should
Expand All @@ -175,15 +175,16 @@ def test_edl_disk_vs_string(self):
edltmp = tempfile.mkstemp(suffix=".edl", text=True)[1]
otio.adapters.write_to_file(timeline, edltmp)
in_memory = otio.adapters.write_to_string(timeline, 'cmx_3600')
on_disk = open(edltmp, 'r').read()
with open(edltmp, 'r') as f:
on_disk = f.read()

self.assertEquals(in_memory, on_disk)
self.assertEqual(in_memory, on_disk)

def test_adapters_fetch(self):
""" Test the dynamic string based adapter fetching """
printer = otio.adapters.from_name('pretty_print_string')
self.assertEquals(printer.module(), pretty_print_string)
self.assertEquals(
self.assertEqual(printer.module(), pretty_print_string)
self.assertEqual(
otio.adapters.from_name('cmx_3600').module(),
cmx_3600
)
Expand Down
20 changes: 10 additions & 10 deletions tests/test_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ def test_cons(self):
# transition_in
# transition_out
)
self.assertEquals(cl.name, name)
self.assertEquals(cl.source_range, tr)
self.assertEquals(cl.media_reference, mr)
self.assertEquals(cl.source_range, tr)
self.assertEqual(cl.name, name)
self.assertEqual(cl.source_range, tr)
self.assertEqual(cl.media_reference, mr)
self.assertEqual(cl.source_range, tr)

encoded = otio.adapters.otio_json.write_to_string(cl)
decoded = otio.adapters.otio_json.read_from_string(encoded)
self.assertEquals(cl, decoded)
self.assertEqual(cl, decoded)

def test_each_clip(self):
cl = otio.schema.Clip(name="test_clip")
self.assertEquals(list(cl.each_clip()), [cl])
self.assertEqual(list(cl.each_clip()), [cl])

def test_str(self):
cl = otio.schema.Clip(name="test_clip")
Expand Down Expand Up @@ -91,15 +91,15 @@ def test_computed_duration(self):
available_range=tr
)
)
self.assertEquals(cl.duration(), cl.computed_duration())
self.assertEquals(cl.duration(), tr.duration)
self.assertEqual(cl.duration(), cl.computed_duration())
self.assertEqual(cl.duration(), tr.duration)
cl.source_range = otio.opentime.TimeRange(
# 1 hour + 100 frames
start_time=otio.opentime.RationalTime(86500, 24),
duration=otio.opentime.RationalTime(50, 24)
)
self.assertNotEquals(cl.duration(), tr.duration)
self.assertEquals(cl.duration(), cl.source_range.duration)
self.assertNotEqual(cl.duration(), tr.duration)
self.assertEqual(cl.duration(), cl.source_range.duration)

if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit 4ee8aa1

Please sign in to comment.