Skip to content

Commit

Permalink
Do not allow find_first_match without ensure_strategy (#173)
Browse files Browse the repository at this point in the history
* Do not allow find_first_match without ensure_strategy

* lint
  • Loading branch information
ludeeus authored Jul 7, 2022
1 parent a122fd8 commit def202c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
19 changes: 14 additions & 5 deletions awesomeversion/awesomeversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
from .comparehandlers.modifier import compare_handler_semver_modifier
from .comparehandlers.sections import compare_handler_sections
from .comparehandlers.simple import compare_handler_simple
from .exceptions import AwesomeVersionCompareException, AwesomeVersionStrategyException
from .exceptions import (
AwesomeVersionCompareException,
AwesomeVersionException,
AwesomeVersionStrategyException,
)
from .strategy import (
VERSION_STRATEGIES,
VERSION_STRATEGIES_DICT,
Expand Down Expand Up @@ -98,13 +102,18 @@ def __init__(
)
find_first_match = args[1]

if isinstance(version, AwesomeVersion):
self._version = version._version
else:
self._version = str(version)
self._version = (
version._version if isinstance(version, AwesomeVersion) else str(version)
)

if isinstance(self._version, str):
self._version = self._version.strip()

if find_first_match and not ensure_strategy:
raise AwesomeVersionException(
"Can not use find_first_match without ensure_strategy"
)

if ensure_strategy is not None:
self._ensure_strategy = ensure_strategy = (
ensure_strategy
Expand Down
10 changes: 10 additions & 0 deletions tests/test_awesomeversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from awesomeversion import (
AwesomeVersion,
AwesomeVersionException,
AwesomeVersionStrategy,
AwesomeVersionStrategyException,
)
Expand Down Expand Up @@ -212,3 +213,12 @@ def test_find_first_match(
)
assert obj.string == result
assert AwesomeVersion(version, strategy, True).string == obj.string


def test_find_first_match_exception() -> None:
"""Test"""
with pytest.raises(
AwesomeVersionException,
match="Can not use find_first_match without ensure_strategy",
):
AwesomeVersion("1", find_first_match=True)

0 comments on commit def202c

Please sign in to comment.