Skip to content

Commit

Permalink
rollback to parametrize usage
Browse files Browse the repository at this point in the history
  • Loading branch information
OlteanuRares committed Jan 29, 2024
1 parent a8ce980 commit 1f76a35
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 38 deletions.
36 changes: 13 additions & 23 deletions tests/test_dfxp.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,20 @@ def test_convert_timestamp_to_microseconds(self):
with pytest.raises(NotImplementedError):
reader._convert_timestamp_to_microseconds("2.3t")

def test_clock_time(self):
timestamp_mapp = {
'12:23:34': 44614000000,
'23:34:45:56': 84886866666,
'34:45:56.7': 125156700000,
'13:24:35.67': 48275670000,
'24:35:46.456': 88546456000,
'1:23:34': 5014000000
}
for timestamp in timestamp_mapp:
assert DFXPReader()._convert_timestamp_to_microseconds(
timestamp) == timestamp_mapp.get(timestamp)

def test_invalid_timestamp(self):
timestamps = [
'1:1:11', '1:11:1', '1:11:11:1', '11:11:11:11.11', '11:11:11,11',
'11.11.11.11', '11:11:11.', 'o1:11:11'
]
@pytest.mark.parametrize('timestamp, microseconds', [
('12:23:34', 44614000000), ('23:34:45:56', 84886866666),
('34:45:56.7', 125156700000), ('13:24:35.67', 48275670000),
('24:35:46.456', 88546456000), ('1:23:34', 5014000000)])
def test_clock_time(self, timestamp, microseconds):
assert DFXPReader()._convert_timestamp_to_microseconds(
timestamp) == microseconds

@pytest.mark.parametrize('timestamp', [
'1:1:11', '1:11:1', '1:11:11:1', '11:11:11:11.11', '11:11:11,11',
'11.11.11.11', '11:11:11.', 'o1:11:11'])
def test_invalid_timestamp(self, timestamp):
with pytest.raises(CaptionReadTimingError) as exc_info:
for timestamp in timestamps:
DFXPReader()._convert_timestamp_to_microseconds(timestamp)

assert exc_info.value.args[0].startswith(
f'Invalid timestamp: {timestamp}.')
DFXPReader()._convert_timestamp_to_microseconds(timestamp)

def test_empty_file(self, sample_dfxp_empty):
with pytest.raises(CaptionReadNoCaptions):
Expand Down
29 changes: 14 additions & 15 deletions tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,19 @@ def test_layout_is_relative(self):


class TestSize:
def test_valid_size_from_string(self):
strings = ['1px', '2.3em', '12.34%', '1.234c', '10pt', '0']
values = [1.0, 2.3, 12.34, 1.234, 10, 0.0]
units = [UnitEnum.PIXEL, UnitEnum.EM, UnitEnum.PERCENT, UnitEnum.CELL, UnitEnum.PT, UnitEnum.PIXEL]

for idx, str in enumerate(strings):
size = Size.from_string(str)

assert size.value == values[idx]
assert size.unit == units[idx]

def test_invalid_size_from_string(self):
@pytest.mark.parametrize('string, value, unit', [
('1px', 1.0, UnitEnum.PIXEL), ('2.3em', 2.3, UnitEnum.EM),
('12.34%', 12.34, UnitEnum.PERCENT), ('1.234c', 1.234, UnitEnum.CELL),
('10pt', 10.0, UnitEnum.PT), ('0', 0.0, UnitEnum.PIXEL)])
def test_valid_size_from_string(self, string, value, unit):
size = Size.from_string(string)

assert size.value == value
assert size.unit == unit

@pytest.mark.parametrize('string', ['10', '11,1px', '12xx', '%', 'o1pt'])
def test_invalid_size_from_string(self, string):
with pytest.raises(CaptionReadSyntaxError) as exc_info:
for st in ['10', '11,1px', '12xx', '%', 'o1pt']:
Size.from_string(st)
Size.from_string(string)

assert exc_info.value.args[0].startswith(f"Invalid size: {st}.")
assert exc_info.value.args[0].startswith(f"Invalid size: {string}.")

0 comments on commit 1f76a35

Please sign in to comment.