From 3d0de11f8ff4cfd28e717bf3f4b8e13f1391949f Mon Sep 17 00:00:00 2001 From: Keshav Priyadarshi Date: Thu, 25 Jul 2024 00:03:09 +0530 Subject: [PATCH] Use from_versions for getting vers from discrete versions Signed-off-by: Keshav Priyadarshi --- src/univers/version_range.py | 30 ------------------------------ tests/test_version_range.py | 9 --------- 2 files changed, 39 deletions(-) diff --git a/src/univers/version_range.py b/src/univers/version_range.py index 0532c525..d2bff302 100644 --- a/src/univers/version_range.py +++ b/src/univers/version_range.py @@ -1377,36 +1377,6 @@ def build_range_from_snyk_advisory_string(scheme: str, string: Union[str, List]) return vrc(constraints=version_constraints) -def build_range_from_discrete_version_string(scheme: str, string: Union[str, List]): - """ - Return VersionRange computed from discrete versions. - Discrete version range looks like: - ["1.5","3.1.2","3.1-beta"] - - For example:: - - # >>> vr = build_constraints_from_discrete_version_string("pypi", ["1.5","3.1.2","3.1-beta"]) - # >>> assert str(vr) == "vers:pypi/1.5|3.1-beta|3.1.2" - # >>> vr = build_constraints_from_discrete_version_string("pypi","9.21") - # >>> assert str(vr) == "vers:pypi/9.21" - """ - version_constraints = [] - vrc = RANGE_CLASS_BY_SCHEMES[scheme] - - if isinstance(string, str): - string = [string] - - for item in string: - version = item.strip() - version = vrc.version_class(version) - version_constraints.append( - VersionConstraint( - version=version, - ) - ) - return vrc(constraints=version_constraints) - - RANGE_CLASS_BY_SCHEMES = { "npm": NpmVersionRange, "deb": DebianVersionRange, diff --git a/tests/test_version_range.py b/tests/test_version_range.py index 03387862..1d5848c1 100644 --- a/tests/test_version_range.py +++ b/tests/test_version_range.py @@ -20,7 +20,6 @@ from univers.version_range import OpensslVersionRange from univers.version_range import PypiVersionRange from univers.version_range import VersionRange -from univers.version_range import build_range_from_discrete_version_string from univers.version_range import build_range_from_snyk_advisory_string from univers.version_range import from_gitlab_native from univers.versions import InvalidVersion @@ -489,14 +488,6 @@ def test_build_range_from_snyk_advisory_string_spaced(): assert str(vr) == expected -def test_build_range_from_discrete_version_string(): - expression = ["4.1.0", " 4.4.1", "2.1.0 ", " 3.2.7 "] - vr = build_range_from_discrete_version_string("pypi", expression) - expected = "vers:pypi/2.1.0|3.2.7|4.1.0|4.4.1" - - assert str(vr) == expected - - def test_version_range_normalize_case1(): known_versions = ["4.0.0", "3.0.0", "1.0.0", "2.0.0", "1.3.0", "1.1.0", "1.2.0"]