def test_allows_all() -> None:
    c = UnionConstraint(Constraint("win32"), Constraint("linux"))

    assert c.allows_all(c)
    assert not c.allows_all(UnionConstraint(Constraint("win32"), Constraint("darwin")))
    assert not c.allows_all(UnionConstraint(Constraint("linux2"), Constraint("darwin")))
    assert c.allows_all(Constraint("win32"))
    assert not c.allows_all(Constraint("darwin"))
Example #2
0
def test_allows_all() -> None:
    c = MultiConstraint(Constraint("win32", "!="), Constraint("linux", "!="))

    assert c.allows_all(Constraint("darwin"))
    assert c.allows_all(Constraint("darwin", "!="))
    assert not c.allows_all(Constraint("win32"))
    assert c.allows_all(c)
    assert not c.allows_all(
        MultiConstraint(Constraint("win32", "!="), Constraint("darwin", "!=")))
Example #3
0
def parse_single_constraint(constraint: str) -> Constraint:
    # Basic comparator
    m = BASIC_CONSTRAINT.match(constraint)
    if m:
        op = m.group(1)
        if op is None:
            op = "=="

        version = m.group(2).strip()

        return Constraint(version, op)

    raise ValueError(f"Could not parse version constraint: {constraint}")
Example #4
0
import pytest

from poetry.core.packages.constraints import parse_constraint
from poetry.core.packages.constraints.any_constraint import AnyConstraint
from poetry.core.packages.constraints.constraint import Constraint
from poetry.core.packages.constraints.multi_constraint import MultiConstraint
from poetry.core.packages.constraints.union_constraint import UnionConstraint


@pytest.mark.parametrize(
    "input,constraint",
    [
        ("*", AnyConstraint()),
        ("win32", Constraint("win32", "=")),
        ("=win32", Constraint("win32", "=")),
        ("==win32", Constraint("win32", "=")),
        ("!=win32", Constraint("win32", "!=")),
        ("!= win32", Constraint("win32", "!=")),
    ],
)
def test_parse_constraint(input, constraint):
    assert parse_constraint(input) == constraint


@pytest.mark.parametrize(
    "input,constraint",
    [
        (
            "!=win32,!=linux",
            MultiConstraint(Constraint("win32", "!="), Constraint(
                "linux", "!=")),
def test_allows_all() -> None:
    c = Constraint("win32")

    assert c.allows_all(Constraint("win32"))
    assert not c.allows_all(Constraint("linux"))
    assert not c.allows_all(Constraint("linux", "!="))
    assert not c.allows_all(UnionConstraint(Constraint("win32"), Constraint("linux")))
def test_allows() -> None:
    c = Constraint("win32")

    assert c.allows(Constraint("win32"))
    assert not c.allows(Constraint("linux"))

    c = Constraint("win32", "!=")

    assert not c.allows(Constraint("win32"))
    assert c.allows(Constraint("linux"))
def test_difference() -> None:
    c = Constraint("win32")

    assert c.difference(Constraint("win32")).is_empty()
    assert c.difference(Constraint("linux")) == c

def test_allows_all() -> None:
    c = Constraint("win32")

    assert c.allows_all(Constraint("win32"))
    assert not c.allows_all(Constraint("linux"))
    assert not c.allows_all(Constraint("linux", "!="))
    assert not c.allows_all(UnionConstraint(Constraint("win32"), Constraint("linux")))


@pytest.mark.parametrize(
    ("constraint1", "constraint2", "expected"),
    [
        (
            Constraint("win32"),
            Constraint("win32"),
            Constraint("win32"),
        ),
        (
            Constraint("win32"),
            Constraint("linux"),
            EmptyConstraint(),
        ),
        (
            Constraint("win32"),
            UnionConstraint(Constraint("win32"), Constraint("linux")),
            Constraint("win32"),
        ),
        (
            Constraint("win32"),
Example #9
0
def test_union():
    c = Constraint("win32")

    union = c.union(Constraint("linux"))
    assert union == UnionConstraint(Constraint("win32"), Constraint("linux"))

    union = c.union(UnionConstraint(Constraint("win32"), Constraint("linux")))
    assert union == UnionConstraint(Constraint("win32"), Constraint("linux"))

    union = c.union(UnionConstraint(Constraint("linux"), Constraint("linux2")))
    assert union == UnionConstraint(Constraint("win32"), Constraint("linux"),
                                    Constraint("linux2"))
Example #10
0
def test_intersect():
    c = Constraint("win32")

    intersection = c.intersect(Constraint("linux"))
    assert intersection == EmptyConstraint()

    intersection = c.intersect(
        UnionConstraint(Constraint("win32"), Constraint("linux")))
    assert intersection == Constraint("win32")

    intersection = c.intersect(
        UnionConstraint(Constraint("linux"), Constraint("linux2")))
    assert intersection == EmptyConstraint()

    intersection = c.intersect(Constraint("linux", "!="))
    assert intersection == c

    c = Constraint("win32", "!=")

    intersection = c.intersect(Constraint("linux", "!="))
    assert intersection == MultiConstraint(Constraint("win32", "!="),
                                           Constraint("linux", "!="))
Example #11
0
def test_allows_any():
    c = Constraint("win32")

    assert c.allows_any(Constraint("win32"))
    assert not c.allows_any(Constraint("linux"))
    assert c.allows_any(
        UnionConstraint(Constraint("win32"), Constraint("linux")))
    assert c.allows_any(Constraint("linux", "!="))

    c = Constraint("win32", "!=")

    assert not c.allows_any(Constraint("win32"))
    assert c.allows_any(Constraint("linux"))
    assert c.allows_any(
        UnionConstraint(Constraint("win32"), Constraint("linux")))
    assert c.allows_any(Constraint("linux", "!="))
Example #12
0
def test_intersect() -> None:
    c = MultiConstraint(Constraint("win32", "!="), Constraint("linux", "!="))

    intersection = c.intersect(Constraint("win32", "!="))
    assert intersection == Constraint("win32", "!=")