def test_specifier_filter(self, specifier, prereleases, input, expected): spec = PythonSpecifier(specifier) kwargs = ({ "prereleases": prereleases } if prereleases is not None else {}) assert list(spec.filter(input, **kwargs)) == expected
def test_specifiers_prereleases(self, specifier, version, expected): spec = PythonSpecifier(specifier) if expected: assert version in spec spec.prereleases = False assert version not in spec else: assert version not in spec spec.prereleases = True assert version in spec
def test_specifiers_normalized(self, version): if "+" not in version: ops = ["~=", "==", "!=", "<=", ">=", "<", ">"] else: ops = ["==", "!="] for op in ops: PythonSpecifier(op + version)
def test_specifiers_identity(self, version, spec, expected): spec = PythonSpecifier(spec) if expected: # Identity comparisons only support the plain string form assert version in spec else: # Identity comparisons only support the plain string form assert version not in spec
def test_specifiers(self, version, spec, expected): spec = PythonSpecifier(spec, prereleases=True) if expected: # Test that the plain string form works assert version in spec assert spec.contains(version) # Test that the version instance form works assert PythonVersion(version) in spec assert spec.contains(PythonVersion(version)) else: # Test that the plain string form works assert version not in spec assert not spec.contains(version) # Test that the version instance form works assert PythonVersion(version) not in spec assert not spec.contains(PythonVersion(version))
def test_comparison_false(self, left, right, op): assert not op(PythonSpecifierSet(left), PythonSpecifierSet(right)) assert not op(PythonSpecifierSet(left), PythonSpecifier(right)) assert not op(PythonSpecifier(left), PythonSpecifierSet(right)) assert not op(left, PythonSpecifierSet(right)) assert not op(PythonSpecifierSet(left), right)
def test_specifiers_invalid(self, specifier): with pytest.raises(InvalidSpecifier): PythonSpecifier(specifier)
def test_specifier_version_property(self, spec, version): assert PythonSpecifier(spec).version == version
def test_specifier_operator_property(self, spec, op): assert PythonSpecifier(spec).operator == op
def test_specifier_explicit_loose(self): assert PythonSpecifier("==1.0").contains(LooseVersion("1.0"))
def test_specifiers_hash(self, specifier): assert (hash(PythonSpecifier(specifier)) == hash( PythonSpecifier(specifier)))
def test_comparison_true(self, left, right, op): assert op(PythonSpecifier(left), PythonSpecifier(right)) assert op(left, PythonSpecifier(right)) assert op(PythonSpecifier(left), right)
def test_specifier_prereleases_detection(self, specifier, expected): assert PythonSpecifier(specifier).prereleases == expected
def test_specifiers_str_and_repr(self, specifier, expected): spec = PythonSpecifier(specifier) assert str(spec) == expected assert repr(spec) == "<PythonSpecifier({0})>".format(repr(expected))
def test_specifiers_valid(self, specifier): PythonSpecifier(specifier)
def test_comparison_non_specifier(self): assert PythonSpecifier("==1.0") != 12 assert not PythonSpecifier("==1.0") == 12 assert PythonSpecifier("==1.0") != "12" assert not PythonSpecifier("==1.0") == "12"
def test_comparison_canonicalizes(self, left, right): assert PythonSpecifier(left) == PythonSpecifier(right) assert left == PythonSpecifier(right) assert PythonSpecifier(left) == right