Example #1
0
def parse_reference_expression(expression):
    try:
        return package_constraint_to_reference(PackageConstraint.parse(expression))
    except ValueError:
        # if we failed to parse the expression as constraint expression
        # we will try to parse it as reference
        return PackageReference.parse(expression)
Example #2
0
def test_constraint_multiple():
    package_constraint = PackageConstraint.parse('swss>1.2.0,<3.0.0,!=2.2.2')
    assert package_constraint.name == 'swss'
    assert not package_constraint.constraint.allows(Version.parse('2.2.2'))
    assert not package_constraint.constraint.allows(Version.parse('3.2.0'))
    assert not package_constraint.constraint.allows(Version.parse('0.2.0'))
    assert package_constraint.constraint.allows(Version.parse('2.2.3'))
    assert package_constraint.constraint.allows(Version.parse('1.2.3'))
Example #3
0
def test_constraint_from_dict():
    package_constraint = PackageConstraint.parse({
        'name': 'swss',
        'version': '^1.0.0',
        'components': {
            'libswsscommon': '^1.1.0',
        },
    })
    assert package_constraint.name == 'swss'
    assert package_constraint.constraint.allows(Version.parse('1.0.0'))
    assert not package_constraint.constraint.allows(Version.parse('2.0.0'))
    assert package_constraint.components['libswsscommon'].allows(
        Version.parse('1.2.0'))
    assert not package_constraint.components['libswsscommon'].allows(
        Version.parse('1.0.0'))
    assert not package_constraint.components['libswsscommon'].allows(
        Version.parse('2.0.0'))
Example #4
0
def test_constraint_only_name():
    package_constraint = PackageConstraint.parse('swss')
    assert package_constraint.name == 'swss'
    assert package_constraint.constraint == VersionConstraint('*')
Example #5
0
def test_constraint_match():
    package_constraint = PackageConstraint.parse('swss==1.2.*')
    assert package_constraint.name == 'swss'
    assert not package_constraint.constraint.allows(Version.parse('1.1.1'))
    assert package_constraint.constraint.allows(Version.parse('1.2.0'))
Example #6
0
def test_constraint_range():
    package_constraint = PackageConstraint.parse('swss^1.2.0')
    assert package_constraint.name == 'swss'
    assert not package_constraint.constraint.allows(Version.parse('1.1.1'))
    assert package_constraint.constraint.allows(Version.parse('1.2.5'))
    assert not package_constraint.constraint.allows(Version.parse('2.0.1'))
Example #7
0
def test_constraint():
    package_constraint = PackageConstraint.parse('swss>1.0.0')
    assert package_constraint.name == 'swss'
    assert not package_constraint.constraint.allows(Version.parse('0.9.1'))
    assert package_constraint.constraint.allows(Version.parse('1.1.1'))