From f6301a53ea465571b94ecfcca87b325ec76df0ee Mon Sep 17 00:00:00 2001 From: OlteanuRares Date: Mon, 29 Jan 2024 13:26:12 +0200 Subject: [PATCH 1/3] work around parametrize --- tests/test_dfxp.py | 64 ++++++++++++++++++++++++------------------ tests/test_geometry.py | 29 ++++++++++--------- tests/test_microdvd.py | 23 +++++++++------ tests/test_sami.py | 23 +++++++++------ tests/test_scc.py | 23 +++++++++------ tests/test_srt.py | 23 +++++++++------ tests/test_webvtt.py | 23 +++++++++------ 7 files changed, 122 insertions(+), 86 deletions(-) diff --git a/tests/test_dfxp.py b/tests/test_dfxp.py index 8294a3f3..df3a0320 100644 --- a/tests/test_dfxp.py +++ b/tests/test_dfxp.py @@ -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): @@ -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) @@ -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): diff --git a/tests/test_geometry.py b/tests/test_geometry.py index 597bbd78..426191ce 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -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}.") diff --git a/tests/test_microdvd.py b/tests/test_microdvd.py index 7921b3c5..657b03f3 100644 --- a/tests/test_microdvd.py +++ b/tests/test_microdvd.py @@ -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) diff --git a/tests/test_sami.py b/tests/test_sami.py index 9b07d059..66748475 100644 --- a/tests/test_sami.py +++ b/tests/test_sami.py @@ -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) diff --git a/tests/test_scc.py b/tests/test_scc.py index dc5a0ed0..25a6abd4 100644 --- a/tests/test_scc.py +++ b/tests/test_scc.py @@ -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) diff --git a/tests/test_srt.py b/tests/test_srt.py index edeeab0c..3aedbede 100644 --- a/tests/test_srt.py +++ b/tests/test_srt.py @@ -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) diff --git a/tests/test_webvtt.py b/tests/test_webvtt.py index 14e149e6..87739cb3 100644 --- a/tests/test_webvtt.py +++ b/tests/test_webvtt.py @@ -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) From a8ce9805d94e1234af6c5e74e1a6dbb585d134ac Mon Sep 17 00:00:00 2001 From: OlteanuRares Date: Mon, 29 Jan 2024 13:38:14 +0200 Subject: [PATCH 2/3] remove lazy_fixtures --- test_requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/test_requirements.txt b/test_requirements.txt index 8ef1ace3..c9532a43 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,6 +1,5 @@ pytest pytest-cov -pytest-lazy-fixture beautifulsoup4>=4.12.1 lxml>=4.9.1 cssutils>=2.0.0 \ No newline at end of file From 1f76a3537f39b91a4598bd104c22ead59664ed87 Mon Sep 17 00:00:00 2001 From: OlteanuRares Date: Mon, 29 Jan 2024 15:41:31 +0200 Subject: [PATCH 3/3] rollback to parametrize usage --- tests/test_dfxp.py | 36 +++++++++++++----------------------- tests/test_geometry.py | 29 ++++++++++++++--------------- 2 files changed, 27 insertions(+), 38 deletions(-) diff --git a/tests/test_dfxp.py b/tests/test_dfxp.py index df3a0320..c3e1136a 100644 --- a/tests/test_dfxp.py +++ b/tests/test_dfxp.py @@ -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): diff --git a/tests/test_geometry.py b/tests/test_geometry.py index 426191ce..447a85c0 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -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}.") \ No newline at end of file