Skip to content

Support matching 'not equal' with '!=' #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions semver.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,22 @@ def compare_by_keys(d1, d2):

def match(version, match_expr):
prefix = match_expr[:2]
if prefix in ('>=', '<=', '=='):
if prefix in ('>=', '<=', '==', '!='):
match_version = match_expr[2:]
elif prefix and prefix[0] in ('>', '<', '='):
elif prefix and prefix[0] in ('>', '<'):
prefix = prefix[0]
match_version = match_expr[1:]
else:
raise ValueError("match_expr parameter should be in format <op><ver>, "
"where <op> is one of ['<', '>', '==', '<=', '>=']. "
"where <op> is one of "
"['<', '>', '==', '<=', '>=', '!=']. "
"You provided: %r" % match_expr)

possibilities_dict = {
'>': (1,),
'<': (-1,),
'==': (0,),
'!=': (-1, 1),
'>=': (0, 1),
'<=': (-1, 0)
}
Expand Down
25 changes: 25 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@ def test_should_no_match_simple():
assert match("2.3.7", ">=2.3.8") is False


def test_should_match_not_equal():
assert match("2.3.7", "!=2.3.8") is True
assert match("2.3.7", "!=2.3.6") is True
assert match("2.3.7", "!=2.3.7") is False


def test_should_not_raise_value_error_for_expected_match_expression():
assert match("2.3.7", "<2.4.0") is True
assert match("2.3.7", ">2.3.5") is True

assert match("2.3.7", "<=2.3.9") is True
assert match("2.3.7", ">=2.3.5") is True
assert match("2.3.7", "==2.3.7") is True
assert match("2.3.7", "!=2.3.7") is False


def test_should_raise_value_error_for_unexpected_match_expression():
with pytest.raises(ValueError):
match("2.3.7", "=2.3.7")
with pytest.raises(ValueError):
match("2.3.7", "~2.3.7")
with pytest.raises(ValueError):
match("2.3.7", "^2.3.7")


def test_should_raise_value_error_for_zero_prefixed_versions():
with pytest.raises(ValueError):
parse("01.2.3")
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy