Skip to content

Commit

Permalink
fix comparer conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
geo-martino committed Nov 18, 2024
1 parent 1c3f66c commit 8770341
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
10 changes: 9 additions & 1 deletion docs/info/release-history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@ The format is based on `Keep a Changelog <https://keepachangelog.com/en>`_,
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_


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
Expand Down
34 changes: 25 additions & 9 deletions musify/processors/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -207,23 +209,29 @@ 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:
return not self._is_in(value=value, expected=expected)

@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:
Expand All @@ -239,27 +247,35 @@ 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:
return not self._contains(value=value, expected=expected)

@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))

Expand Down

0 comments on commit 8770341

Please sign in to comment.