def test_floordiv(self): """ Test timedelta.__floordiv__ behavior.""" ts = (self.ts + 0.000001) // 2 expected = int(self.td.total_seconds() * 1000000) / 2000000.0 self.assert_ts_equal(ts, expected) ts = (self.ts + 0.000001) // meta.TS(2.0) expected = int(self.td.total_seconds() * 1000000) // 2000000 self.assertIsInstance(ts, int) self.assertEqual(ts, expected)
def test_parse_streams(self): streams = meta.from_media_info(self.media_info) self.assertEqual(len(streams), 2) video = streams[0] self.assertIsInstance(video, meta.VideoMeta) scene = meta.Scene(stream=None, start=meta.TS(0), duration=meta.TS(6.740), position=meta.TS(0)) expected = meta.VideoMeta( scenes=[scene], streams=[], duration=meta.TS(6.740), start=meta.TS(0), bitrate=4321426, width=1920, height=1080, par=1.0, dar=1.778, frame_rate=50.0, frames=337, device=None, ) self.assertEqual(expected, video) audio = streams[1] self.assertIsInstance(audio, meta.AudioMeta) scene = meta.Scene(stream=None, start=meta.TS(0), duration=meta.TS(6.742), position=meta.TS(0)) expected = meta.AudioMeta( scenes=[scene], streams=[], duration=meta.TS(6.742), start=meta.TS(0), bitrate=192000, sampling_rate=48000, channels=6, samples=323616, ) self.assertEqual(expected, audio)
def test_ts_init(self): cases = ( # from float seconds self.td.total_seconds(), # from in milliseconds int(self.td.total_seconds() * 1000), # from string '252:34:56.789000', ) for v in cases: with self.subTest(v): self.assertEqual(self.ts, meta.TS(v))
def test_truediv(self): ts = (self.ts + 0.000001) / 2 expected = int(self.td.total_seconds() * 1000000) / 2000000.0 self.assert_ts_equal(ts, expected) ts = (self.ts + 0.000001) / 2.0 expected = int(self.td.total_seconds() * 1000000) / 2000000.0 self.assert_ts_equal(ts, expected) ts = (self.ts + 0.000001) / meta.TS(2.0) expected = int(self.td.total_seconds() * 1000000) / 2000000.0 self.assertIsInstance(ts, float) self.assertAlmostEqual(ts, expected, places=5)
def setUpClass(cls) -> None: cls.td = timedelta(days=10, hours=12, minutes=34, seconds=56, microseconds=789000) cls.ts = meta.TS(cls.td.total_seconds()) ms = int(cls.td.total_seconds() * 1000) seconds = cls.td.total_seconds() string = '252:34:56.789000' cls.binary_cases = ( (cls.ts, cls.ts), (cls.ts, cls.td), (cls.ts, ms), (cls.ts, seconds), (cls.ts, string), (cls.td, cls.ts), (ms, cls.ts), (seconds, cls.ts), (string, cls.ts), )