From b5f69d408e6c8d61de074fd48dcfed151e7669fe Mon Sep 17 00:00:00 2001 From: robi-wan Date: Mon, 23 May 2016 08:47:13 +0200 Subject: [PATCH 1/2] Support matching 'not equal' with '!=' Remove check for unused/unsupported match expression '='. --- semver.py | 7 ++++--- tests.py | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/semver.py b/semver.py index d0683170..7fdae5b6 100644 --- a/semver.py +++ b/semver.py @@ -76,20 +76,21 @@ 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") From becd7089459cd26a5091d0e732397767cdf14f29 Mon Sep 17 00:00:00 2001 From: robi-wan Date: Mon, 23 May 2016 09:29:08 +0200 Subject: [PATCH 2/2] Format ValueError message to meet expected line length. --- semver.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/semver.py b/semver.py index 7fdae5b6..8e65ecb0 100644 --- a/semver.py +++ b/semver.py @@ -83,7 +83,8 @@ def match(version, match_expr): 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 = { 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