def test_empty_specifier(self, version): spec = LooseSpecifierSet() assert version in spec assert spec.contains(version) assert LooseVersion(version) in spec assert spec.contains(LooseVersion(version))
def test_specifiers(self, version, spec, expected): spec = LooseSpecifier(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 LooseVersion(version) in spec assert spec.contains(LooseVersion(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 LooseVersion(version) not in spec assert not spec.contains(LooseVersion(version))
def test_compare_other(self, op, expected): other = pretend.stub(**{ "__{0}__".format(op): lambda other: NotImplemented }) assert getattr(operator, op)(LooseVersion("1"), other) is expected
def test_compare_with_pythonversion(self, op): method = getattr(LooseVersion, "__{0}__".format(op)) assert method(LooseVersion("0"), PythonVersion("1")) is NotImplemented
def test_comparison_false(self, left, right, op): assert not op(LooseVersion(left), LooseVersion(right))
def test_dunder_op_returns_notimplemented(self, op): method = getattr(LooseVersion, "__{0}__".format(op)) assert method(LooseVersion("1"), 1) is NotImplemented
def test_loose_version_is_postrelease(self, version): assert not LooseVersion(version).is_postrelease
def test_equality_false(self, left, right, op): assert not op(LooseVersion(left), LooseVersion(right))
class TestLooseSpecifierSet: @pytest.mark.parametrize("version", VERSIONS + LOOSE_VERSIONS) def test_empty_specifier(self, version): spec = LooseSpecifierSet() assert version in spec assert spec.contains(version) assert LooseVersion(version) in spec assert spec.contains(LooseVersion(version)) @pytest.mark.parametrize( ("specifier", "prereleases", "input", "expected"), [ # General test of the filter method ("", None, ["1.0", "2.0a1"], ["1.0", "2.0a1"]), (">=1.0.dev1", None, ["1.0", "2.0a1"], ["1.0", "2.0a1"]), ("", None, ["1.0a1"], ["1.0a1"]), ("", None, ["1.0", LooseVersion("2.0") ], ["1.0", LooseVersion("2.0")]), ("", None, ["2.0dog", "1.0"], ["2.0dog", "1.0"]), # Test overriding with the prereleases parameter on filter ("", False, ["1.0a1"], ["1.0a1"]), (">=1.0.dev1", False, ["1.0", "2.0a1"], ["1.0", "2.0a1"]), ("", True, ["1.0", "2.0a1"], ["1.0", "2.0a1"]), ], ) def test_specifier_filter(self, specifier, prereleases, input, expected): spec = LooseSpecifierSet(specifier) kwargs = ({ "prereleases": prereleases } if prereleases is not None else {}) assert list(spec.filter(input, **kwargs)) == expected def test_specifier_explicit_python(self): assert LooseSpecifier("==1.0").contains(PythonVersion("1.0")) def test_loose_specifiers_combined(self): spec = LooseSpecifierSet("<3,>1-1-1") assert "2.0" in spec @pytest.mark.parametrize( ("specifier", "expected"), [ # Single item specifiers should just be reflexive ("!=2.0", "!=2.0"), ("<2.0", "<2.0"), ("<=2.0", "<=2.0"), ("==2.0", "==2.0"), (">2.0", ">2.0"), (">=2.0", ">=2.0"), # Spaces should be removed ("< 2", "<2"), # Multiple item specifiers should work ("!=2.0,>1.0", "!=2.0,>1.0"), ("!=2.0 ,>1.0", "!=2.0,>1.0"), ], ) def test_specifiers_str_and_repr(self, specifier, expected): spec = LooseSpecifierSet(specifier) assert str(spec) == expected assert repr(spec) == "<LooseSpecifierSet({0})>".format(repr(expected)) @pytest.mark.parametrize("specifier", LOOSE_SPECIFIERS) def test_specifiers_hash(self, specifier): assert hash(LooseSpecifierSet(specifier)) == hash( LooseSpecifierSet(specifier)) @pytest.mark.parametrize(("left", "right", "expected"), [(">2.0", "<5.0", ">2.0,<5.0")]) def test_specifiers_combine(self, left, right, expected): result = LooseSpecifierSet(left) & LooseSpecifierSet(right) assert result == LooseSpecifierSet(expected) result = LooseSpecifierSet(left) & right assert result == LooseSpecifierSet(expected) def test_specifiers_combine_not_implemented(self): with pytest.raises(TypeError): PythonSpecifierSet() & 12 @pytest.mark.parametrize( ("left", "right", "op"), itertools.chain( * # Verify that the equal (==) operator works correctly [[(x, x, operator.eq) for x in LOOSE_SPECIFIERS]] + # Verify that the not equal (!=) operator works correctly [[(x, y, operator.ne) for j, y in enumerate(LOOSE_SPECIFIERS) if i != j] for i, x in enumerate(LOOSE_SPECIFIERS)]), ) def test_comparison_true(self, left, right, op): assert op(LooseSpecifierSet(left), LooseSpecifierSet(right)) assert op(LooseSpecifierSet(left), LooseSpecifier(right)) assert op(LooseSpecifier(left), LooseSpecifierSet(right)) assert op(left, LooseSpecifierSet(right)) assert op(LooseSpecifierSet(left), right) @pytest.mark.parametrize( ("left", "right", "op"), itertools.chain( * # Verify that the not equal (!=) operator works correctly [[(x, x, operator.ne) for x in LOOSE_SPECIFIERS]] + # Verify that the equal (==) operator works correctly [[(x, y, operator.eq) for j, y in enumerate(LOOSE_SPECIFIERS) if i != j] for i, x in enumerate(LOOSE_SPECIFIERS)]), ) def test_comparison_false(self, left, right, op): assert not op(LooseSpecifierSet(left), LooseSpecifierSet(right)) assert not op(LooseSpecifierSet(left), LooseSpecifier(right)) assert not op(LooseSpecifier(left), LooseSpecifierSet(right)) assert not op(left, LooseSpecifierSet(right)) assert not op(LooseSpecifierSet(left), right) def test_comparison_non_specifier(self): assert LooseSpecifierSet("==1.0") != 12 assert not LooseSpecifierSet("==1.0") == 12
def test_loose_version_public(self, version): assert LooseVersion(version).public == version
def test_loose_version_local(self, version): assert LooseVersion(version).local is None
def test_loose_version_pre(self, version): assert LooseVersion(version).pre is None
def test_loose_version_release(self, version): assert LooseVersion(version).release is None
def test_loose_version_epoch(self, version): assert LooseVersion(version).epoch == 0
def test_loose_version_base_version(self, version): assert LooseVersion(version).base_version == version
def test_specifier_explicit_loose(self): assert PythonSpecifier("==1.0").contains(LooseVersion("1.0"))
def test_loose_version_str_repr(self, version): assert str(LooseVersion(version)) == version assert repr(LooseVersion(version)) == "<LooseVersion({0})>".format( repr(version) )
def test_loose_version_dev(self, version): assert LooseVersion(version).dev is None
def test_loose_version_hash(self, version): assert hash(LooseVersion(version)) == hash(LooseVersion(version))
def test_loose_version_post(self, version): assert LooseVersion(version).post is None
def test_valid_loose_versions(self, version): LooseVersion(version)