diff --git a/docs/info/release-history.rst b/docs/info/release-history.rst index 99ed735a..9fb6c674 100644 --- a/docs/info/release-history.rst +++ b/docs/info/release-history.rst @@ -32,11 +32,19 @@ The format is based on `Keep a Changelog `_, and this project adheres to `Semantic Versioning `_ +1.1.10 +====== + +Fixed +----- +* Bug in :py:class:`.Comparer` methods which caused them to fail on invalid expected values + + 1.1.9 ===== Changed ------ +------- * :py:class:`.Comparer` now correctly ignores the reference track given when the ``reference_required`` flag is False. Fixed diff --git a/musify/processors/compare.py b/musify/processors/compare.py index fae8335c..526aa1b5 100644 --- a/musify/processors/compare.py +++ b/musify/processors/compare.py @@ -199,6 +199,8 @@ def _get_seconds(time_str: str) -> float: @dynamicprocessormethod def _is(self, value: Any | None, expected: Sequence[Any] | None) -> bool: + if expected is None: + return False return value == expected[0] @dynamicprocessormethod @@ -207,15 +209,19 @@ def _is_not(self, value: Any | None, expected: Sequence[Any] | None) -> bool: @dynamicprocessormethod("greater_than", "in_the_last") def _is_after(self, value: Any | None, expected: Sequence[Any] | None) -> bool: - return value > expected[0] if value is not None and expected[0] is not None else False + if value is None or expected is None or expected[0] is None: + return False + return value > expected[0] @dynamicprocessormethod("less_than", "not_in_the_last") def _is_before(self, value: Any | None, expected: Sequence[Any] | None) -> bool: - return value < expected[0] if value is not None and expected[0] is not None else False + if value is None or expected is None or expected[0] is None: + return False + return value < expected[0] @dynamicprocessormethod def _is_in(self, value: Any | None, expected: Sequence[Any] | None) -> bool: - return value in expected + return expected is not None and value in expected @dynamicprocessormethod def _is_not_in(self, value: Any | None, expected: Sequence[Any] | None) -> bool: @@ -223,7 +229,9 @@ def _is_not_in(self, value: Any | None, expected: Sequence[Any] | None) -> bool: @dynamicprocessormethod def _in_range(self, value: Any | None, expected: Sequence[Any] | None) -> bool: - return expected[0] <= value <= expected[1] if value is not None and expected[0] is not None else False + if value is None or expected is None or expected[0] is None or expected[1] is None: + return False + return expected[0] <= value <= expected[1] @dynamicprocessormethod def _not_in_range(self, value: Any | None, expected: Sequence[Any] | None) -> bool: @@ -239,15 +247,21 @@ def _is_null(self, value: Any | None, _: Sequence[Any] | None = None) -> bool: @dynamicprocessormethod def _starts_with(self, value: Any | None, expected: Sequence[Any] | None) -> bool: - return value.startswith(str(expected[0])) if value is not None and expected[0] is not None else False + if value is None or expected is None or expected[0] is None: + return False + return value.startswith(str(expected[0])) @dynamicprocessormethod def _ends_with(self, value: Any | None, expected: Sequence[Any] | None) -> bool: - return value.endswith(str(expected[0])) if value is not None and expected[0] is not None else False + if value is None or expected is None or expected[0] is None: + return False + return value.endswith(str(expected[0])) @dynamicprocessormethod def _contains(self, value: Any | None, expected: Sequence[Any] | None) -> bool: - return str(expected[0]) in value if value is not None and expected[0] is not None else False + if value is None or expected is None or expected[0] is None: + return False + return str(expected[0]) in value @dynamicprocessormethod def _does_not_contain(self, value: Any | None, expected: Sequence[Any] | None) -> bool: @@ -255,11 +269,13 @@ def _does_not_contain(self, value: Any | None, expected: Sequence[Any] | None) - @dynamicprocessormethod def _matches_reg_ex(self, value: Any | None, expected: Sequence[Any] | None) -> bool: - return bool(re.search(str(expected[0]), value)) if value is not None and expected[0] is not None else False + if value is None or expected is None or expected[0] is None: + return False + return bool(re.search(str(expected[0]), value)) @dynamicprocessormethod def _matches_reg_ex_ignore_case(self, value: Any | None, expected: Sequence[Any] | None) -> bool: - if value is not None and expected[0] is not None: + if value is None or expected is None or expected[0] is None: return False return bool(re.search(str(expected[0]), str(value), flags=re.I))