Skip to content

Commit

Permalink
work around parametrize
Browse files Browse the repository at this point in the history
  • Loading branch information
OlteanuRares committed Jan 29, 2024
1 parent 4b95ab2 commit f6301a5
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 86 deletions.
64 changes: 37 additions & 27 deletions tests/test_dfxp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

from pycaption import DFXPReader, CaptionReadNoCaptions
from pycaption.exceptions import (
CaptionReadSyntaxError, InvalidInputError, CaptionReadError,
CaptionReadTimingError,
CaptionReadSyntaxError, CaptionReadError, CaptionReadTimingError,
)
from pycaption.geometry import (
UnitEnum, HorizontalAlignmentEnum, VerticalAlignmentEnum,
)
from tests.mixins import ReaderTestingMixIn
from pytest_lazyfixture import lazy_fixture


class TestDFXPReader(ReaderTestingMixIn):
Expand All @@ -19,15 +17,20 @@ def setup_class(self):
def test_positive_answer_for_detection(self, sample_dfxp):
super().assert_positive_answer_for_detection(sample_dfxp)

@pytest.mark.parametrize('different_sample', [
pytest.lazy_fixture('sample_microdvd'),
pytest.lazy_fixture('sample_sami'),
pytest.lazy_fixture('sample_scc_pop_on'),
pytest.lazy_fixture('sample_srt'),
pytest.lazy_fixture('sample_webvtt')
])
def test_negative_answer_for_detection(self, different_sample):
super().assert_negative_answer_for_detection(different_sample)
def test_negative_answer_for_microdvd(self, sample_microdvd):
super().assert_negative_answer_for_detection(sample_microdvd)

def test_negative_answer_for_sami(self, sample_sami):
super().assert_negative_answer_for_detection(sample_sami)

def test_negative_answer_for_scc_on_pop_on(self, sample_scc_pop_on):
super().assert_negative_answer_for_detection(sample_scc_pop_on)

def test_negative_answer_for_srt(self, sample_srt):
super().assert_negative_answer_for_detection(sample_srt)

def test_negative_answer_for_webvtt(self, sample_webvtt):
super().assert_negative_answer_for_detection(sample_webvtt)

def test_caption_length(self, sample_dfxp):
captions = DFXPReader().read(sample_dfxp)
Expand Down Expand Up @@ -72,23 +75,30 @@ def test_convert_timestamp_to_microseconds(self):
with pytest.raises(NotImplementedError):
reader._convert_timestamp_to_microseconds("2.3t")

@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):
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'
]
with pytest.raises(CaptionReadTimingError) as exc_info:
DFXPReader()._convert_timestamp_to_microseconds(timestamp)
for timestamp in timestamps:
DFXPReader()._convert_timestamp_to_microseconds(timestamp)

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

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


class TestSize:
@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):
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):
with pytest.raises(CaptionReadSyntaxError) as exc_info:
Size.from_string(string)
for st in ['10', '11,1px', '12xx', '%', 'o1pt']:
Size.from_string(st)

assert exc_info.value.args[0].startswith(f"Invalid size: {string}.")
assert exc_info.value.args[0].startswith(f"Invalid size: {st}.")
23 changes: 14 additions & 9 deletions tests/test_microdvd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ def setup_class(self):
def test_positive_answer_for_detection(self, sample_microdvd):
super().assert_positive_answer_for_detection(sample_microdvd)

@pytest.mark.parametrize('different_sample', [
pytest.lazy_fixture('sample_dfxp'),
pytest.lazy_fixture('sample_sami'),
pytest.lazy_fixture('sample_scc_pop_on'),
pytest.lazy_fixture('sample_srt'),
pytest.lazy_fixture('sample_webvtt')
])
def test_negative_answer_for_detection(self, different_sample):
super().assert_negative_answer_for_detection(different_sample)
def test_negative_answer_for_detection_dfxp(self, sample_dfxp):
super().assert_negative_answer_for_detection(sample_dfxp)

def test_negative_answer_for_detection_sami(self, sample_sami):
super().assert_negative_answer_for_detection(sample_sami)

def test_negative_answer_for_detection_scc_pop_on(self, sample_scc_pop_on):
super().assert_negative_answer_for_detection(sample_scc_pop_on)

def test_negative_answer_for_detection_srt(self, sample_srt):
super().assert_negative_answer_for_detection(sample_srt)

def test_negative_answer_for_detection_webvtt(self, sample_webvtt):
super().assert_negative_answer_for_detection(sample_webvtt)

def test_caption_length(self, sample_microdvd):
captions = MicroDVDReader().read(sample_microdvd)
Expand Down
23 changes: 14 additions & 9 deletions tests/test_sami.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ def setup_method(self):
def test_positive_answer_for_detection(self, sample_sami):
super().assert_positive_answer_for_detection(sample_sami)

@pytest.mark.parametrize('different_sample', [
pytest.lazy_fixture('sample_dfxp'),
pytest.lazy_fixture('sample_microdvd'),
pytest.lazy_fixture('sample_scc_pop_on'),
pytest.lazy_fixture('sample_srt'),
pytest.lazy_fixture('sample_webvtt')
])
def test_negative_answer_for_detection(self, different_sample):
super().assert_negative_answer_for_detection(different_sample)
def test_negative_answer_for_detection_dfxp(self, sample_dfxp):
super().assert_negative_answer_for_detection(sample_dfxp)

