From 4c01198ce9da4b383db514768c928d37e8f26efd Mon Sep 17 00:00:00 2001 From: jbannon Date: Tue, 12 Apr 2022 04:23:52 +0000 Subject: [PATCH] update unit tests --- tests/unit/entries/conftest.py | 9 ++++----- tests/unit/entries/test_entry.py | 11 ----------- .../validators/test_string_formatter_validator.py | 11 +++++++++++ ytdl_subscribe/entries/entry.py | 15 --------------- 4 files changed, 15 insertions(+), 31 deletions(-) diff --git a/tests/unit/entries/conftest.py b/tests/unit/entries/conftest.py index cd7877fe..146c1b07 100644 --- a/tests/unit/entries/conftest.py +++ b/tests/unit/entries/conftest.py @@ -154,13 +154,12 @@ def validate_entry_dict_contains_valid_formatters(): def _validate_entry_dict_contains_valid_formatters(entry: Entry): for key, value in entry.to_dict().items(): expected_string = f"test {value} formatting works" - format_string = f"test {{{key}}} formatting works" - - assert ( - entry.apply_formatter(StringFormatterValidator(name="test", value=format_string)) - == expected_string + formatter = StringFormatterValidator( + name="test", value=f"test {{{key}}} formatting works" ) + assert formatter.apply_formatter(entry.to_dict()) == expected_string + return True return _validate_entry_dict_contains_valid_formatters diff --git a/tests/unit/entries/test_entry.py b/tests/unit/entries/test_entry.py index 79f94f5b..0b603dd8 100644 --- a/tests/unit/entries/test_entry.py +++ b/tests/unit/entries/test_entry.py @@ -39,14 +39,3 @@ class TestEntry(object): assert mock_entry.kwargs_contains(key) is False with pytest.raises(KeyError, match=expected_error_msg): mock_entry.kwargs(key) - - def test_entry_formatter_fails_missing_field(self, mock_entry): - format_string = StringFormatterValidator(name="test", value=f"prefix {{bah_humbug}} suffix") - available_fields = ", ".join(sorted(mock_entry.to_dict().keys())) - expected_error_msg = ( - f"Validation error in test: Format variable 'bah_humbug' does not exist. " - f"Available variables: {available_fields}" - ) - - with pytest.raises(StringFormattingException, match=expected_error_msg): - assert mock_entry.apply_formatter(format_string) diff --git a/tests/unit/validators/test_string_formatter_validator.py b/tests/unit/validators/test_string_formatter_validator.py index 5280a8e9..04df1425 100644 --- a/tests/unit/validators/test_string_formatter_validator.py +++ b/tests/unit/validators/test_string_formatter_validator.py @@ -89,6 +89,17 @@ class TestStringFormatterValidator(object): with pytest.raises(ValidationException, match=expected_error_msg): _ = StringFormatterValidator(name="fail", value=format_string) + def test_entry_formatter_fails_missing_field(self): + format_string = StringFormatterValidator(name="test", value=f"prefix {{bah_humbug}} suffix") + variable_dict = {"varb": "a", "vara": "b"} + expected_error_msg = ( + f"Validation error in test: Format variable 'bah_humbug' does not exist. " + f"Available variables: {', '.join(sorted(variable_dict.keys()))}" + ) + + with pytest.raises(StringFormattingException, match=expected_error_msg): + assert format_string.apply_formatter(variable_dict=variable_dict) + def test_string_formatter_single_field(self): uid = "this uid" format_string = StringFormatterValidator(name="test", value=f"prefix {{uid}} suffix") diff --git a/ytdl_subscribe/entries/entry.py b/ytdl_subscribe/entries/entry.py index 71256929..8bc97b71 100644 --- a/ytdl_subscribe/entries/entry.py +++ b/ytdl_subscribe/entries/entry.py @@ -63,21 +63,6 @@ class BaseEntry(ABC): "extractor": self.extractor, } - def apply_formatter( - self, - formatter: StringFormatterValidator, - overrides: Optional[OverridesValidator] = None, - ) -> str: - """ - Perform a string format on the given format string, using the entry's dict for format - values. The override dict will overwrite any values within the entry's dict. - """ - entry_dict = self.to_dict() - if overrides: - entry_dict = dict(entry_dict, **overrides.dict_with_format_strings) - - return formatter.apply_formatter(variable_dict=entry_dict) - class Entry(BaseEntry): """