|
3 | 3 |
|
4 | 4 | from timecode import Timecode, TimecodeError |
5 | 5 |
|
| 6 | +import random |
6 | 7 |
|
7 | 8 | @pytest.mark.parametrize( |
8 | 9 | "args,kwargs", [ |
@@ -999,6 +1000,34 @@ def test_rollover_for_23_98(): |
999 | 1000 | assert 2071873 == tc.frames |
1000 | 1001 | assert "23:58:48:00" == tc.__repr__() |
1001 | 1002 |
|
| 1003 | +@pytest.mark.parametrize( |
| 1004 | + "framerate", [ |
| 1005 | + "23.976", "23.98", "24", "25", "29.97", "30", "50", "59.94", "60", "ms" |
| 1006 | + ] |
| 1007 | +) |
| 1008 | +def test_float_representation_roundtrip(framerate): |
| 1009 | + """Test float representation of Timecode.""" |
| 1010 | + mismatched = 0 |
| 1011 | + # Close enough to max frame across our supported framerates. |
| 1012 | + num_frames = Timecode(framerate, "23:59:59;23").frame_number |
| 1013 | + max_samples = 50_000 |
| 1014 | + |
| 1015 | + if num_frames <= max_samples: |
| 1016 | + frames_to_test = range(1, num_frames) |
| 1017 | + else: |
| 1018 | + # Not the most efficient sample allocation, but our range is pretty small. |
| 1019 | + random.seed(42) # Fixed seed for repeatability |
| 1020 | + frames_to_test = sorted(random.sample(range(1, num_frames), max_samples)) |
| 1021 | + |
| 1022 | + for i in frames_to_test: |
| 1023 | + tc = Timecode(framerate, frames=i) |
| 1024 | + from_float = Timecode(framerate, start_seconds=tc.float) |
| 1025 | + if tc != from_float: |
| 1026 | + mismatched += 1 |
| 1027 | + |
| 1028 | + tested = len(frames_to_test) |
| 1029 | + assert mismatched == 0, f"{mismatched}/{tested} ({mismatched / tested * 100:.1f}%) incorrect (sampled {tested} of {num_frames} total frames)" |
| 1030 | + |
1002 | 1031 |
|
1003 | 1032 | @pytest.mark.parametrize( |
1004 | 1033 | "args,kwargs,str_repr", [ |
|
0 commit comments