def test_negative_answer_for_detection_microdvd(self, sample_microdvd):
super().assert_negative_answer_for_detection(sample_microdvd)

def test_negative_answer_for_detection_scc_pop_on(self, sample_scc_pop_on):
super().assert_negative_answer_for_detection(sample_scc_pop_on)

def test_negative_answer_for_detection_srt(self, sample_srt):
super().assert_negative_answer_for_detection(sample_srt)

def test_negative_answer_for_detection_webvtt(self, sample_webvtt):
super().assert_negative_answer_for_detection(sample_webvtt)

def test_caption_length(self, sample_sami):
caption_set = self.reader.read(sample_sami)
Expand Down
23 changes: 14 additions & 9 deletions tests/test_scc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ def setup_method(self):
def test_positive_answer_for_detection(self, sample_scc_pop_on):
super().assert_positive_answer_for_detection(sample_scc_pop_on)

@pytest.mark.parametrize('different_sample', [
pytest.lazy_fixture('sample_dfxp'),
pytest.lazy_fixture('sample_microdvd'),
pytest.lazy_fixture('sample_sami'),
pytest.lazy_fixture('sample_srt'),
pytest.lazy_fixture('sample_webvtt')
])
def test_negative_answer_for_detection(self, different_sample):
super().assert_negative_answer_for_detection(different_sample)
def test_negative_answer_for_detection_dfxp(self, sample_dfxp):
super().assert_negative_answer_for_detection(sample_dfxp)

def test_negative_answer_for_detection_microdvd(self, sample_microdvd):
super().assert_negative_answer_for_detection(sample_microdvd)

def test_negative_answer_for_detection_sami(self, sample_sami):
super().assert_negative_answer_for_detection(sample_sami)

def test_negative_answer_for_detection_srt(self, sample_srt):
super().assert_negative_answer_for_detection(sample_srt)

def test_negative_answer_for_detection_webvtt(self, sample_webvtt):
super().assert_negative_answer_for_detection(sample_webvtt)

def test_caption_length(self, sample_scc_pop_on):
captions = SCCReader().read(sample_scc_pop_on)
Expand Down
23 changes: 14 additions & 9 deletions tests/test_srt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ def setup_class(self):
def test_positive_answer_for_detection(self, sample_srt):
super().assert_positive_answer_for_detection(sample_srt)

@pytest.mark.parametrize('different_sample', [
pytest.lazy_fixture('sample_dfxp'),
pytest.lazy_fixture('sample_microdvd'),
pytest.lazy_fixture('sample_sami'),
pytest.lazy_fixture('sample_scc_pop_on'),
pytest.lazy_fixture('sample_webvtt')
])
def test_negative_answer_for_detection(self, different_sample):
super().assert_negative_answer_for_detection(different_sample)
def test_negative_answer_for_detection_dfxp(self, sample_dfxp):
super().assert_negative_answer_for_detection(sample_dfxp)

def test_negative_answer_for_detection_microdvd(self, sample_microdvd):
super().assert_negative_answer_for_detection(sample_microdvd)

def test_negative_answer_for_detection_sami(self, sample_sami):
super().assert_negative_answer_for_detection(sample_sami)

def test_negative_answer_for_detection_scc_pop_on(self, sample_scc_pop_on):
super().assert_negative_answer_for_detection(sample_scc_pop_on)

def test_negative_answer_for_detection_webvtt(self, sample_webvtt):
super().assert_negative_answer_for_detection(sample_webvtt)

def test_caption_length(self, sample_srt):
captions = self.reader.read(sample_srt)
Expand Down
23 changes: 14 additions & 9 deletions tests/test_webvtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ def setup_method(self):
def test_positive_answer_for_detection(self, sample_webvtt):
super().assert_positive_answer_for_detection(sample_webvtt)

@pytest.mark.parametrize('different_sample', [
pytest.lazy_fixture('sample_dfxp'),
pytest.lazy_fixture('sample_microdvd'),
pytest.lazy_fixture('sample_sami'),
pytest.lazy_fixture('sample_scc_pop_on'),
pytest.lazy_fixture('sample_srt')
])
def test_negative_answer_for_detection(self, different_sample):
super().assert_negative_answer_for_detection(different_sample)
def test_negative_answer_for_detection_dfxp(self, sample_dfxp):
super().assert_negative_answer_for_detection(sample_dfxp)

def test_negative_answer_for_detection_microdvd(self, sample_microdvd):
super().assert_negative_answer_for_detection(sample_microdvd)

def test_negative_answer_for_detection_sami(self, sample_sami):
super().assert_negative_answer_for_detection(sample_sami)

def test_negative_answer_for_detection_scc_pop_on(self, sample_scc_pop_on):
super().assert_negative_answer_for_detection(sample_scc_pop_on)

def test_negative_answer_for_detection_srt(self, sample_srt):
super().assert_negative_answer_for_detection(sample_srt)

def test_caption_length(self, sample_webvtt_2):
captions = self.reader.read(sample_webvtt_2)
Expand Down

0 comments on commit f6301a5

Please sign in to comment.