diff --git a/semver.py b/semver.py index d0683170..8e65ecb0 100644 --- a/semver.py +++ b/semver.py @@ -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 , " - "where is one of ['<', '>', '==', '<=', '>=']. " + "where is one of " + "['<', '>', '==', '<=', '>=', '!=']. " "You provided: %r" % match_expr) possibilities_dict = { '>': (1,), '<': (-1,), '==': (0,), + '!=': (-1, 1), '>=': (0, 1), '<=': (-1, 0) } diff --git a/tests.py b/tests.py index 253b3712..9d4f1a77 100644 --- a/tests.py +++ b/tests.py @@ -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") 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