1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
import pytest
from semver import match
def test_should_match_simple():
assert match("2.3.7", ">=2.3.6") is True
def test_should_no_match_simple():
assert match("2.3.7", ">=2.3.8") is False
@pytest.mark.parametrize(
"left,right,expected",
[
("2.3.7", "!=2.3.8", True),
("2.3.7", "!=2.3.6", True),
("2.3.7", "!=2.3.7", False),
],
)
def test_should_match_not_equal(left, right, expected):
assert match(left, right) is expected
@pytest.mark.parametrize(
"left,right,expected",
[
("2.3.7", "2.3.7", True),
("2.3.6", "2.3.6", True),
("2.3.7", "4.3.7", False),
],
)
def test_should_match_equal_by_default(left, right, expected):
assert match(left, right) is expected
@pytest.mark.parametrize(
"left,right,expected",
[
("2.3.7", "<2.4.0", True),
("2.3.7", ">2.3.5", True),
("2.3.7", "<=2.3.9", True),
("2.3.7", ">=2.3.5", True),
("2.3.7", "==2.3.7", True),
("2.3.7", "!=2.3.7", False),
],
)
def test_should_not_raise_value_error_for_expected_match_expression(
left, right, expected
):
assert match(left, right) is expected
@pytest.mark.parametrize(
"left,right", [("2.3.7", "=2.3.7"), ("2.3.7", "~2.3.7"), ("2.3.7", "^2.3.7")]
)
def test_should_raise_value_error_for_unexpected_match_expression(left, right):
with pytest.raises(ValueError):
match(left, right)
@pytest.mark.parametrize("left,right", [("1.0.0", ""), ("1.0.0", "!")])
def test_should_raise_value_error_for_invalid_match_expression(left, right):
with pytest.raises(ValueError):
match(left, right)
|