From 2b290f520858ad21da21b51b9b12b6b326601f24 Mon Sep 17 00:00:00 2001 From: Joshua Minor Date: Tue, 8 Nov 2022 13:59:47 -0800 Subject: [PATCH] Fixing all the timecode rate tests except one... Signed-off-by: Joshua Minor --- tests/test_opentime.py | 70 ++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/tests/test_opentime.py b/tests/test_opentime.py index 5afc847b7..9029394e7 100755 --- a/tests/test_opentime.py +++ b/tests/test_opentime.py @@ -180,29 +180,30 @@ def test_long_running_timecode_24(self): def test_timecode_23976_fps(self): # This should behave exactly like 24 fps + ntsc_23976 = 24000 / 1001.0 timecode = "00:00:01:00" - t = otio.opentime.RationalTime(value=24, rate=23.976) - self.assertEqual(t, otio.opentime.from_timecode(timecode, 23.976)) + t = otio.opentime.RationalTime(value=24, rate=ntsc_23976) + self.assertEqual(t, otio.opentime.from_timecode(timecode, ntsc_23976)) timecode = "00:01:00:00" - t = otio.opentime.RationalTime(value=24 * 60, rate=23.976) - self.assertEqual(t, otio.opentime.from_timecode(timecode, 23.976)) + t = otio.opentime.RationalTime(value=24 * 60, rate=ntsc_23976) + self.assertEqual(t, otio.opentime.from_timecode(timecode, ntsc_23976)) timecode = "01:00:00:00" - t = otio.opentime.RationalTime(value=24 * 60 * 60, rate=23.976) - self.assertEqual(t, otio.opentime.from_timecode(timecode, 23.976)) + t = otio.opentime.RationalTime(value=24 * 60 * 60, rate=ntsc_23976) + self.assertEqual(t, otio.opentime.from_timecode(timecode, ntsc_23976)) timecode = "24:00:00:00" - t = otio.opentime.RationalTime(value=24 * 60 * 60 * 24, rate=23.976) - self.assertEqual(t, otio.opentime.from_timecode(timecode, 23.976)) + t = otio.opentime.RationalTime(value=24 * 60 * 60 * 24, rate=ntsc_23976) + self.assertEqual(t, otio.opentime.from_timecode(timecode, ntsc_23976)) timecode = "23:59:59:23" t = otio.opentime.RationalTime( value=24 * 60 * 60 * 24 - 1, - rate=(24000 / 1001.0) + rate=ntsc_23976 ) self.assertEqual( - t, otio.opentime.from_timecode(timecode, (24000 / 1001.0)) + t, otio.opentime.from_timecode(timecode, ntsc_23976) ) def test_converting_negative_values_to_timecode(self): @@ -298,15 +299,17 @@ def test_dropframe_timecode_2997fps(self): ] } + ntsc_2997 = otio.opentime.RationalTime.nearest_valid_timecode_rate(29.97) + self.assertEqual(ntsc_2997, 30000 / 1001.0) for time_key, time_values in test_values.items(): for value, tc in time_values: - t = otio.opentime.RationalTime(value, 29.97) + t = otio.opentime.RationalTime(value, ntsc_2997) self.assertEqual( tc, otio.opentime.to_timecode( - t, rate=29.97, drop_frame=True + t, rate=ntsc_2997, drop_frame=True ) ) - t1 = otio.opentime.from_timecode(tc, rate=29.97) + t1 = otio.opentime.from_timecode(tc, rate=ntsc_2997) self.assertEqual(t, t1) def test_timecode_ntsc_2997fps(self): @@ -353,12 +356,12 @@ def test_timecode_2997(self): (17983, '00:09:59:13', '00:10:00;01'), (17984, '00:09:59:14', '00:10:00;02'), ] - + ntsc_2997 = 30000 / 1001.0 for value, tc, dftc in ref_values: - t = otio.opentime.RationalTime(value, 29.97) - to_dftc = otio.opentime.to_timecode(t, rate=29.97, drop_frame=True) - to_tc = otio.opentime.to_timecode(t, rate=29.97, drop_frame=False) - to_auto_tc = otio.opentime.to_timecode(t, rate=29.97) + t = otio.opentime.RationalTime(value, ntsc_2997) + to_dftc = otio.opentime.to_timecode(t, rate=ntsc_2997, drop_frame=True) + to_tc = otio.opentime.to_timecode(t, rate=ntsc_2997, drop_frame=False) + to_auto_tc = otio.opentime.to_timecode(t, rate=ntsc_2997) # 29.97 should auto-detect dftc for backward compatability self.assertEqual(to_dftc, to_auto_tc) @@ -368,10 +371,10 @@ def test_timecode_2997(self): self.assertEqual(tc, to_tc) # Check they convert back - t1 = otio.opentime.from_timecode(to_dftc, rate=29.97) + t1 = otio.opentime.from_timecode(to_dftc, rate=ntsc_2997) self.assertEqual(t1, t) - t2 = otio.opentime.from_timecode(to_tc, rate=29.97) + t2 = otio.opentime.from_timecode(to_tc, rate=ntsc_2997) self.assertEqual(t2, t) def test_faulty_formatted_timecode_24(self): @@ -392,10 +395,10 @@ def test_faulty_formatted_timecode_24(self): otio.opentime.from_timecode('01:00:13;23', 24) def test_invalid_rate_to_timecode_functions(self): - t = otio.opentime.RationalTime(100, 29.98) + t = otio.opentime.RationalTime(100, 29.7) with self.assertRaises(ValueError): - otio.opentime.to_timecode(t, 29.98) + otio.opentime.to_timecode(t, 29.7) with self.assertRaises(ValueError): otio.opentime.to_timecode(t) @@ -671,36 +674,43 @@ def test_passing_ndf_tc_at_df_rate(self): DF_TC = "01:00:02;05" NDF_TC = "00:59:58:17" frames = 107957 + ntsc_2997 = otio.opentime.RationalTime.nearest_valid_timecode_rate(29.97) + self.assertEqual(ntsc_2997, 30000 / 1001.0) tc1 = otio.opentime.to_timecode( - otio.opentime.RationalTime(frames, 29.97) + otio.opentime.RationalTime(frames, ntsc_2997) ) self.assertEqual(tc1, DF_TC) tc2 = otio.opentime.to_timecode( - otio.opentime.RationalTime(frames, 29.97), - 29.97, + otio.opentime.RationalTime(frames, ntsc_2997), + ntsc_2997, drop_frame=False ) self.assertEqual(tc2, NDF_TC) - t1 = otio.opentime.from_timecode(DF_TC, 29.97) + t1 = otio.opentime.from_timecode(DF_TC, ntsc_2997) self.assertEqual(t1.value, frames) - t2 = otio.opentime.from_timecode(NDF_TC, 29.97) + t2 = otio.opentime.from_timecode(NDF_TC, ntsc_2997) self.assertEqual(t2.value, frames) def test_nearest_valid_timecode_rate(self): - invalid_valid_rates = ( + rate_pairs = ( (23.97602397602397, 24000.0 / 1001.0), (23.97, 24000.0 / 1001.0), (23.976, 24000.0 / 1001.0), (23.98, 24000.0 / 1001.0), (29.97, 30000.0 / 1001.0), (59.94, 60000.0 / 1001.0), + (24.0, 24.0), + (23.999999, 24.0), + (29.999999, 30.0), + (30.01, 30.0), + (60.01, 60.0) ) - for invalid_rate, nearest_valid_rate in invalid_valid_rates: + for invalid_rate, nearest_valid_rate in rate_pairs: self.assertTrue( otio.opentime.RationalTime.is_valid_timecode_rate( nearest_valid_rate @@ -1314,7 +1324,7 @@ def test_to_timecode_mixed_rates(self): t = otio.opentime.from_timecode(timecode, 24) self.assertEqual(timecode, otio.opentime.to_timecode(t)) self.assertEqual(timecode, otio.opentime.to_timecode(t, 24)) - self.assertNotEqual(timecode, otio.opentime.to_timecode(t, 12)) + self.assertNotEqual(timecode, otio.opentime.to_timecode(t, 48)) time1 = otio.opentime.RationalTime(24.0, 24.0) time2 = otio.opentime.RationalTime(1.0, 1.0)