File: test_arbitrary.py

package info (click to toggle)
dep-logic 0.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 344 kB
  • sloc: python: 4,428; makefile: 3
file content (47 lines) | stat: -rw-r--r-- 1,463 bytes parent folder | download | duplicates (2)
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
import pytest

from dep_logic.specifiers import parse_version_specifier


@pytest.mark.parametrize(
    "a, b, expected",
    [
        ("===abc", "", "===abc"),
        ("", "===abc", "===abc"),
        ("===abc", "===abc", "===abc"),
        ("===abc", "===def", "<empty>"),
        ("===abc", "<empty>", "<empty>"),
        ("<empty>", "===abc", "<empty>"),
        ("===1.0.0", ">=1", "===1.0.0"),
        ("===1.0.0", "<1", "<empty>"),
    ],
)
def test_arbitrary_intersection(a: str, b: str, expected: str) -> None:
    assert str(parse_version_specifier(a) & parse_version_specifier(b)) == expected


@pytest.mark.parametrize(
    "a, b, expected",
    [
        ("===abc", "", ""),
        ("", "===abc", ""),
        ("===abc", "===abc", "===abc"),
        ("===abc", "<empty>", "===abc"),
        ("<empty>", "===abc", "===abc"),
        ("===1.0.0", ">=1", ">=1"),
    ],
)
def test_arbitrary_union(a: str, b: str, expected: str) -> None:
    assert str(parse_version_specifier(a) | parse_version_specifier(b)) == expected


@pytest.mark.parametrize(
    "a, b, operand",
    [("===abc", ">=1", "and"), ("===1.0.0", "<1", "or"), ("===abc", "==1.*", "or")],
)
def test_arbitrary_unsupported(a: str, b: str, operand: str) -> None:
    with pytest.raises(ValueError):
        if operand == "and":
            _ = parse_version_specifier(a) & parse_version_specifier(b)
        else:
            _ = parse_version_specifier(a) | parse_version_specifier(b)