From a1900af2d9736cf36ccdd5df5ab1a2fc08483b1e Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Tue, 20 Aug 2024 15:41:33 +0800 Subject: [PATCH 1/2] Fixed #140 - Update link references of ownership from nexB to aboutcode-org Signed-off-by: Chin Yeung Li --- CHANGELOG.rst | 11 +- Makefile | 4 +- NOTICE | 2 +- README.rst | 20 +- configure | 2 +- configure.bat | 2 +- conftest.py | 2 +- docs/source/conf.py | 2 +- docs/source/contribute/contrib_doc.rst | 2 +- docs/source/skeleton-usage.rst | 2 +- etc/scripts/check_thirdparty.py | 5 +- etc/scripts/fetch_thirdparty.py | 19 +- etc/scripts/gen_requirements.py | 2 +- etc/scripts/gen_requirements_dev.py | 2 +- etc/scripts/utils_dejacode.py | 11 +- etc/scripts/utils_requirements.py | 11 +- etc/scripts/utils_thirdparty.py | 89 ++++++--- overlay.nix | 2 +- setup.cfg | 4 +- src/univers/arch.py | 2 +- src/univers/conan/errors.py | 2 +- src/univers/conan/version.py | 2 +- src/univers/conan/version_range.py | 2 +- src/univers/debian.py | 6 +- src/univers/gem.py | 2 +- src/univers/gentoo.py | 2 +- src/univers/maven.py | 2 +- src/univers/nuget.py | 2 +- src/univers/rpm.py | 2 +- src/univers/univers_semver.py | 2 +- src/univers/utils.py | 2 +- src/univers/version_constraint.py | 2 +- src/univers/version_range.py | 6 +- src/univers/versions.py | 2 +- tests/test_alpine.py | 2 +- tests/test_codestyle.py | 2 +- tests/test_conan_version_bump.py | 2 +- tests/test_conan_version_comparison.py | 2 +- tests/test_conan_version_range.py | 26 ++- tests/test_debian_version.py | 19 +- tests/test_debian_version.py.ABOUT | 4 +- ...est_debian_version_python_deb_pkg_tools.py | 5 +- tests/test_gem.py | 2 +- tests/test_gentoo.py | 2 +- tests/test_gentoo_pkgcore.py | 11 +- tests/test_maven_version.py | 17 +- tests/test_maven_version_range.py | 53 +++-- tests/test_openssl_vercmp.py | 2 +- tests/test_openssl_versort.py | 5 +- tests/test_pacman_vercmp.py | 2 +- tests/test_pypi_version.py | 2 +- tests/test_python_semver.py | 2 +- tests/test_rpm_vercmp.py | 8 +- tests/test_skeleton_codestyle.py | 2 +- tests/test_vers.py | 2 +- tests/test_version_comparison.py | 2 +- tests/test_version_constraint.py | 2 +- tests/test_version_range.py | 185 ++++++++++++------ tests/test_versions.py | 8 +- tests/util_tests.py | 2 +- 60 files changed, 376 insertions(+), 227 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b6632502..b495b28b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ Changelog ========= +Version v30.12.1 +---------------- + +- Update link references of ownership from nexB to aboutcode-org. https://github.com/aboutcode-org/univers/issues/140 + Version v30.12.0 ---------------- @@ -37,7 +42,7 @@ Version v30.10.0 Version v30.9.2 ---------------- -- Fix unhashable error in GemVersion. +- Fix unhashable error in GemVersion. Version v30.9.1 @@ -89,7 +94,7 @@ Version v30.5.0 Version v30.4.0 ---------------- -- Add support for forming VersionRange from a list of versions.Thank you +- Add support for forming VersionRange from a list of versions.Thank you to Keshav Priyadarshi @keshav-space for this. @@ -146,7 +151,7 @@ Version v30.0.0 Version v21.4.9 ----------------- -- Add support Gentoo style versions. +- Add support Gentoo style versions. Version v21.4.8 diff --git a/Makefile b/Makefile index cc36c355..94451b33 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ # ScanCode is a trademark of nexB Inc. # SPDX-License-Identifier: Apache-2.0 # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. -# See https://github.com/nexB/skeleton for support or download. +# See https://github.com/aboutcode-org/skeleton for support or download. # See https://aboutcode.org for more information about nexB OSS projects. # @@ -35,7 +35,7 @@ check: @echo "-> Run pycodestyle (PEP8) validation" @${ACTIVATE} pycodestyle --max-line-length=100 --exclude=.eggs,venv,lib,thirdparty,docs,migrations,settings.py,.cache . @echo "-> Run isort imports ordering validation" - @${ACTIVATE} isort --sl --check-only -l 100 setup.py src tests . + @${ACTIVATE} isort --sl --check-only -l 100 setup.py src tests . @echo "-> Run black validation" @${ACTIVATE} black --check --check -l 100 src tests setup.py diff --git a/NOTICE b/NOTICE index 365b33d7..1a7384d7 100644 --- a/NOTICE +++ b/NOTICE @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/vulnerablecode +# Visit https://aboutcode.org and https://github.com/aboutcode-org/vulnerablecode # for support and download. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/README.rst b/README.rst index 90159655..82531791 100644 --- a/README.rst +++ b/README.rst @@ -16,7 +16,7 @@ ranges and to compare two software package versions in VulnerableCode. Package version ranges and version constraints are useful and essential: - When relating a known vulnerability or bug to a range of affected package - versions. For instance a statement such as "vulnerability 123 affects + versions. For instance a statement such as "vulnerability 123 affects package bar, version 3.1 and version 4.2 but not version 5" defines a range of bar versions affected by a vulnerability. @@ -78,7 +78,7 @@ include: This is supported in part by the `semantic_version `_ library. -- pypi: handled by Python's packaging library and the standard +- pypi: handled by Python's packaging library and the standard ``packaging.version`` module. - Rubygems which use a semver-like but not-quite-semver scheme and there can be @@ -89,26 +89,26 @@ include: "OR" between constraints (that it call requirements). Gem are handled by Python port of the Rubygems requirements and version handling code from the `puppeteer tool - `_ + `_ - debian: handled by the `debian-inspector library - `_. + `_. - maven: handled by the embedded `pymaven library - `_. + `_. - rpm: handled by the embedded `rpm_vercmp library - `_. + `_. - golang (using semver) - PHP composer - ebuild/gentoo: handled by the embedded `gentoo_vercmp module - `_. + `_. - arch linux: handled by the embedded `arch utility module borrowed from msys2 - `_. + `_. - Alpine linux: handled using the base Gentoo version support and extras specific to Alpine. @@ -172,7 +172,7 @@ Test if a version is within or outside a version range: Development ============ -Run these commands, starting from a git clone of https://github.com/nexB/univers :: +Run these commands, starting from a git clone of https://github.com/aboutcode-org/univers :: $ ./configure --dev $ source venv/bin/active @@ -181,7 +181,7 @@ Run these commands, starting from a git clone of https://github.com/nexB/univers We use the same development process as other AboutCode projects. -Visit https://github.com/nexB/univers and +Visit https://github.com/aboutcode-org/univers and https://gitter.im/aboutcode-org/vulnerablecode and https://gitter.im/aboutcode-org/aboutcode for support and chat. diff --git a/configure b/configure index 926a894e..22d92885 100755 --- a/configure +++ b/configure @@ -3,7 +3,7 @@ # Copyright (c) nexB Inc. and others. All rights reserved. # SPDX-License-Identifier: Apache-2.0 # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. -# See https://github.com/nexB/ for support or download. +# See https://github.com/aboutcode-org/ for support or download. # See https://aboutcode.org for more information about nexB OSS projects. # diff --git a/configure.bat b/configure.bat index 5e95b311..5b9a9d68 100644 --- a/configure.bat +++ b/configure.bat @@ -4,7 +4,7 @@ @rem Copyright (c) nexB Inc. and others. All rights reserved. @rem SPDX-License-Identifier: Apache-2.0 @rem See http://www.apache.org/licenses/LICENSE-2.0 for the license text. -@rem See https://github.com/nexB/ for support or download. +@rem See https://github.com/aboutcode-org/ for support or download. @rem See https://aboutcode.org for more information about nexB OSS projects. diff --git a/conftest.py b/conftest.py index 57496c7a..f694f251 100644 --- a/conftest.py +++ b/conftest.py @@ -2,6 +2,6 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. collect_ignore = ["setup.py"] diff --git a/docs/source/conf.py b/docs/source/conf.py index 7771ff09..8c88fa2c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -43,7 +43,7 @@ # This points to aboutcode.readthedocs.io # In case of "undefined label" ERRORS check docs on intersphinx to troubleshoot -# Link was created at commit - https://github.com/nexB/aboutcode/commit/faea9fcf3248f8f198844fe34d43833224ac4a83 +# Link was created at commit - https://github.com/aboutcode-org/aboutcode/commit/faea9fcf3248f8f198844fe34d43833224ac4a83 intersphinx_mapping = { "aboutcode": ("https://aboutcode.readthedocs.io/en/latest/", None), diff --git a/docs/source/contribute/contrib_doc.rst b/docs/source/contribute/contrib_doc.rst index 13882e10..5640db26 100644 --- a/docs/source/contribute/contrib_doc.rst +++ b/docs/source/contribute/contrib_doc.rst @@ -12,7 +12,7 @@ To get started, create or identify a working directory on your local machine. Open that directory and execute the following command in a terminal session:: - git clone https://github.com/nexB/skeleton.git + git clone https://github.com/aboutcode-org/skeleton.git That will create an ``/skeleton`` directory in your working directory. Now you can install the dependencies in a virtualenv:: diff --git a/docs/source/skeleton-usage.rst b/docs/source/skeleton-usage.rst index cde23dcd..6cb4cc5f 100644 --- a/docs/source/skeleton-usage.rst +++ b/docs/source/skeleton-usage.rst @@ -118,7 +118,7 @@ corrected. You can check to see if your corrections are valid by running: Once the wheels are collected and the ABOUT files are generated and correct, upload them to thirdparty.aboutcode.org/pypi by placing the wheels and ABOUT files from the thirdparty directory to the pypi directory at -https://github.com/nexB/thirdparty-packages +https://github.com/aboutcode-org/thirdparty-packages Usage after project initialization diff --git a/etc/scripts/check_thirdparty.py b/etc/scripts/check_thirdparty.py index b052f25b..2daded94 100644 --- a/etc/scripts/check_thirdparty.py +++ b/etc/scripts/check_thirdparty.py @@ -5,7 +5,7 @@ # ScanCode is a trademark of nexB Inc. # SPDX-License-Identifier: Apache-2.0 # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. -# See https://github.com/nexB/skeleton for support or download. +# See https://github.com/aboutcode-org/skeleton for support or download. # See https://aboutcode.org for more information about nexB OSS projects. # import click @@ -17,7 +17,8 @@ @click.option( "-d", "--dest", - type=click.Path(exists=True, readable=True, path_type=str, file_okay=False), + type=click.Path(exists=True, readable=True, + path_type=str, file_okay=False), required=True, help="Path to the thirdparty directory to check.", ) diff --git a/etc/scripts/fetch_thirdparty.py b/etc/scripts/fetch_thirdparty.py index eedf05c6..3f9ff527 100644 --- a/etc/scripts/fetch_thirdparty.py +++ b/etc/scripts/fetch_thirdparty.py @@ -5,7 +5,7 @@ # ScanCode is a trademark of nexB Inc. # SPDX-License-Identifier: Apache-2.0 # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. -# See https://github.com/nexB/skeleton for support or download. +# See https://github.com/aboutcode-org/skeleton for support or download. # See https://aboutcode.org for more information about nexB OSS projects. # @@ -55,7 +55,8 @@ "-d", "--dest", "dest_dir", - type=click.Path(exists=True, readable=True, path_type=str, file_okay=False), + type=click.Path(exists=True, readable=True, + path_type=str, file_okay=False), metavar="DIR", default=utils_thirdparty.THIRDPARTY_DIR, show_default=True, @@ -224,7 +225,8 @@ def fetch_thirdparty( environments = None if wheels: evts = itertools.product(python_versions, operating_systems) - environments = [utils_thirdparty.Environment.from_pyver_and_os(pyv, os) for pyv, os in evts] + environments = [utils_thirdparty.Environment.from_pyver_and_os( + pyv, os) for pyv, os in evts] # Collect PyPI repos repos = [] @@ -260,13 +262,14 @@ def fetch_thirdparty( repos=repos, ) if not fetched: - wheels_or_sdist_not_found[f"{name}=={version}"].append(environment) + wheels_or_sdist_not_found[f"{name}=={version}"].append( + environment) if TRACE: print(f" NOT FOUND") if (sdists or (f"{name}=={version}" in wheels_or_sdist_not_found and name in sdist_only) - ): + ): if TRACE: print(f" ==> Fetching sdist: {name}=={version}") @@ -289,7 +292,8 @@ def fetch_thirdparty( sdist_missing = sdists and "sdist" in dists and not name in wheel_only if sdist_missing: mia.append(f"SDist missing: {nv} {dists}") - wheels_missing = wheels and any(d for d in dists if d != "sdist") and not name in sdist_only + wheels_missing = wheels and any( + d for d in dists if d != "sdist") and not name in sdist_only if wheels_missing: mia.append(f"Wheels missing: {nv} {dists}") @@ -299,7 +303,8 @@ def fetch_thirdparty( raise Exception(mia) print(f"==> FETCHING OR CREATING ABOUT AND LICENSE FILES") - utils_thirdparty.fetch_abouts_and_licenses(dest_dir=dest_dir, use_cached_index=use_cached_index) + utils_thirdparty.fetch_abouts_and_licenses( + dest_dir=dest_dir, use_cached_index=use_cached_index) utils_thirdparty.clean_about_files(dest_dir=dest_dir) # check for problems diff --git a/etc/scripts/gen_requirements.py b/etc/scripts/gen_requirements.py index 07e26f77..2b65ae80 100644 --- a/etc/scripts/gen_requirements.py +++ b/etc/scripts/gen_requirements.py @@ -5,7 +5,7 @@ # ScanCode is a trademark of nexB Inc. # SPDX-License-Identifier: Apache-2.0 # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. -# See https://github.com/nexB/skeleton for support or download. +# See https://github.com/aboutcode-org/skeleton for support or download. # See https://aboutcode.org for more information about nexB OSS projects. # import argparse diff --git a/etc/scripts/gen_requirements_dev.py b/etc/scripts/gen_requirements_dev.py index 12cc06d3..5db1c48e 100644 --- a/etc/scripts/gen_requirements_dev.py +++ b/etc/scripts/gen_requirements_dev.py @@ -5,7 +5,7 @@ # ScanCode is a trademark of nexB Inc. # SPDX-License-Identifier: Apache-2.0 # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. -# See https://github.com/nexB/skeleton for support or download. +# See https://github.com/aboutcode-org/skeleton for support or download. # See https://aboutcode.org for more information about nexB OSS projects. # import argparse diff --git a/etc/scripts/utils_dejacode.py b/etc/scripts/utils_dejacode.py index f6e91a91..e189dd07 100644 --- a/etc/scripts/utils_dejacode.py +++ b/etc/scripts/utils_dejacode.py @@ -5,7 +5,7 @@ # ScanCode is a trademark of nexB Inc. # SPDX-License-Identifier: Apache-2.0 # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. -# See https://github.com/nexB/skeleton for support or download. +# See https://github.com/aboutcode-org/skeleton for support or download. # See https://aboutcode.org for more information about nexB OSS projects. # import io @@ -33,7 +33,8 @@ def can_do_api_calls(): if not DEJACODE_API_KEY and DEJACODE_API_URL: - print("DejaCode DEJACODE_API_KEY and DEJACODE_API_URL not configured. Doing nothing") + print( + "DejaCode DEJACODE_API_KEY and DEJACODE_API_URL not configured. Doing nothing") return False else: return True @@ -68,7 +69,8 @@ def get_package_data(distribution): return results[0] elif len_results > 1: - print(f"More than 1 entry exists, review at: {DEJACODE_API_URL_PACKAGES}") + print( + f"More than 1 entry exists, review at: {DEJACODE_API_URL_PACKAGES}") else: print("Could not find package:", distribution.download_url) @@ -149,7 +151,8 @@ def find_latest_dejacode_package(distribution): # there was no exact match, find the latest version # TODO: consider the closest version rather than the latest # or the version that has the best data - with_versions = [(packaging_version.parse(p["version"]), p) for p in packages] + with_versions = [(packaging_version.parse(p["version"]), p) + for p in packages] with_versions = sorted(with_versions) latest_version, latest_package_version = sorted(with_versions)[-1] print( diff --git a/etc/scripts/utils_requirements.py b/etc/scripts/utils_requirements.py index 0fc25a35..1c502390 100644 --- a/etc/scripts/utils_requirements.py +++ b/etc/scripts/utils_requirements.py @@ -5,7 +5,7 @@ # ScanCode is a trademark of nexB Inc. # SPDX-License-Identifier: Apache-2.0 # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. -# See https://github.com/nexB/skeleton for support or download. +# See https://github.com/aboutcode-org/skeleton for support or download. # See https://aboutcode.org for more information about nexB OSS projects. # @@ -102,7 +102,8 @@ def lock_dev_requirements( all_req_nvs = get_required_name_versions(all_req_lines) dev_only_req_nvs = {n: v for n, v in all_req_nvs if n not in main_names} - new_reqs = "\n".join(f"{n}=={v}" for n, v in sorted(dev_only_req_nvs.items())) + new_reqs = "\n".join( + f"{n}=={v}" for n, v in sorted(dev_only_req_nvs.items())) with open(dev_requirements_file, "w") as fo: fo.write(new_reqs) @@ -113,10 +114,12 @@ def get_installed_reqs(site_packages_dir): as a text. """ if not os.path.exists(site_packages_dir): - raise Exception(f"site_packages directory: {site_packages_dir!r} does not exists") + raise Exception( + f"site_packages directory: {site_packages_dir!r} does not exists") # Also include these packages in the output with --all: wheel, distribute, # setuptools, pip - args = ["pip", "freeze", "--exclude-editable", "--all", "--path", site_packages_dir] + args = ["pip", "freeze", "--exclude-editable", + "--all", "--path", site_packages_dir] return subprocess.check_output(args, encoding="utf-8") diff --git a/etc/scripts/utils_thirdparty.py b/etc/scripts/utils_thirdparty.py index addf8e5e..46dc7289 100644 --- a/etc/scripts/utils_thirdparty.py +++ b/etc/scripts/utils_thirdparty.py @@ -5,7 +5,7 @@ # ScanCode is a trademark of nexB Inc. # SPDX-License-Identifier: Apache-2.0 # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. -# See https://github.com/nexB/skeleton for support or download. +# See https://github.com/aboutcode-org/skeleton for support or download. # See https://aboutcode.org for more information about nexB OSS projects. # import email @@ -245,9 +245,11 @@ def download_wheel(name, version, environment, dest_dir=THIRDPARTY_DIR, repos=tu package = repo.get_package_version(name=name, version=version) if not package: if TRACE_DEEP: - print(f" download_wheel: No package in {repo.index_url} for {name}=={version}") + print( + f" download_wheel: No package in {repo.index_url} for {name}=={version}") continue - supported_wheels = list(package.get_supported_wheels(environment=environment)) + supported_wheels = list( + package.get_supported_wheels(environment=environment)) if not supported_wheels: if TRACE_DEEP: print( @@ -291,7 +293,8 @@ def download_sdist(name, version, dest_dir=THIRDPARTY_DIR, repos=tuple()): if not package: if TRACE_DEEP: - print(f" download_sdist: No package in {repo.index_url} for {name}=={version}") + print( + f" download_sdist: No package in {repo.index_url} for {name}=={version}") continue sdist = package.sdist if not sdist: @@ -300,7 +303,8 @@ def download_sdist(name, version, dest_dir=THIRDPARTY_DIR, repos=tuple()): continue if TRACE_DEEP: - print(f" download_sdist: Getting sdist from index (or cache): {sdist.download_url}") + print( + f" download_sdist: Getting sdist from index (or cache): {sdist.download_url}") fetched_sdist_filename = package.sdist.download(dest_dir=dest_dir) if fetched_sdist_filename: @@ -533,7 +537,8 @@ def get_best_download_url(self, repos=tuple()): repos = DEFAULT_PYPI_REPOS for repo in repos: - package = repo.get_package_version(name=self.name, version=self.version) + package = repo.get_package_version( + name=self.name, version=self.version) if not package: if TRACE: print( @@ -772,7 +777,8 @@ def load_remote_about_data(self): if notice_text: about_data["notice_text"] = notice_text except RemoteNotFetchedException: - print(f"Failed to fetch NOTICE file: {self.notice_download_url}") + print( + f"Failed to fetch NOTICE file: {self.notice_download_url}") return self.load_about_data(about_data) def get_checksums(self, dest_dir=THIRDPARTY_DIR): @@ -821,9 +827,11 @@ def fetch_license_files(self, dest_dir=THIRDPARTY_DIR, use_cached_index=False): Fetch license files if missing in `dest_dir`. Return True if license files were fetched. """ - urls = LinksRepository.from_url(use_cached_index=use_cached_index).links + urls = LinksRepository.from_url( + use_cached_index=use_cached_index).links errors = [] - extra_lic_names = [l.get("file") for l in self.extra_data.get("licenses", {})] + extra_lic_names = [l.get("file") + for l in self.extra_data.get("licenses", {})] extra_lic_names += [self.extra_data.get("license_file")] extra_lic_names = [ln for ln in extra_lic_names if ln] lic_names = [f"{key}.LICENSE" for key in self.get_license_keys()] @@ -834,7 +842,8 @@ def fetch_license_files(self, dest_dir=THIRDPARTY_DIR, use_cached_index=False): try: # try remotely first - lic_url = get_license_link_for_filename(filename=filename, urls=urls) + lic_url = get_license_link_for_filename( + filename=filename, urls=urls) fetch_and_save( path_or_url=lic_url, @@ -911,7 +920,8 @@ def load_pkginfo_data(self, dest_dir=THIRDPARTY_DIR): c for c in classifiers if c.startswith("License") ] license_expression = get_license_expression(declared_license) - other_classifiers = [c for c in classifiers if not c.startswith("License")] + other_classifiers = [ + c for c in classifiers if not c.startswith("License")] holder = raw_data["Author"] holder_contact = raw_data["Author-email"] @@ -953,7 +963,8 @@ def update(self, data, overwrite=False, keep_extra=True): package_url = data.get("package_url") if package_url: purl_from_data = packageurl.PackageURL.from_string(package_url) - purl_from_self = packageurl.PackageURL.from_string(self.package_url) + purl_from_self = packageurl.PackageURL.from_string( + self.package_url) if purl_from_data != purl_from_self: print( f"Invalid dist update attempt, no same same purl with dist: " @@ -1003,7 +1014,8 @@ def get_license_link_for_filename(filename, urls): if not path_or_url: raise Exception(f"Missing link to file: {filename}") if not len(path_or_url) == 1: - raise Exception(f"Multiple links to file: {filename}: \n" + "\n".join(path_or_url)) + raise Exception( + f"Multiple links to file: {filename}: \n" + "\n".join(path_or_url)) return path_or_url[0] @@ -1397,7 +1409,8 @@ def packages_from_dir(cls, directory): """ base = os.path.abspath(directory) - paths = [os.path.join(base, f) for f in os.listdir(base) if f.endswith(EXTENSIONS)] + paths = [os.path.join(base, f) + for f in os.listdir(base) if f.endswith(EXTENSIONS)] if TRACE_ULTRA_DEEP: print("packages_from_dir: paths:", paths) @@ -1458,7 +1471,8 @@ def dists_from_paths_or_urls(cls, paths_or_urls): dists = [] if TRACE_ULTRA_DEEP: print(" ###paths_or_urls:", paths_or_urls) - installable = [f for f in paths_or_urls if f.endswith(EXTENSIONS_INSTALLABLE)] + installable = [f for f in paths_or_urls if f.endswith( + EXTENSIONS_INSTALLABLE)] for path_or_url in installable: try: dist = Distribution.from_path_or_url(path_or_url) @@ -1476,7 +1490,8 @@ def dists_from_paths_or_urls(cls, paths_or_urls): ) except InvalidDistributionFilename: if TRACE_DEEP: - print(f" Skipping invalid distribution from: {path_or_url}") + print( + f" Skipping invalid distribution from: {path_or_url}") continue return dists @@ -1525,7 +1540,8 @@ class Environment: implementation = attr.ib( type=str, default="cp", - metadata=dict(help="Python implementation supported by this environment."), + metadata=dict( + help="Python implementation supported by this environment."), repr=False, ) @@ -1539,7 +1555,8 @@ class Environment: platforms = attr.ib( type=list, default=attr.Factory(list), - metadata=dict(help="List of platform tags supported by this environment."), + metadata=dict( + help="List of platform tags supported by this environment."), repr=False, ) @@ -1623,7 +1640,8 @@ class PypiSimpleRepository: fetched_package_normalized_names = attr.ib( type=set, default=attr.Factory(set), - metadata=dict(help="A set of already fetched package normalized names."), + metadata=dict( + help="A set of already fetched package normalized names."), ) use_cached_index = attr.ib( @@ -1654,10 +1672,12 @@ def _get_package_versions_map(self, name): self.packages[normalized_name] = versions except RemoteNotFetchedException as e: if TRACE: - print(f"failed to fetch package name: {name} from: {self.index_url}:\n{e}") + print( + f"failed to fetch package name: {name} from: {self.index_url}:\n{e}") if not versions and TRACE: - print(f"WARNING: package {name} not found in repo: {self.index_url}") + print( + f"WARNING: package {name} not found in repo: {self.index_url}") return versions @@ -1842,7 +1862,8 @@ def get(self, path_or_url, as_text=True, force=False): if force or not os.path.exists(cached): if TRACE_DEEP: print(f" FILE CACHE MISS: {path_or_url}") - content = get_file_content(path_or_url=path_or_url, as_text=as_text) + content = get_file_content( + path_or_url=path_or_url, as_text=as_text) wmode = "w" if as_text else "wb" with open(cached, wmode) as fo: fo.write(content) @@ -1864,7 +1885,8 @@ def get_file_content(path_or_url, as_text=True): if path_or_url.startswith("https://"): if TRACE_DEEP: print(f"Fetching: {path_or_url}") - _headers, content = get_remote_file_content(url=path_or_url, as_text=as_text) + _headers, content = get_remote_file_content( + url=path_or_url, as_text=as_text) return content elif path_or_url.startswith("file://") or ( @@ -1930,7 +1952,8 @@ def get_remote_file_content( ) else: - raise RemoteNotFetchedException(f"Failed HTTP request from {url} with {status}") + raise RemoteNotFetchedException( + f"Failed HTTP request from {url} with {status}") if headers_only: return response.headers, None @@ -2021,7 +2044,8 @@ def get_other_dists(_package, _dist): # if has key data we may look to improve later, but we can move on if local_dist.has_key_metadata(): local_dist.save_about_and_notice_files(dest_dir=dest_dir) - local_dist.fetch_license_files(dest_dir=dest_dir, use_cached_index=use_cached_index) + local_dist.fetch_license_files( + dest_dir=dest_dir, use_cached_index=use_cached_index) continue # lets try to get from another dist of the same local package @@ -2033,7 +2057,8 @@ def get_other_dists(_package, _dist): # if has key data we may look to improve later, but we can move on if local_dist.has_key_metadata(): local_dist.save_about_and_notice_files(dest_dir=dest_dir) - local_dist.fetch_license_files(dest_dir=dest_dir, use_cached_index=use_cached_index) + local_dist.fetch_license_files( + dest_dir=dest_dir, use_cached_index=use_cached_index) continue # try to get another version of the same package that is not our version @@ -2044,7 +2069,8 @@ def get_other_dists(_package, _dist): ] other_local_version = other_local_packages and other_local_packages[-1] if other_local_version: - latest_local_dists = list(other_local_version.get_distributions()) + latest_local_dists = list( + other_local_version.get_distributions()) for latest_local_dist in latest_local_dists: latest_local_dist.load_about_data(dest_dir=dest_dir) if not latest_local_dist.has_key_metadata(): @@ -2070,7 +2096,8 @@ def get_other_dists(_package, _dist): # if has key data we may look to improve later, but we can move on if local_dist.has_key_metadata(): local_dist.save_about_and_notice_files(dest_dir=dest_dir) - local_dist.fetch_license_files(dest_dir=dest_dir, use_cached_index=use_cached_index) + local_dist.fetch_license_files( + dest_dir=dest_dir, use_cached_index=use_cached_index) continue # try to get a latest version of the same package that is not our version @@ -2111,7 +2138,8 @@ def get_other_dists(_package, _dist): # if local_dist.has_key_metadata() or not local_dist.has_key_metadata(): local_dist.save_about_and_notice_files(dest_dir) - lic_errs = local_dist.fetch_license_files(dest_dir, use_cached_index=use_cached_index) + lic_errs = local_dist.fetch_license_files( + dest_dir, use_cached_index=use_cached_index) if not local_dist.has_key_metadata(): print(f"Unable to add essential ABOUT data for: {local_dist}") @@ -2259,7 +2287,8 @@ def find_problems( for dist in package.get_distributions(): dist.load_about_data(dest_dir=dest_dir) - abpth = os.path.abspath(os.path.join(dest_dir, dist.about_filename)) + abpth = os.path.abspath(os.path.join( + dest_dir, dist.about_filename)) if not dist.has_key_metadata(): print(f" Missing key ABOUT data in file://{abpth}") if "classifiers" in dist.extra_data: diff --git a/overlay.nix b/overlay.nix index 22e223a5..fc1596a8 100644 --- a/overlay.nix +++ b/overlay.nix @@ -31,7 +31,7 @@ final: prev: rec { meta = with lib; { description = "Library for parsing version ranges and expressions"; - homepage = "https://github.com/nexB/univers"; + homepage = "https://github.com/aboutcode-org/univers"; license = with licenses; [ asl20 bsd3 mit ]; }; }) diff --git a/setup.cfg b/setup.cfg index 614979dd..a40267a1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,7 +6,7 @@ license = Apache-2.0 AND BSD-3-Clause AND MIT description = A mostly universal library to parse and compare software package versions and version ranges. A companion to Package URLs. long_description = file:README.rst long_description_content_type = text/x-rst -url = https://github.com/nexB/univers +url = https://github.com/aboutcode-org/univers author = Shivam Sandbhor, nexB. Inc. and others author_email = info@aboutcode.org @@ -18,7 +18,7 @@ classifiers = Programming Language :: Python :: 3 :: Only Topic :: Software Development Topic :: Utilities -keywords = +keywords = semver utilities version diff --git a/src/univers/arch.py b/src/univers/arch.py index 898987d2..3eae6c9f 100644 --- a/src/univers/arch.py +++ b/src/univers/arch.py @@ -4,7 +4,7 @@ # Version utility extracted from msys2 https://github.com/msys2/msys2-web/ # and further stripped down. # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import re from itertools import zip_longest diff --git a/src/univers/conan/errors.py b/src/univers/conan/errors.py index bd965c13..40d1e886 100644 --- a/src/univers/conan/errors.py +++ b/src/univers/conan/errors.py @@ -2,7 +2,7 @@ # Copyright (c) 2019 JFrog LTD # SPDX-License-Identifier: MIT # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. """ Exceptions raised and handled in Conan diff --git a/src/univers/conan/version.py b/src/univers/conan/version.py index 9bd853b9..7cac8635 100644 --- a/src/univers/conan/version.py +++ b/src/univers/conan/version.py @@ -2,7 +2,7 @@ # Copyright (c) 2019 JFrog LTD # SPDX-License-Identifier: MIT # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. from functools import total_ordering diff --git a/src/univers/conan/version_range.py b/src/univers/conan/version_range.py index 7add0a8c..f64980fa 100644 --- a/src/univers/conan/version_range.py +++ b/src/univers/conan/version_range.py @@ -2,7 +2,7 @@ # Copyright (c) 2019 JFrog LTD # SPDX-License-Identifier: MIT # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. from collections import namedtuple diff --git a/src/univers/debian.py b/src/univers/debian.py index e7ab6ba4..463c2e72 100644 --- a/src/univers/debian.py +++ b/src/univers/debian.py @@ -1,12 +1,12 @@ # # Copyright (c) nexB Inc. and others. -# Extracted from http://nexb.com and https://github.com/nexB/debian_inspector/ +# Extracted from http://nexb.com and https://github.com/aboutcode-org/debian_inspector/ # Copyright (c) Peter Odding # Author: Peter Odding # URL: https://github.com/xolox/python-deb-pkg-tools # SPDX-License-Identifier: MIT # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import logging import operator as operator_module @@ -27,7 +27,7 @@ described at https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version -This has been substantially modified and enhanced from the original +This has been substantially modified and enhanced from the original python-deb-pkg-tools by Peter Odding to extract only the subset that does the version parsing, comparison and version constraints evaluation. diff --git a/src/univers/gem.py b/src/univers/gem.py index cb0d77d9..2b7259e5 100644 --- a/src/univers/gem.py +++ b/src/univers/gem.py @@ -6,7 +6,7 @@ # SPDX-License-Identifier: Apache-2.0 AND MIT # This has been significantly modified from the original # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. # notes: This has been substantially modified and enhanced from the original # puppeteer code to extract the Ruby version handling code. diff --git a/src/univers/gentoo.py b/src/univers/gentoo.py index 892a7ceb..543f8548 100644 --- a/src/univers/gentoo.py +++ b/src/univers/gentoo.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Version comparison utility extracted from pkgcore and further stripped down. # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import re diff --git a/src/univers/maven.py b/src/univers/maven.py index 072058d4..368437a4 100644 --- a/src/univers/maven.py +++ b/src/univers/maven.py @@ -4,7 +4,7 @@ # Version comparison utility extracted from pymaven and further stripped down # and significantly modified from the original at pymaven # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import functools from itertools import zip_longest diff --git a/src/univers/nuget.py b/src/univers/nuget.py index ff9ab0ce..a5cd8678 100644 --- a/src/univers/nuget.py +++ b/src/univers/nuget.py @@ -4,7 +4,7 @@ # Copyright 2022 Google LLC # modified by nexB and others for integration in the Univers library # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import functools import re diff --git a/src/univers/rpm.py b/src/univers/rpm.py index 1c35dc52..f597aca8 100644 --- a/src/univers/rpm.py +++ b/src/univers/rpm.py @@ -7,7 +7,7 @@ # stripped down and significantly modified from the original at python-rpm-vercmp # Also includes updates from Facebook antlir merged in. # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import re from typing import NamedTuple diff --git a/src/univers/univers_semver.py b/src/univers/univers_semver.py index 5b7469db..d617b4aa 100644 --- a/src/univers/univers_semver.py +++ b/src/univers/univers_semver.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. from univers.utils import remove_spaces from univers.version_constraint import VersionConstraint diff --git a/src/univers/utils.py b/src/univers/utils.py index b283d983..63952ce4 100644 --- a/src/univers/utils.py +++ b/src/univers/utils.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. def remove_spaces(string): diff --git a/src/univers/version_constraint.py b/src/univers/version_constraint.py index a96e667a..36ec6d81 100644 --- a/src/univers/version_constraint.py +++ b/src/univers/version_constraint.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import operator from functools import total_ordering diff --git a/src/univers/version_range.py b/src/univers/version_range.py index 422d2196..69f84f24 100644 --- a/src/univers/version_range.py +++ b/src/univers/version_range.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. from typing import List from typing import Union @@ -460,7 +460,7 @@ class GemVersionRange(VersionRange): A version range implementation for Rubygems. gem need its own versioning scheme as this is not semver. - See https//github.com/nexB/univers/issues/5 + See https//github.com/aboutcode-org/univers/issues/5 See https://github.com/ruby/ruby/blob/415671a28273e5bfbe9aa00a0e386f025720ac23/lib/rubygems/requirement.rb See https//semver.org/spec/v2.0.0.html#spec-item-11 See https//snyk.io/blog/differences-in-version-handling-gems-and-npm/ @@ -842,7 +842,7 @@ class NugetVersionRange(MavenVersionRange): class ComposerVersionRange(VersionRange): - # TODO composer may need its own scheme see https//github.com/nexB/univers/issues/5 + # TODO composer may need its own scheme see https//github.com/aboutcode-org/univers/issues/5 # and https//getcomposer.org/doc/articles/versions.md scheme = "composer" version_class = versions.ComposerVersion diff --git a/src/univers/versions.py b/src/univers/versions.py index 768a2c86..14b3e007 100644 --- a/src/univers/versions.py +++ b/src/univers/versions.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import attr import semantic_version diff --git a/tests/test_alpine.py b/tests/test_alpine.py index 681ed0ed..fa9598fc 100644 --- a/tests/test_alpine.py +++ b/tests/test_alpine.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import operator from typing import NamedTuple diff --git a/tests/test_codestyle.py b/tests/test_codestyle.py index c0fbd5e0..610acbd0 100644 --- a/tests/test_codestyle.py +++ b/tests/test_codestyle.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import subprocess import sys diff --git a/tests/test_conan_version_bump.py b/tests/test_conan_version_bump.py index 892cb1f5..51c7fc7e 100644 --- a/tests/test_conan_version_bump.py +++ b/tests/test_conan_version_bump.py @@ -2,7 +2,7 @@ # Copyright (c) 2019 JFrog LTD # SPDX-License-Identifier: MIT # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import pytest diff --git a/tests/test_conan_version_comparison.py b/tests/test_conan_version_comparison.py index 7e4da43d..d7cec4d2 100644 --- a/tests/test_conan_version_comparison.py +++ b/tests/test_conan_version_comparison.py @@ -2,7 +2,7 @@ # Copyright (c) 2019 JFrog LTD # SPDX-License-Identifier: MIT # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import pytest diff --git a/tests/test_conan_version_range.py b/tests/test_conan_version_range.py index 1bf7e69f..73b22788 100644 --- a/tests/test_conan_version_range.py +++ b/tests/test_conan_version_range.py @@ -2,7 +2,7 @@ # Copyright (c) 2019 JFrog LTD # SPDX-License-Identifier: MIT # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import pytest @@ -15,13 +15,18 @@ ["<2.0", [[["<", "2.0"]]], ["1.0.1"], ["2.1"]], [">1 <2.0", [[[">", "1"], ["<", "2.0"]]], ["1.5.1"], ["0.1", "2.1"]], # tilde - ["~2.5", [[[">=", "2.5"], ["<", "2.6-"]]], ["2.5.0", "2.5.3"], ["2.7", "2.6.1"]], - ["~2.5.1", [[[">=", "2.5.1"], ["<", "2.6.0-"]]], ["2.5.1", "2.5.3"], ["2.5", "2.6.1"]], + ["~2.5", [[[">=", "2.5"], ["<", "2.6-"]]], + ["2.5.0", "2.5.3"], ["2.7", "2.6.1"]], + ["~2.5.1", [[[">=", "2.5.1"], ["<", "2.6.0-"]]], + ["2.5.1", "2.5.3"], ["2.5", "2.6.1"]], ["~1", [[[">=", "1"], ["<", "2-"]]], ["1.3", "1.8.1"], ["0.8", "2.2"]], # caret - ["^1.2", [[[">=", "1.2"], ["<", "2.0-"]]], ["1.2.1", "1.51"], ["1", "2", "2.0.1"]], - ["^1.2.3", [[[">=", "1.2.3"], ["<", "2.0.0-"]]], ["1.2.3", "1.2.4"], ["2", "2.1", "2.0.1"]], - ["^0.1.2", [[[">=", "0.1.2"], ["<", "0.2.0-"]]], ["0.1.3", "0.1.44"], ["1", "0.3", "0.2.1"]], + ["^1.2", [[[">=", "1.2"], ["<", "2.0-"]]], + ["1.2.1", "1.51"], ["1", "2", "2.0.1"]], + ["^1.2.3", [[[">=", "1.2.3"], ["<", "2.0.0-"]]], + ["1.2.3", "1.2.4"], ["2", "2.1", "2.0.1"]], + ["^0.1.2", [[[">=", "0.1.2"], ["<", "0.2.0-"]]], + ["0.1.3", "0.1.44"], ["1", "0.3", "0.2.1"]], # Identity ["1.0.0", [[["=", "1.0.0"]]], ["1.0.0"], ["2", "1.0.1"]], ["=1.0.0", [[["=", "1.0.0"]]], ["1.0.0"], ["2", "1.0.1"]], @@ -29,7 +34,8 @@ ["*", [[[">=", "0.0.0"]]], ["1.0", "a.b"], []], ["", [[[">=", "0.0.0"]]], ["1.0", "a.b"], []], # Unions - ["1.0.0 || 2.1.3", [[["=", "1.0.0"]], [["=", "2.1.3"]]], ["1.0.0", "2.1.3"], ["2", "1.0.1"]], + ["1.0.0 || 2.1.3", [[["=", "1.0.0"]], [["=", "2.1.3"]]], + ["1.0.0", "2.1.3"], ["2", "1.0.1"]], [ ">1 <2.0 || ^3.2 ", [[[">", "1"], ["<", "2.0"]], [[">=", "3.2"], ["<", "4.0-"]]], @@ -47,8 +53,10 @@ ["1.5-a1", "3.3"], ["3.3-a1"], ], - ["^1.1.2-", [[[">=", "1.1.2"], ["<", "2.0.0-"]]], ["1.2.3", "1.2.0-alpha1"], ["2.0.0-alpha1"]], - ["~1.1.2-", [[[">=", "1.1.2"], ["<", "1.2.0-"]]], ["1.1.3", "1.1.3-alpha1"], ["1.2.0-alpha1"]], + ["^1.1.2-", [[[">=", "1.1.2"], ["<", "2.0.0-"]]], + ["1.2.3", "1.2.0-alpha1"], ["2.0.0-alpha1"]], + ["~1.1.2-", [[[">=", "1.1.2"], ["<", "1.2.0-"]]], + ["1.1.3", "1.1.3-alpha1"], ["1.2.0-alpha1"]], ] diff --git a/tests/test_debian_version.py b/tests/test_debian_version.py index c9507f5b..e04c1905 100644 --- a/tests/test_debian_version.py +++ b/tests/test_debian_version.py @@ -4,12 +4,12 @@ # original author: Nathan J. Meh # Copyright (c) nexB Inc. and others. -# http://nexb.com and https://github.com/nexB/debian_inspector/ +# http://nexb.com and https://github.com/aboutcode-org/debian_inspector/ # SPDX-License-Identifier: Apache-2.0 # this has been significantly modified from the original # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. from unittest import TestCase @@ -91,7 +91,8 @@ def test_compare_strings(self): def test_compare_strings_can_sort(self): # taken from # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version - result = sorted(["a", "", "~", "~~a", "~~"], key=version.compare_strings_key) + result = sorted(["a", "", "~", "~~a", "~~"], + key=version.compare_strings_key) expected = ["~~", "~~a", "~", "", "a"] assert expected == result @@ -151,8 +152,10 @@ def test_compare_versions(self): assert compare_versions("9.0.0", "10.0.0") == -1 assert compare_versions("1.2.3-1~deb7u1", "1.2.3-1") == -1 - assert compare_versions("2.7.4+reloaded2-13ubuntu1", "2.7.4+reloaded2-13+deb9u1") == -1 - assert compare_versions("2.7.4+reloaded2-13", "2.7.4+reloaded2-13+deb9u1") == -1 + assert compare_versions( + "2.7.4+reloaded2-13ubuntu1", "2.7.4+reloaded2-13+deb9u1") == -1 + assert compare_versions("2.7.4+reloaded2-13", + "2.7.4+reloaded2-13+deb9u1") == -1 # greater than assert compare_versions("0.0.1-0", "0:0.0.0") == 1 @@ -163,8 +166,10 @@ def test_compare_versions(self): assert compare_versions("9.0.0", "1.0.0") == 1 assert compare_versions("1.2.3-1", "1.2.3-1~deb7u1") == 1 - assert compare_versions("2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13ubuntu1") == 1 - assert compare_versions("2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13") == 1 + assert compare_versions( + "2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13ubuntu1") == 1 + assert compare_versions( + "2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13") == 1 # unicode assert compare_versions("2:0.0.44-1", "2:0.0.44-nobin") == -1 diff --git a/tests/test_debian_version.py.ABOUT b/tests/test_debian_version.py.ABOUT index 891ec3af..3171974b 100644 --- a/tests/test_debian_version.py.ABOUT +++ b/tests/test_debian_version.py.ABOUT @@ -4,5 +4,5 @@ download_url: https://raw.githubusercontent.com/nexB/debian-inspector/b8f413de99 copyright: Copyright (c) nexB Inc. and others. package_url: pkg:pypi/debian-inspector@0.9.10#tests/test_version.py notes: this subset of tests has been modified to tests version comparison and parsing -homepage_url: https://github.com/nexB/debian-inspector -notice_file: test_debian_version.py.NOTICE \ No newline at end of file +homepage_url: https://github.com/aboutcode-org/debian-inspector +notice_file: test_debian_version.py.NOTICE diff --git a/tests/test_debian_version_python_deb_pkg_tools.py b/tests/test_debian_version_python_deb_pkg_tools.py index ca0c4657..6c225dfc 100644 --- a/tests/test_debian_version_python_deb_pkg_tools.py +++ b/tests/test_debian_version_python_deb_pkg_tools.py @@ -3,7 +3,7 @@ # URL: https://github.com/xolox/python-deb-pkg-tools # SPDX-License-Identifier: MIT # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. from unittest import TestCase @@ -16,7 +16,8 @@ def test_version_sorting(self): # Check version sorting implemented on top of `=' and `<<' comparisons. expected_order = ["0.1", "0.5", "1.0", "2.0", "3.0", "1:0.4", "2:0.3"] assert list(sorted(expected_order)) != expected_order - result = [str(v) for v in sorted(map(Version.from_string, expected_order))] + result = [str(v) + for v in sorted(map(Version.from_string, expected_order))] assert result == expected_order def test_version_comparison(self): diff --git a/tests/test_gem.py b/tests/test_gem.py index 2a675bed..2cde6e51 100644 --- a/tests/test_gem.py +++ b/tests/test_gem.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # this has been significantly modified from the original # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. # notes: This has been substantially modified and enhanced from the original # puppeteer code to extract the Ruby version handling code. diff --git a/tests/test_gentoo.py b/tests/test_gentoo.py index eeabacbc..da1682ef 100644 --- a/tests/test_gentoo.py +++ b/tests/test_gentoo.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: GPL-2.0-only # this has been significantly modified from the original # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. from unittest import TestCase diff --git a/tests/test_gentoo_pkgcore.py b/tests/test_gentoo_pkgcore.py index bb417c1c..0d3a1519 100644 --- a/tests/test_gentoo_pkgcore.py +++ b/tests/test_gentoo_pkgcore.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Version comparison utility extracted from pkgcore and further stripped down. # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. from random import shuffle @@ -16,10 +16,12 @@ def generate_misc_sufs(): suf_nums = list(range(100)) shuffle(suf_nums) - good_sufs = simple_good_sufs + [f"{x}{suf_nums.pop()}" for x in simple_good_sufs] + good_sufs = simple_good_sufs + \ + [f"{x}{suf_nums.pop()}" for x in simple_good_sufs] l = len(good_sufs) - good_sufs = good_sufs + [good_sufs[x] + good_sufs[l - x - 1] for x in range(l)] + good_sufs = good_sufs + [good_sufs[x] + + good_sufs[l - x - 1] for x in range(l)] bad_sufs = ["_a", "_9", "_"] + [x + " " for x in simple_good_sufs] return good_sufs, bad_sufs @@ -63,7 +65,8 @@ def test_parse_version_and_revisions(self): v_r = parse_version_and_revision(version) expected_rev = rev.lstrip("-r") expected_rev = expected_rev and int(expected_rev) or 0 - assert v_r == (ver, expected_rev), f"Failed to parse: {version}" + assert v_r == ( + ver, expected_rev), f"Failed to parse: {version}" except Exception as e: raise Exception(f"Failed to parse: {version!r}") from e diff --git a/tests/test_maven_version.py b/tests/test_maven_version.py index 97d25585..f57561d7 100644 --- a/tests/test_maven_version.py +++ b/tests/test_maven_version.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 # this has been significantly modified from the original# # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import unittest @@ -240,7 +240,8 @@ def test_from_string(self): for test, expected in test_pairs: v = Version(test) - assert v._parsed == expected, "Version(%s) == %s, want %s" % (test, v._parsed, expected) + assert v._parsed == expected, "Version(%s) == %s, want %s" % ( + test, v._parsed, expected) def test_version_qualifiers(self): version_qualifiers = ( @@ -268,7 +269,7 @@ def test_version_qualifiers(self): "1-123", ) for idx, low in enumerate(version_qualifiers[:-1]): - for high in version_qualifiers[idx + 1 :]: + for high in version_qualifiers[idx + 1:]: self._assert_version_order(low, high) def test_version_numbers(self): @@ -300,7 +301,7 @@ def test_version_numbers(self): "11m", ) for idx, low in enumerate(version_numbers[:-1]): - for high in version_numbers[idx + 1 :]: + for high in version_numbers[idx + 1:]: self._assert_version_order(low, high) unicode_version_numbers = ( @@ -332,7 +333,7 @@ def test_version_numbers(self): "11m", ) for idx, low in enumerate(unicode_version_numbers[:-1]): - for high in unicode_version_numbers[idx + 1 :]: + for high in unicode_version_numbers[idx + 1:]: self._assert_version_order(low, high) def test_version_equality(self): @@ -622,7 +623,8 @@ def test_compare(self): def test_str(self): for inp in ("[1.0,2.0]", "1.0"): actual = str(VersionRange(inp)) - assert inp == actual, "VersionRange(%s) == %s, wanted %s" % (inp, actual, inp) + assert inp == actual, "VersionRange(%s) == %s, wanted %s" % ( + inp, actual, inp) def test_fromversion(self): v = Version("1.0") @@ -631,7 +633,8 @@ def test_fromversion(self): assert vr.version == v def test_match_versions(self): - versions = [Version("0.1"), Version("1.0"), Version("1.1"), Version("2.0"), Version("2.1")] + versions = [Version("0.1"), Version("1.0"), Version( + "1.1"), Version("2.0"), Version("2.1")] vr = VersionRange("(1.0,2.0]") assert vr.match_version(versions) == "2.0" assert vr.match_version(versions[:3]) == "1.1" diff --git a/tests/test_maven_version_range.py b/tests/test_maven_version_range.py index 2f487a04..b49c67c9 100644 --- a/tests/test_maven_version_range.py +++ b/tests/test_maven_version_range.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. from univers.version_constraint import VersionConstraint from univers.version_range import MavenVersionRange @@ -13,8 +13,10 @@ def test_maven_version_range_from_native_with_lower_inclusive(): version_range = MavenVersionRange.from_native("[1.0.0,2.0.0)") assert version_range == MavenVersionRange( constraints=( - VersionConstraint(comparator=">=", version=MavenVersion(string="1.0.0")), - VersionConstraint(comparator="<", version=MavenVersion(string="2.0.0")), + VersionConstraint( + comparator=">=", version=MavenVersion(string="1.0.0")), + VersionConstraint( + comparator="<", version=MavenVersion(string="2.0.0")), ) ) @@ -23,8 +25,10 @@ def test_maven_version_range_from_native_with_nothing_inclusive(): version_range = MavenVersionRange.from_native(" ( 1.0.0 , 2.1.4 ) ") assert version_range == MavenVersionRange( constraints=( - VersionConstraint(comparator=">", version=MavenVersion(string="1.0.0")), - VersionConstraint(comparator="<", version=MavenVersion(string="2.1.4")), + VersionConstraint( + comparator=">", version=MavenVersion(string="1.0.0")), + VersionConstraint( + comparator="<", version=MavenVersion(string="2.1.4")), ) ) @@ -32,7 +36,8 @@ def test_maven_version_range_from_native_with_nothing_inclusive(): def test_maven_version_range_from_native_for_pinned_version(): version_range = MavenVersionRange.from_native("[1.0.0]") assert version_range == MavenVersionRange( - constraints=(VersionConstraint(comparator="=", version=MavenVersion(string="1.0.0")),) + constraints=(VersionConstraint(comparator="=", + version=MavenVersion(string="1.0.0")),) ) @@ -50,26 +55,38 @@ def test_maven_version_range_from_native_str_representation(): def test_maven_version_range_from_native_for_multiple_version_ranges(): - version_range = MavenVersionRange.from_native("[2.0,2.3.1] , [2.4.0,2.12.2) , [2.13.0,2.15.0)") + version_range = MavenVersionRange.from_native( + "[2.0,2.3.1] , [2.4.0,2.12.2) , [2.13.0,2.15.0)") assert version_range == MavenVersionRange( constraints=( - VersionConstraint(comparator=">=", version=MavenVersion(string="2.0")), - VersionConstraint(comparator="<=", version=MavenVersion(string="2.3.1")), - VersionConstraint(comparator=">=", version=MavenVersion(string="2.4.0")), - VersionConstraint(comparator="<", version=MavenVersion(string="2.12.2")), - VersionConstraint(comparator=">=", version=MavenVersion(string="2.13.0")), - VersionConstraint(comparator="<", version=MavenVersion(string="2.15.0")), + VersionConstraint( + comparator=">=", version=MavenVersion(string="2.0")), + VersionConstraint( + comparator="<=", version=MavenVersion(string="2.3.1")), + VersionConstraint( + comparator=">=", version=MavenVersion(string="2.4.0")), + VersionConstraint( + comparator="<", version=MavenVersion(string="2.12.2")), + VersionConstraint( + comparator=">=", version=MavenVersion(string="2.13.0")), + VersionConstraint( + comparator="<", version=MavenVersion(string="2.15.0")), ) ) def test_maven_version_range_from_native_for_multiple_pinned_versions_and_a_range(): - version_range = MavenVersionRange.from_native("[2.0] , [2.4.0] , [2.13.0,2.15.0)") + version_range = MavenVersionRange.from_native( + "[2.0] , [2.4.0] , [2.13.0,2.15.0)") assert version_range == MavenVersionRange( constraints=( - VersionConstraint(comparator="=", version=MavenVersion(string="2.0")), - VersionConstraint(comparator="=", version=MavenVersion(string="2.4.0")), - VersionConstraint(comparator=">=", version=MavenVersion(string="2.13.0")), - VersionConstraint(comparator="<", version=MavenVersion(string="2.15.0")), + VersionConstraint( + comparator="=", version=MavenVersion(string="2.0")), + VersionConstraint( + comparator="=", version=MavenVersion(string="2.4.0")), + VersionConstraint( + comparator=">=", version=MavenVersion(string="2.13.0")), + VersionConstraint( + comparator="<", version=MavenVersion(string="2.15.0")), ) ) diff --git a/tests/test_openssl_vercmp.py b/tests/test_openssl_vercmp.py index 7f5a622c..0efb195f 100644 --- a/tests/test_openssl_vercmp.py +++ b/tests/test_openssl_vercmp.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import operator diff --git a/tests/test_openssl_versort.py b/tests/test_openssl_versort.py index 08627e60..300db84f 100644 --- a/tests/test_openssl_versort.py +++ b/tests/test_openssl_versort.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. from pathlib import Path @@ -22,7 +22,8 @@ def test_openssl_version_sort(self): results = [OpensslVersion(x.strip()) for x in all_openssl_versions] results.sort() results = [version_to_dict(x) for x in results] - expected_file = self.get_test_loc("openssl_versort_expected.json", must_exist=False) + expected_file = self.get_test_loc( + "openssl_versort_expected.json", must_exist=False) util_tests.check_results_against_json(results, expected_file) diff --git a/tests/test_pacman_vercmp.py b/tests/test_pacman_vercmp.py index 278947a2..e6f2cdf4 100644 --- a/tests/test_pacman_vercmp.py +++ b/tests/test_pacman_vercmp.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 # this has been significantly modified from the original # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. from univers.versions import ArchLinuxVersion diff --git a/tests/test_pypi_version.py b/tests/test_pypi_version.py index d4ade6da..7b6325d7 100644 --- a/tests/test_pypi_version.py +++ b/tests/test_pypi_version.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. from unittest import TestCase diff --git a/tests/test_python_semver.py b/tests/test_python_semver.py index 9ca1807f..5111bc00 100644 --- a/tests/test_python_semver.py +++ b/tests/test_python_semver.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. from unittest import TestCase diff --git a/tests/test_rpm_vercmp.py b/tests/test_rpm_vercmp.py index 785ff37a..ad7f4554 100644 --- a/tests/test_rpm_vercmp.py +++ b/tests/test_rpm_vercmp.py @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 # this has been significantly modified from the original # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import io import os @@ -76,7 +76,8 @@ def create_test_function(ver1, ver2, expected, name): def test_rpm_version(self): ver1_str = str(ver1).encode("utf-8") ver2_str = str(ver2).encode("utf-8") - print(f"testing (ver1={ver1_str}, ver2={ver2_str}, expected=expected{expected}") + print( + f"testing (ver1={ver1_str}, ver2={ver2_str}, expected=expected{expected}") result = vercmp.vercmp(ver1, ver2) if result != expected: assert result == (expected, ver1, ver2) @@ -92,7 +93,8 @@ def get_tests(): test_file = os.path.join(os.path.dirname(__file__), "data", "rpmvercmp.at") with io.open(test_file, encoding="utf-8") as rpmtests: - tests = list(parse_rpmvercmp_tests(rpmtests, with_buggy_comparisons=True)) + tests = list(parse_rpmvercmp_tests( + rpmtests, with_buggy_comparisons=True)) for test_count, (ver1, ver2, expected) in enumerate(tests, 1): name = f"test_rpm_version_{test_count}" yield create_test_function(ver1, ver2, expected, name) diff --git a/tests/test_skeleton_codestyle.py b/tests/test_skeleton_codestyle.py index 3304806a..328f0c8b 100644 --- a/tests/test_skeleton_codestyle.py +++ b/tests/test_skeleton_codestyle.py @@ -3,7 +3,7 @@ # ScanCode is a trademark of nexB Inc. # SPDX-License-Identifier: Apache-2.0 # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. -# See https://github.com/nexB/skeleton for support or download. +# See https://github.com/aboutcode-org/skeleton for support or download. # See https://aboutcode.org for more information about nexB OSS projects. # diff --git a/tests/test_vers.py b/tests/test_vers.py index e4258499..3b322858 100644 --- a/tests/test_vers.py +++ b/tests/test_vers.py @@ -3,7 +3,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import json import os diff --git a/tests/test_version_comparison.py b/tests/test_version_comparison.py index b77843db..6efaeeba 100644 --- a/tests/test_version_comparison.py +++ b/tests/test_version_comparison.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import pytest diff --git a/tests/test_version_constraint.py b/tests/test_version_constraint.py index b4b5df9b..b58828ec 100644 --- a/tests/test_version_constraint.py +++ b/tests/test_version_constraint.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import pytest diff --git a/tests/test_version_range.py b/tests/test_version_range.py index 8361467c..e9479b61 100644 --- a/tests/test_version_range.py +++ b/tests/test_version_range.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import json from unittest import TestCase @@ -34,14 +34,16 @@ class TestVersionRange(TestCase): def test_VersionRange_afrom_string(self): version_range = VersionRange.from_string("vers:pypi/>0.0.2") assert version_range == PypiVersionRange( - constraints=[VersionConstraint(comparator=">", version=PypiVersion(string="0.0.2"))] + constraints=[VersionConstraint( + comparator=">", version=PypiVersion(string="0.0.2"))] ) def test_VersionRange_to_string(self): vers = "vers:pypi/0.0.2|0.0.6|>=0.0.0|0.0.1|0.0.4|0.0.5|0.0.3" version_range = VersionRange.from_string(vers) # note the sorting taking place - assert str(version_range) == "vers:pypi/>=0.0.0|0.0.1|0.0.2|0.0.3|0.0.4|0.0.5|0.0.6" + assert str( + version_range) == "vers:pypi/>=0.0.0|0.0.1|0.0.2|0.0.3|0.0.4|0.0.5|0.0.6" def test_VersionRange_pypi_does_not_contain_basic(self): vers = "vers:pypi/0.0.2|0.0.6|>=3.0.0|0.0.1|0.0.4|0.0.5|0.0.3" @@ -97,25 +99,36 @@ def test_VersionRange_from_string_pypi(self): assert version_range.scheme == "pypi" # note the sorting taking place expected = ( - VersionConstraint(comparator="=", version=PypiVersion(string="0.0.0")), - VersionConstraint(comparator="=", version=PypiVersion(string="0.0.1")), - VersionConstraint(comparator="=", version=PypiVersion(string="0.0.2")), - VersionConstraint(comparator="=", version=PypiVersion(string="0.0.3")), - VersionConstraint(comparator="=", version=PypiVersion(string="0.0.4")), - VersionConstraint(comparator="=", version=PypiVersion(string="0.0.5")), - VersionConstraint(comparator="=", version=PypiVersion(string="0.0.6")), + VersionConstraint( + comparator="=", version=PypiVersion(string="0.0.0")), + VersionConstraint( + comparator="=", version=PypiVersion(string="0.0.1")), + VersionConstraint( + comparator="=", version=PypiVersion(string="0.0.2")), + VersionConstraint( + comparator="=", version=PypiVersion(string="0.0.3")), + VersionConstraint( + comparator="=", version=PypiVersion(string="0.0.4")), + VersionConstraint( + comparator="=", version=PypiVersion(string="0.0.5")), + VersionConstraint( + comparator="=", version=PypiVersion(string="0.0.6")), ) assert version_range.constraints == expected # note the sorting taking place - assert str(version_range) == "vers:pypi/0.0.0|0.0.1|0.0.2|0.0.3|0.0.4|0.0.5|0.0.6" + assert str( + version_range) == "vers:pypi/0.0.0|0.0.1|0.0.2|0.0.3|0.0.4|0.0.5|0.0.6" - version_range1 = VersionRange.from_string(vers, simplify=False, validate=True) + version_range1 = VersionRange.from_string( + vers, simplify=False, validate=True) assert version_range1.constraints == expected - version_range2 = VersionRange.from_string(vers, simplify=True, validate=False) + version_range2 = VersionRange.from_string( + vers, simplify=True, validate=False) assert version_range2.constraints == expected - version_range3 = VersionRange.from_string(vers, simplify=True, validate=True) + version_range3 = VersionRange.from_string( + vers, simplify=True, validate=True) assert version_range3.constraints == expected def test_VersionRange_from_string_pypi_complex_simplify(self): @@ -127,74 +140,90 @@ def test_VersionRange_from_string_pypi_complex_simplify(self): raise Exception(f"Exception not raised: {vers}") except ValueError: pass - version_range = VersionRange.from_string(vers, validate=True, simplify=True) + version_range = VersionRange.from_string( + vers, validate=True, simplify=True) assert str(version_range) == "vers:pypi/>0.0.0|<0.0.5|>=0.0.6" def test_VersionRange_from_string_pypi_complex_simplify_and_validate(self): vers = "vers:pypi/>0.0.0|>=0.0.1|0.0.2|0.0.3|0.0.4|<0.0.5|>=0.0.6|!=0.8" version_range = VersionRange.from_string(vers, simplify=True) assert str(version_range) == "vers:pypi/>0.0.0|<0.0.5|>=0.0.6|!=0.8" - version_range = VersionRange.from_string(vers, simplify=True, validate=True) + version_range = VersionRange.from_string( + vers, simplify=True, validate=True) def test_VersionRange_from_string_pypi_complex_simplify2(self): vers = ( "vers:pypi/>0.0.0|>=0.0.1|>=0.0.1|0.0.2|0.0.3|0.0.4|<0.0.5|<=0.0.6|!=0.7|8.0|>12|<15.3" ) version_range = VersionRange.from_string(vers, simplify=True) - assert str(version_range) == "vers:pypi/>0.0.0|<=0.0.6|!=0.7|8.0|>12|<15.3" + assert str( + version_range) == "vers:pypi/>0.0.0|<=0.0.6|!=0.7|8.0|>12|<15.3" def test_VersionRange_from_string_pypi_simple_cases(self): vers = "vers:pypi/>0.0.1" - version_range = VersionRange.from_string(vers, simplify=True, validate=True) + version_range = VersionRange.from_string( + vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/>=0.0.1" - version_range = VersionRange.from_string(vers, simplify=True, validate=True) + version_range = VersionRange.from_string( + vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/<0.0.1" - version_range = VersionRange.from_string(vers, simplify=True, validate=True) + version_range = VersionRange.from_string( + vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/<=0.0.1" - version_range = VersionRange.from_string(vers, simplify=True, validate=True) + version_range = VersionRange.from_string( + vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/0.0.1" - version_range = VersionRange.from_string(vers, simplify=True, validate=True) + version_range = VersionRange.from_string( + vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/!=0.0.1" - version_range = VersionRange.from_string(vers, simplify=True, validate=True) + version_range = VersionRange.from_string( + vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/*" - version_range = VersionRange.from_string(vers, simplify=True, validate=True) + version_range = VersionRange.from_string( + vers, simplify=True, validate=True) assert str(version_range) == vers def test_VersionRange_from_string_pypi_two_cases(self): vers = "vers:pypi/>0.0.1|<0.1" - version_range = VersionRange.from_string(vers, simplify=True, validate=True) + version_range = VersionRange.from_string( + vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/>=0.0.1|<0.1" - version_range = VersionRange.from_string(vers, simplify=True, validate=True) + version_range = VersionRange.from_string( + vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/<0.0.1|>0.1" - version_range = VersionRange.from_string(vers, simplify=True, validate=True) + version_range = VersionRange.from_string( + vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/<=0.0.1|>0.1" - version_range = VersionRange.from_string(vers, simplify=True, validate=True) + version_range = VersionRange.from_string( + vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/0.0.1|>0.1" - version_range = VersionRange.from_string(vers, simplify=True, validate=True) + version_range = VersionRange.from_string( + vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/!=0.0.1|>0.1" - version_range = VersionRange.from_string(vers, simplify=True, validate=True) + version_range = VersionRange.from_string( + vers, simplify=True, validate=True) assert str(version_range) == vers def test_GemVersionRange_from_native_range_with_pessimistic_operator(self): @@ -202,21 +231,26 @@ def test_GemVersionRange_from_native_range_with_pessimistic_operator(self): version_range = GemVersionRange.from_native(gem_range) assert version_range.to_string() == "vers:gem/>=2.0.8|<2.1" assert version_range.constraints == ( - VersionConstraint(comparator=">=", version=RubygemsVersion(string="2.0.8")), - VersionConstraint(comparator="<", version=RubygemsVersion(string="2.1")), + VersionConstraint( + comparator=">=", version=RubygemsVersion(string="2.0.8")), + VersionConstraint( + comparator="<", version=RubygemsVersion(string="2.1")), ) def test_VersionRange_contains_works_for_star_range(self): from univers.versions import NginxVersion - assert NginxVersion("1.0.0") in VersionRange.from_string("vers:nginx/*") + assert NginxVersion( + "1.0.0") in VersionRange.from_string("vers:nginx/*") def test_NpmVersionRange_from_native_with_compatible_with_version_operator(self): npm_range = "^1.2.9" expected = NpmVersionRange( constraints=( - VersionConstraint(comparator=">=", version=SemverVersion(string="1.2.9")), - VersionConstraint(comparator="<", version=SemverVersion(string="2.0.0")), + VersionConstraint( + comparator=">=", version=SemverVersion(string="1.2.9")), + VersionConstraint( + comparator="<", version=SemverVersion(string="2.0.0")), ) ) version_range = NpmVersionRange.from_native(npm_range) @@ -226,8 +260,10 @@ def test_NpmVersionRange_from_native_with_prerelease_carate_range(self): npm_range = "^1.2.3-beta.1" expected = NpmVersionRange( constraints=( - VersionConstraint(comparator=">=", version=SemverVersion(string="1.2.3-beta.1")), - VersionConstraint(comparator="<", version=SemverVersion(string="2.0.0")), + VersionConstraint( + comparator=">=", version=SemverVersion(string="1.2.3-beta.1")), + VersionConstraint( + comparator="<", version=SemverVersion(string="2.0.0")), ) ) version_range = NpmVersionRange.from_native(npm_range) @@ -237,8 +273,10 @@ def test_NpmVersionRange_from_native_with_prerelease_carate_range_wihtout_major( npm_range = "^0.2.1-beta" expected = NpmVersionRange( constraints=( - VersionConstraint(comparator=">=", version=SemverVersion(string="0.2.1-beta")), - VersionConstraint(comparator="<", version=SemverVersion(string="0.3.0")), + VersionConstraint( + comparator=">=", version=SemverVersion(string="0.2.1-beta")), + VersionConstraint( + comparator="<", version=SemverVersion(string="0.3.0")), ) ) version_range = NpmVersionRange.from_native(npm_range) @@ -248,8 +286,10 @@ def test_NpmVersionRange_from_native_with_prerelease_carate_range_wihtout_major_ npm_range = "^0.0.2-beta" expected = NpmVersionRange( constraints=( - VersionConstraint(comparator=">=", version=SemverVersion(string="0.0.2-beta")), - VersionConstraint(comparator="<", version=SemverVersion(string="0.0.3")), + VersionConstraint( + comparator=">=", version=SemverVersion(string="0.0.2-beta")), + VersionConstraint( + comparator="<", version=SemverVersion(string="0.0.3")), ) ) version_range = NpmVersionRange.from_native(npm_range) @@ -259,8 +299,10 @@ def test_NpmVersionRange_from_native_with_approximately_equal_to_operator(self): npm_range = "~3.8.2" expected = NpmVersionRange( constraints=( - VersionConstraint(comparator=">=", version=SemverVersion(string="3.8.2")), - VersionConstraint(comparator="<", version=SemverVersion(string="3.9.0")), + VersionConstraint( + comparator=">=", version=SemverVersion(string="3.8.2")), + VersionConstraint( + comparator="<", version=SemverVersion(string="3.9.0")), ) ) version_range = NpmVersionRange.from_native(npm_range) @@ -270,7 +312,8 @@ def test_OpensslVersionRange_from_native_single_legacy(self): openssl_range = "0.9.8j" expected = OpensslVersionRange( constraints=( - VersionConstraint(comparator="=", version=OpensslVersion(string="0.9.8j")), + VersionConstraint( + comparator="=", version=OpensslVersion(string="0.9.8j")), ) ) version_range = OpensslVersionRange.from_native(openssl_range) @@ -279,7 +322,8 @@ def test_OpensslVersionRange_from_native_single_legacy(self): def test_OpensslVersionRange_from_native_single_new_semver(self): openssl_range = "3.0.1" expected = OpensslVersionRange( - constraints=(VersionConstraint(comparator="=", version=OpensslVersion(string="3.0.1")),) + constraints=(VersionConstraint(comparator="=", + version=OpensslVersion(string="3.0.1")),) ) version_range = OpensslVersionRange.from_native(openssl_range) assert version_range == expected @@ -288,8 +332,10 @@ def test_OpensslVersionRange_from_native_mixed(self): openssl_range = "3.0.0, 1.0.1b" expected = OpensslVersionRange( constraints=( - VersionConstraint(comparator="=", version=OpensslVersion(string="1.0.1b")), - VersionConstraint(comparator="=", version=OpensslVersion(string="3.0.0")), + VersionConstraint( + comparator="=", version=OpensslVersion(string="1.0.1b")), + VersionConstraint( + comparator="=", version=OpensslVersion(string="3.0.0")), ) ) version_range = OpensslVersionRange.from_native(openssl_range) @@ -299,11 +345,16 @@ def test_OpensslVersionRange_from_versions(self): sequence = ["3.0.0", "1.0.1b", "3.0.2", "0.9.7a ", "1.1.1ka"] expected = OpensslVersionRange( constraints=( - VersionConstraint(comparator="=", version=OpensslVersion(string="0.9.7a")), - VersionConstraint(comparator="=", version=OpensslVersion(string="1.0.1b")), - VersionConstraint(comparator="=", version=OpensslVersion(string="1.1.1ka")), - VersionConstraint(comparator="=", version=OpensslVersion(string="3.0.0")), - VersionConstraint(comparator="=", version=OpensslVersion(string="3.0.2")), + VersionConstraint( + comparator="=", version=OpensslVersion(string="0.9.7a")), + VersionConstraint( + comparator="=", version=OpensslVersion(string="1.0.1b")), + VersionConstraint( + comparator="=", version=OpensslVersion(string="1.1.1ka")), + VersionConstraint( + comparator="=", version=OpensslVersion(string="3.0.0")), + VersionConstraint( + comparator="=", version=OpensslVersion(string="3.0.2")), ) ) version_range = OpensslVersionRange.from_versions(sequence) @@ -313,8 +364,10 @@ def test_nuget_version_range(self): nuget_range = "[1.0.0, 2.0.0)" expected = NugetVersionRange( constraints=( - VersionConstraint(comparator=">=", version=NugetVersion(string="1.0.0")), - VersionConstraint(comparator="<", version=NugetVersion(string="2.0.0")), + VersionConstraint( + comparator=">=", version=NugetVersion(string="1.0.0")), + VersionConstraint( + comparator="<", version=NugetVersion(string="2.0.0")), ) ) version_range = NugetVersionRange.from_native(nuget_range) @@ -466,18 +519,23 @@ def test_conan_advisory_version_range_parse(test_case): def test_invert(): vers_with_equal_operator = VersionRange.from_string("vers:gem/1.0") assert str(vers_with_equal_operator.invert()) == "vers:gem/!=1.0" - assert VersionRange.from_string("vers:gem/!=1.0").invert() == vers_with_equal_operator + assert VersionRange.from_string( + "vers:gem/!=1.0").invert() == vers_with_equal_operator vers_with_less_than_operator = VersionRange.from_string("vers:gem/<1.0") assert str(vers_with_less_than_operator.invert()) == "vers:gem/>=1.0" - assert VersionRange.from_string("vers:gem/>=1.0").invert() == vers_with_less_than_operator + assert VersionRange.from_string( + "vers:gem/>=1.0").invert() == vers_with_less_than_operator vers_with_greater_than_operator = VersionRange.from_string("vers:gem/>1.0") assert str(vers_with_greater_than_operator.invert()) == "vers:gem/<=1.0" - assert VersionRange.from_string("vers:gem/<=1.0").invert() == vers_with_greater_than_operator + assert VersionRange.from_string( + "vers:gem/<=1.0").invert() == vers_with_greater_than_operator - vers_with_complex_constraints = VersionRange.from_string("vers:gem/<=1.0|>=3.0|<4.0|!=5.0") - assert str(vers_with_complex_constraints.invert()) == "vers:gem/>1.0|<3.0|>=4.0|5.0" + vers_with_complex_constraints = VersionRange.from_string( + "vers:gem/<=1.0|>=3.0|<4.0|!=5.0") + assert str(vers_with_complex_constraints.invert() + ) == "vers:gem/>1.0|<3.0|>=4.0|5.0" vers_with_star_operator = VersionRange.from_string("vers:gem/*") assert vers_with_star_operator.invert() == None @@ -522,7 +580,8 @@ def test_build_range_from_snyk_advisory_string_spaced(): 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"] + known_versions = ["4.0.0", "3.0.0", "1.0.0", + "2.0.0", "1.3.0", "1.1.0", "1.2.0"] vr = VersionRange.from_string("vers:pypi/<=1.1.0|>=1.2.0|<=1.3.0|3.0.0") nvr = vr.normalize(known_versions=known_versions) @@ -531,7 +590,8 @@ def test_version_range_normalize_case1(): def test_version_range_normalize_case2(): - known_versions = ["4.0.0", "3.0.0", "1.0.0", "2.0.0", "1.3.0", "1.1.0", "1.2.0"] + known_versions = ["4.0.0", "3.0.0", "1.0.0", + "2.0.0", "1.3.0", "1.1.0", "1.2.0"] vr = VersionRange.from_string("vers:pypi/<=1.3.0|3.0.0") nvr = vr.normalize(known_versions=known_versions) @@ -540,7 +600,8 @@ def test_version_range_normalize_case2(): def test_version_range_normalize_case3(): - known_versions = ["4.0.0", "3.0.0", "1.0.0", "2.0.0", "1.3.0", "1.1.0", "1.2.0"] + known_versions = ["4.0.0", "3.0.0", "1.0.0", + "2.0.0", "1.3.0", "1.1.0", "1.2.0"] vr = VersionRange.from_string("vers:pypi/<2.0.0|3.0.0") nvr = vr.normalize(known_versions=known_versions) diff --git a/tests/test_versions.py b/tests/test_versions.py index ab5e414e..71631307 100644 --- a/tests/test_versions.py +++ b/tests/test_versions.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. from univers.version_constraint import VersionConstraint from univers.versions import AlpineLinuxVersion @@ -28,7 +28,8 @@ def test_version(): assert Version.is_valid("1.2.3") assert not Version.is_valid(None) assert Version.normalize("v1.2.3") == "1.2.3" - assert Version("1.2.3").satisfies(VersionConstraint(comparator=">=", version=Version("1.2.3"))) + assert Version("1.2.3").satisfies(VersionConstraint( + comparator=">=", version=Version("1.2.3"))) def test_pypi_version(): @@ -78,7 +79,8 @@ def test_semver_version(): assert version.next_patch() == SemverVersion("1.2.3") assert SemverVersion("1.2.3").next_patch() == SemverVersion("1.2.4") assert version.satisfies( - VersionConstraint(comparator=">=", version=SemverVersion("1.2.3-pre.1+build.1")) + VersionConstraint( + comparator=">=", version=SemverVersion("1.2.3-pre.1+build.1")) ) assert SemverVersion("1.0.0") == SemverVersion("1.0") assert SemverVersion("1.2.3+42") != SemverVersion("1.2.3+23") diff --git a/tests/util_tests.py b/tests/util_tests.py index 023678c0..c949e88d 100644 --- a/tests/util_tests.py +++ b/tests/util_tests.py @@ -2,7 +2,7 @@ # Copyright (c) nexB Inc. and others. # SPDX-License-Identifier: Apache-2.0 # -# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download. +# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. import json import os From 3b3787ad118adbd203070d3179e0a7ae94f17c64 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Tue, 20 Aug 2024 15:49:14 +0800 Subject: [PATCH 2/2] #140 - Apply black format Signed-off-by: Chin Yeung Li --- tests/test_conan_version_range.py | 24 +-- tests/test_debian_version.py | 15 +- ...est_debian_version_python_deb_pkg_tools.py | 3 +- tests/test_gentoo_pkgcore.py | 9 +- tests/test_maven_version.py | 15 +- tests/test_maven_version_range.py | 51 ++--- tests/test_openssl_versort.py | 3 +- tests/test_rpm_vercmp.py | 6 +- tests/test_version_range.py | 183 ++++++------------ tests/test_versions.py | 6 +- 10 files changed, 106 insertions(+), 209 deletions(-) diff --git a/tests/test_conan_version_range.py b/tests/test_conan_version_range.py index 73b22788..d2f75d41 100644 --- a/tests/test_conan_version_range.py +++ b/tests/test_conan_version_range.py @@ -15,18 +15,13 @@ ["<2.0", [[["<", "2.0"]]], ["1.0.1"], ["2.1"]], [">1 <2.0", [[[">", "1"], ["<", "2.0"]]], ["1.5.1"], ["0.1", "2.1"]], # tilde - ["~2.5", [[[">=", "2.5"], ["<", "2.6-"]]], - ["2.5.0", "2.5.3"], ["2.7", "2.6.1"]], - ["~2.5.1", [[[">=", "2.5.1"], ["<", "2.6.0-"]]], - ["2.5.1", "2.5.3"], ["2.5", "2.6.1"]], + ["~2.5", [[[">=", "2.5"], ["<", "2.6-"]]], ["2.5.0", "2.5.3"], ["2.7", "2.6.1"]], + ["~2.5.1", [[[">=", "2.5.1"], ["<", "2.6.0-"]]], ["2.5.1", "2.5.3"], ["2.5", "2.6.1"]], ["~1", [[[">=", "1"], ["<", "2-"]]], ["1.3", "1.8.1"], ["0.8", "2.2"]], # caret - ["^1.2", [[[">=", "1.2"], ["<", "2.0-"]]], - ["1.2.1", "1.51"], ["1", "2", "2.0.1"]], - ["^1.2.3", [[[">=", "1.2.3"], ["<", "2.0.0-"]]], - ["1.2.3", "1.2.4"], ["2", "2.1", "2.0.1"]], - ["^0.1.2", [[[">=", "0.1.2"], ["<", "0.2.0-"]]], - ["0.1.3", "0.1.44"], ["1", "0.3", "0.2.1"]], + ["^1.2", [[[">=", "1.2"], ["<", "2.0-"]]], ["1.2.1", "1.51"], ["1", "2", "2.0.1"]], + ["^1.2.3", [[[">=", "1.2.3"], ["<", "2.0.0-"]]], ["1.2.3", "1.2.4"], ["2", "2.1", "2.0.1"]], + ["^0.1.2", [[[">=", "0.1.2"], ["<", "0.2.0-"]]], ["0.1.3", "0.1.44"], ["1", "0.3", "0.2.1"]], # Identity ["1.0.0", [[["=", "1.0.0"]]], ["1.0.0"], ["2", "1.0.1"]], ["=1.0.0", [[["=", "1.0.0"]]], ["1.0.0"], ["2", "1.0.1"]], @@ -34,8 +29,7 @@ ["*", [[[">=", "0.0.0"]]], ["1.0", "a.b"], []], ["", [[[">=", "0.0.0"]]], ["1.0", "a.b"], []], # Unions - ["1.0.0 || 2.1.3", [[["=", "1.0.0"]], [["=", "2.1.3"]]], - ["1.0.0", "2.1.3"], ["2", "1.0.1"]], + ["1.0.0 || 2.1.3", [[["=", "1.0.0"]], [["=", "2.1.3"]]], ["1.0.0", "2.1.3"], ["2", "1.0.1"]], [ ">1 <2.0 || ^3.2 ", [[[">", "1"], ["<", "2.0"]], [[">=", "3.2"], ["<", "4.0-"]]], @@ -53,10 +47,8 @@ ["1.5-a1", "3.3"], ["3.3-a1"], ], - ["^1.1.2-", [[[">=", "1.1.2"], ["<", "2.0.0-"]]], - ["1.2.3", "1.2.0-alpha1"], ["2.0.0-alpha1"]], - ["~1.1.2-", [[[">=", "1.1.2"], ["<", "1.2.0-"]]], - ["1.1.3", "1.1.3-alpha1"], ["1.2.0-alpha1"]], + ["^1.1.2-", [[[">=", "1.1.2"], ["<", "2.0.0-"]]], ["1.2.3", "1.2.0-alpha1"], ["2.0.0-alpha1"]], + ["~1.1.2-", [[[">=", "1.1.2"], ["<", "1.2.0-"]]], ["1.1.3", "1.1.3-alpha1"], ["1.2.0-alpha1"]], ] diff --git a/tests/test_debian_version.py b/tests/test_debian_version.py index e04c1905..87ad95f7 100644 --- a/tests/test_debian_version.py +++ b/tests/test_debian_version.py @@ -91,8 +91,7 @@ def test_compare_strings(self): def test_compare_strings_can_sort(self): # taken from # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version - result = sorted(["a", "", "~", "~~a", "~~"], - key=version.compare_strings_key) + result = sorted(["a", "", "~", "~~a", "~~"], key=version.compare_strings_key) expected = ["~~", "~~a", "~", "", "a"] assert expected == result @@ -152,10 +151,8 @@ def test_compare_versions(self): assert compare_versions("9.0.0", "10.0.0") == -1 assert compare_versions("1.2.3-1~deb7u1", "1.2.3-1") == -1 - assert compare_versions( - "2.7.4+reloaded2-13ubuntu1", "2.7.4+reloaded2-13+deb9u1") == -1 - assert compare_versions("2.7.4+reloaded2-13", - "2.7.4+reloaded2-13+deb9u1") == -1 + assert compare_versions("2.7.4+reloaded2-13ubuntu1", "2.7.4+reloaded2-13+deb9u1") == -1 + assert compare_versions("2.7.4+reloaded2-13", "2.7.4+reloaded2-13+deb9u1") == -1 # greater than assert compare_versions("0.0.1-0", "0:0.0.0") == 1 @@ -166,10 +163,8 @@ def test_compare_versions(self): assert compare_versions("9.0.0", "1.0.0") == 1 assert compare_versions("1.2.3-1", "1.2.3-1~deb7u1") == 1 - assert compare_versions( - "2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13ubuntu1") == 1 - assert compare_versions( - "2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13") == 1 + assert compare_versions("2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13ubuntu1") == 1 + assert compare_versions("2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13") == 1 # unicode assert compare_versions("2:0.0.44-1", "2:0.0.44-nobin") == -1 diff --git a/tests/test_debian_version_python_deb_pkg_tools.py b/tests/test_debian_version_python_deb_pkg_tools.py index 6c225dfc..05fb0cc5 100644 --- a/tests/test_debian_version_python_deb_pkg_tools.py +++ b/tests/test_debian_version_python_deb_pkg_tools.py @@ -16,8 +16,7 @@ def test_version_sorting(self): # Check version sorting implemented on top of `=' and `<<' comparisons. expected_order = ["0.1", "0.5", "1.0", "2.0", "3.0", "1:0.4", "2:0.3"] assert list(sorted(expected_order)) != expected_order - result = [str(v) - for v in sorted(map(Version.from_string, expected_order))] + result = [str(v) for v in sorted(map(Version.from_string, expected_order))] assert result == expected_order def test_version_comparison(self): diff --git a/tests/test_gentoo_pkgcore.py b/tests/test_gentoo_pkgcore.py index 0d3a1519..cbd7eaa8 100644 --- a/tests/test_gentoo_pkgcore.py +++ b/tests/test_gentoo_pkgcore.py @@ -16,12 +16,10 @@ def generate_misc_sufs(): suf_nums = list(range(100)) shuffle(suf_nums) - good_sufs = simple_good_sufs + \ - [f"{x}{suf_nums.pop()}" for x in simple_good_sufs] + good_sufs = simple_good_sufs + [f"{x}{suf_nums.pop()}" for x in simple_good_sufs] l = len(good_sufs) - good_sufs = good_sufs + [good_sufs[x] + - good_sufs[l - x - 1] for x in range(l)] + good_sufs = good_sufs + [good_sufs[x] + good_sufs[l - x - 1] for x in range(l)] bad_sufs = ["_a", "_9", "_"] + [x + " " for x in simple_good_sufs] return good_sufs, bad_sufs @@ -65,8 +63,7 @@ def test_parse_version_and_revisions(self): v_r = parse_version_and_revision(version) expected_rev = rev.lstrip("-r") expected_rev = expected_rev and int(expected_rev) or 0 - assert v_r == ( - ver, expected_rev), f"Failed to parse: {version}" + assert v_r == (ver, expected_rev), f"Failed to parse: {version}" except Exception as e: raise Exception(f"Failed to parse: {version!r}") from e diff --git a/tests/test_maven_version.py b/tests/test_maven_version.py index f57561d7..c485867e 100644 --- a/tests/test_maven_version.py +++ b/tests/test_maven_version.py @@ -240,8 +240,7 @@ def test_from_string(self): for test, expected in test_pairs: v = Version(test) - assert v._parsed == expected, "Version(%s) == %s, want %s" % ( - test, v._parsed, expected) + assert v._parsed == expected, "Version(%s) == %s, want %s" % (test, v._parsed, expected) def test_version_qualifiers(self): version_qualifiers = ( @@ -269,7 +268,7 @@ def test_version_qualifiers(self): "1-123", ) for idx, low in enumerate(version_qualifiers[:-1]): - for high in version_qualifiers[idx + 1:]: + for high in version_qualifiers[idx + 1 :]: self._assert_version_order(low, high) def test_version_numbers(self): @@ -301,7 +300,7 @@ def test_version_numbers(self): "11m", ) for idx, low in enumerate(version_numbers[:-1]): - for high in version_numbers[idx + 1:]: + for high in version_numbers[idx + 1 :]: self._assert_version_order(low, high) unicode_version_numbers = ( @@ -333,7 +332,7 @@ def test_version_numbers(self): "11m", ) for idx, low in enumerate(unicode_version_numbers[:-1]): - for high in unicode_version_numbers[idx + 1:]: + for high in unicode_version_numbers[idx + 1 :]: self._assert_version_order(low, high) def test_version_equality(self): @@ -623,8 +622,7 @@ def test_compare(self): def test_str(self): for inp in ("[1.0,2.0]", "1.0"): actual = str(VersionRange(inp)) - assert inp == actual, "VersionRange(%s) == %s, wanted %s" % ( - inp, actual, inp) + assert inp == actual, "VersionRange(%s) == %s, wanted %s" % (inp, actual, inp) def test_fromversion(self): v = Version("1.0") @@ -633,8 +631,7 @@ def test_fromversion(self): assert vr.version == v def test_match_versions(self): - versions = [Version("0.1"), Version("1.0"), Version( - "1.1"), Version("2.0"), Version("2.1")] + versions = [Version("0.1"), Version("1.0"), Version("1.1"), Version("2.0"), Version("2.1")] vr = VersionRange("(1.0,2.0]") assert vr.match_version(versions) == "2.0" assert vr.match_version(versions[:3]) == "1.1" diff --git a/tests/test_maven_version_range.py b/tests/test_maven_version_range.py index b49c67c9..0905d75a 100644 --- a/tests/test_maven_version_range.py +++ b/tests/test_maven_version_range.py @@ -13,10 +13,8 @@ def test_maven_version_range_from_native_with_lower_inclusive(): version_range = MavenVersionRange.from_native("[1.0.0,2.0.0)") assert version_range == MavenVersionRange( constraints=( - VersionConstraint( - comparator=">=", version=MavenVersion(string="1.0.0")), - VersionConstraint( - comparator="<", version=MavenVersion(string="2.0.0")), + VersionConstraint(comparator=">=", version=MavenVersion(string="1.0.0")), + VersionConstraint(comparator="<", version=MavenVersion(string="2.0.0")), ) ) @@ -25,10 +23,8 @@ def test_maven_version_range_from_native_with_nothing_inclusive(): version_range = MavenVersionRange.from_native(" ( 1.0.0 , 2.1.4 ) ") assert version_range == MavenVersionRange( constraints=( - VersionConstraint( - comparator=">", version=MavenVersion(string="1.0.0")), - VersionConstraint( - comparator="<", version=MavenVersion(string="2.1.4")), + VersionConstraint(comparator=">", version=MavenVersion(string="1.0.0")), + VersionConstraint(comparator="<", version=MavenVersion(string="2.1.4")), ) ) @@ -36,8 +32,7 @@ def test_maven_version_range_from_native_with_nothing_inclusive(): def test_maven_version_range_from_native_for_pinned_version(): version_range = MavenVersionRange.from_native("[1.0.0]") assert version_range == MavenVersionRange( - constraints=(VersionConstraint(comparator="=", - version=MavenVersion(string="1.0.0")),) + constraints=(VersionConstraint(comparator="=", version=MavenVersion(string="1.0.0")),) ) @@ -55,38 +50,26 @@ def test_maven_version_range_from_native_str_representation(): def test_maven_version_range_from_native_for_multiple_version_ranges(): - version_range = MavenVersionRange.from_native( - "[2.0,2.3.1] , [2.4.0,2.12.2) , [2.13.0,2.15.0)") + version_range = MavenVersionRange.from_native("[2.0,2.3.1] , [2.4.0,2.12.2) , [2.13.0,2.15.0)") assert version_range == MavenVersionRange( constraints=( - VersionConstraint( - comparator=">=", version=MavenVersion(string="2.0")), - VersionConstraint( - comparator="<=", version=MavenVersion(string="2.3.1")), - VersionConstraint( - comparator=">=", version=MavenVersion(string="2.4.0")), - VersionConstraint( - comparator="<", version=MavenVersion(string="2.12.2")), - VersionConstraint( - comparator=">=", version=MavenVersion(string="2.13.0")), - VersionConstraint( - comparator="<", version=MavenVersion(string="2.15.0")), + VersionConstraint(comparator=">=", version=MavenVersion(string="2.0")), + VersionConstraint(comparator="<=", version=MavenVersion(string="2.3.1")), + VersionConstraint(comparator=">=", version=MavenVersion(string="2.4.0")), + VersionConstraint(comparator="<", version=MavenVersion(string="2.12.2")), + VersionConstraint(comparator=">=", version=MavenVersion(string="2.13.0")), + VersionConstraint(comparator="<", version=MavenVersion(string="2.15.0")), ) ) def test_maven_version_range_from_native_for_multiple_pinned_versions_and_a_range(): - version_range = MavenVersionRange.from_native( - "[2.0] , [2.4.0] , [2.13.0,2.15.0)") + version_range = MavenVersionRange.from_native("[2.0] , [2.4.0] , [2.13.0,2.15.0)") assert version_range == MavenVersionRange( constraints=( - VersionConstraint( - comparator="=", version=MavenVersion(string="2.0")), - VersionConstraint( - comparator="=", version=MavenVersion(string="2.4.0")), - VersionConstraint( - comparator=">=", version=MavenVersion(string="2.13.0")), - VersionConstraint( - comparator="<", version=MavenVersion(string="2.15.0")), + VersionConstraint(comparator="=", version=MavenVersion(string="2.0")), + VersionConstraint(comparator="=", version=MavenVersion(string="2.4.0")), + VersionConstraint(comparator=">=", version=MavenVersion(string="2.13.0")), + VersionConstraint(comparator="<", version=MavenVersion(string="2.15.0")), ) ) diff --git a/tests/test_openssl_versort.py b/tests/test_openssl_versort.py index 300db84f..443c6f37 100644 --- a/tests/test_openssl_versort.py +++ b/tests/test_openssl_versort.py @@ -22,8 +22,7 @@ def test_openssl_version_sort(self): results = [OpensslVersion(x.strip()) for x in all_openssl_versions] results.sort() results = [version_to_dict(x) for x in results] - expected_file = self.get_test_loc( - "openssl_versort_expected.json", must_exist=False) + expected_file = self.get_test_loc("openssl_versort_expected.json", must_exist=False) util_tests.check_results_against_json(results, expected_file) diff --git a/tests/test_rpm_vercmp.py b/tests/test_rpm_vercmp.py index ad7f4554..3f2b1f36 100644 --- a/tests/test_rpm_vercmp.py +++ b/tests/test_rpm_vercmp.py @@ -76,8 +76,7 @@ def create_test_function(ver1, ver2, expected, name): def test_rpm_version(self): ver1_str = str(ver1).encode("utf-8") ver2_str = str(ver2).encode("utf-8") - print( - f"testing (ver1={ver1_str}, ver2={ver2_str}, expected=expected{expected}") + print(f"testing (ver1={ver1_str}, ver2={ver2_str}, expected=expected{expected}") result = vercmp.vercmp(ver1, ver2) if result != expected: assert result == (expected, ver1, ver2) @@ -93,8 +92,7 @@ def get_tests(): test_file = os.path.join(os.path.dirname(__file__), "data", "rpmvercmp.at") with io.open(test_file, encoding="utf-8") as rpmtests: - tests = list(parse_rpmvercmp_tests( - rpmtests, with_buggy_comparisons=True)) + tests = list(parse_rpmvercmp_tests(rpmtests, with_buggy_comparisons=True)) for test_count, (ver1, ver2, expected) in enumerate(tests, 1): name = f"test_rpm_version_{test_count}" yield create_test_function(ver1, ver2, expected, name) diff --git a/tests/test_version_range.py b/tests/test_version_range.py index e9479b61..2d3c4112 100644 --- a/tests/test_version_range.py +++ b/tests/test_version_range.py @@ -34,16 +34,14 @@ class TestVersionRange(TestCase): def test_VersionRange_afrom_string(self): version_range = VersionRange.from_string("vers:pypi/>0.0.2") assert version_range == PypiVersionRange( - constraints=[VersionConstraint( - comparator=">", version=PypiVersion(string="0.0.2"))] + constraints=[VersionConstraint(comparator=">", version=PypiVersion(string="0.0.2"))] ) def test_VersionRange_to_string(self): vers = "vers:pypi/0.0.2|0.0.6|>=0.0.0|0.0.1|0.0.4|0.0.5|0.0.3" version_range = VersionRange.from_string(vers) # note the sorting taking place - assert str( - version_range) == "vers:pypi/>=0.0.0|0.0.1|0.0.2|0.0.3|0.0.4|0.0.5|0.0.6" + assert str(version_range) == "vers:pypi/>=0.0.0|0.0.1|0.0.2|0.0.3|0.0.4|0.0.5|0.0.6" def test_VersionRange_pypi_does_not_contain_basic(self): vers = "vers:pypi/0.0.2|0.0.6|>=3.0.0|0.0.1|0.0.4|0.0.5|0.0.3" @@ -99,36 +97,25 @@ def test_VersionRange_from_string_pypi(self): assert version_range.scheme == "pypi" # note the sorting taking place expected = ( - VersionConstraint( - comparator="=", version=PypiVersion(string="0.0.0")), - VersionConstraint( - comparator="=", version=PypiVersion(string="0.0.1")), - VersionConstraint( - comparator="=", version=PypiVersion(string="0.0.2")), - VersionConstraint( - comparator="=", version=PypiVersion(string="0.0.3")), - VersionConstraint( - comparator="=", version=PypiVersion(string="0.0.4")), - VersionConstraint( - comparator="=", version=PypiVersion(string="0.0.5")), - VersionConstraint( - comparator="=", version=PypiVersion(string="0.0.6")), + VersionConstraint(comparator="=", version=PypiVersion(string="0.0.0")), + VersionConstraint(comparator="=", version=PypiVersion(string="0.0.1")), + VersionConstraint(comparator="=", version=PypiVersion(string="0.0.2")), + VersionConstraint(comparator="=", version=PypiVersion(string="0.0.3")), + VersionConstraint(comparator="=", version=PypiVersion(string="0.0.4")), + VersionConstraint(comparator="=", version=PypiVersion(string="0.0.5")), + VersionConstraint(comparator="=", version=PypiVersion(string="0.0.6")), ) assert version_range.constraints == expected # note the sorting taking place - assert str( - version_range) == "vers:pypi/0.0.0|0.0.1|0.0.2|0.0.3|0.0.4|0.0.5|0.0.6" + assert str(version_range) == "vers:pypi/0.0.0|0.0.1|0.0.2|0.0.3|0.0.4|0.0.5|0.0.6" - version_range1 = VersionRange.from_string( - vers, simplify=False, validate=True) + version_range1 = VersionRange.from_string(vers, simplify=False, validate=True) assert version_range1.constraints == expected - version_range2 = VersionRange.from_string( - vers, simplify=True, validate=False) + version_range2 = VersionRange.from_string(vers, simplify=True, validate=False) assert version_range2.constraints == expected - version_range3 = VersionRange.from_string( - vers, simplify=True, validate=True) + version_range3 = VersionRange.from_string(vers, simplify=True, validate=True) assert version_range3.constraints == expected def test_VersionRange_from_string_pypi_complex_simplify(self): @@ -140,90 +127,74 @@ def test_VersionRange_from_string_pypi_complex_simplify(self): raise Exception(f"Exception not raised: {vers}") except ValueError: pass - version_range = VersionRange.from_string( - vers, validate=True, simplify=True) + version_range = VersionRange.from_string(vers, validate=True, simplify=True) assert str(version_range) == "vers:pypi/>0.0.0|<0.0.5|>=0.0.6" def test_VersionRange_from_string_pypi_complex_simplify_and_validate(self): vers = "vers:pypi/>0.0.0|>=0.0.1|0.0.2|0.0.3|0.0.4|<0.0.5|>=0.0.6|!=0.8" version_range = VersionRange.from_string(vers, simplify=True) assert str(version_range) == "vers:pypi/>0.0.0|<0.0.5|>=0.0.6|!=0.8" - version_range = VersionRange.from_string( - vers, simplify=True, validate=True) + version_range = VersionRange.from_string(vers, simplify=True, validate=True) def test_VersionRange_from_string_pypi_complex_simplify2(self): vers = ( "vers:pypi/>0.0.0|>=0.0.1|>=0.0.1|0.0.2|0.0.3|0.0.4|<0.0.5|<=0.0.6|!=0.7|8.0|>12|<15.3" ) version_range = VersionRange.from_string(vers, simplify=True) - assert str( - version_range) == "vers:pypi/>0.0.0|<=0.0.6|!=0.7|8.0|>12|<15.3" + assert str(version_range) == "vers:pypi/>0.0.0|<=0.0.6|!=0.7|8.0|>12|<15.3" def test_VersionRange_from_string_pypi_simple_cases(self): vers = "vers:pypi/>0.0.1" - version_range = VersionRange.from_string( - vers, simplify=True, validate=True) + version_range = VersionRange.from_string(vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/>=0.0.1" - version_range = VersionRange.from_string( - vers, simplify=True, validate=True) + version_range = VersionRange.from_string(vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/<0.0.1" - version_range = VersionRange.from_string( - vers, simplify=True, validate=True) + version_range = VersionRange.from_string(vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/<=0.0.1" - version_range = VersionRange.from_string( - vers, simplify=True, validate=True) + version_range = VersionRange.from_string(vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/0.0.1" - version_range = VersionRange.from_string( - vers, simplify=True, validate=True) + version_range = VersionRange.from_string(vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/!=0.0.1" - version_range = VersionRange.from_string( - vers, simplify=True, validate=True) + version_range = VersionRange.from_string(vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/*" - version_range = VersionRange.from_string( - vers, simplify=True, validate=True) + version_range = VersionRange.from_string(vers, simplify=True, validate=True) assert str(version_range) == vers def test_VersionRange_from_string_pypi_two_cases(self): vers = "vers:pypi/>0.0.1|<0.1" - version_range = VersionRange.from_string( - vers, simplify=True, validate=True) + version_range = VersionRange.from_string(vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/>=0.0.1|<0.1" - version_range = VersionRange.from_string( - vers, simplify=True, validate=True) + version_range = VersionRange.from_string(vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/<0.0.1|>0.1" - version_range = VersionRange.from_string( - vers, simplify=True, validate=True) + version_range = VersionRange.from_string(vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/<=0.0.1|>0.1" - version_range = VersionRange.from_string( - vers, simplify=True, validate=True) + version_range = VersionRange.from_string(vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/0.0.1|>0.1" - version_range = VersionRange.from_string( - vers, simplify=True, validate=True) + version_range = VersionRange.from_string(vers, simplify=True, validate=True) assert str(version_range) == vers vers = "vers:pypi/!=0.0.1|>0.1" - version_range = VersionRange.from_string( - vers, simplify=True, validate=True) + version_range = VersionRange.from_string(vers, simplify=True, validate=True) assert str(version_range) == vers def test_GemVersionRange_from_native_range_with_pessimistic_operator(self): @@ -231,26 +202,21 @@ def test_GemVersionRange_from_native_range_with_pessimistic_operator(self): version_range = GemVersionRange.from_native(gem_range) assert version_range.to_string() == "vers:gem/>=2.0.8|<2.1" assert version_range.constraints == ( - VersionConstraint( - comparator=">=", version=RubygemsVersion(string="2.0.8")), - VersionConstraint( - comparator="<", version=RubygemsVersion(string="2.1")), + VersionConstraint(comparator=">=", version=RubygemsVersion(string="2.0.8")), + VersionConstraint(comparator="<", version=RubygemsVersion(string="2.1")), ) def test_VersionRange_contains_works_for_star_range(self): from univers.versions import NginxVersion - assert NginxVersion( - "1.0.0") in VersionRange.from_string("vers:nginx/*") + assert NginxVersion("1.0.0") in VersionRange.from_string("vers:nginx/*") def test_NpmVersionRange_from_native_with_compatible_with_version_operator(self): npm_range = "^1.2.9" expected = NpmVersionRange( constraints=( - VersionConstraint( - comparator=">=", version=SemverVersion(string="1.2.9")), - VersionConstraint( - comparator="<", version=SemverVersion(string="2.0.0")), + VersionConstraint(comparator=">=", version=SemverVersion(string="1.2.9")), + VersionConstraint(comparator="<", version=SemverVersion(string="2.0.0")), ) ) version_range = NpmVersionRange.from_native(npm_range) @@ -260,10 +226,8 @@ def test_NpmVersionRange_from_native_with_prerelease_carate_range(self): npm_range = "^1.2.3-beta.1" expected = NpmVersionRange( constraints=( - VersionConstraint( - comparator=">=", version=SemverVersion(string="1.2.3-beta.1")), - VersionConstraint( - comparator="<", version=SemverVersion(string="2.0.0")), + VersionConstraint(comparator=">=", version=SemverVersion(string="1.2.3-beta.1")), + VersionConstraint(comparator="<", version=SemverVersion(string="2.0.0")), ) ) version_range = NpmVersionRange.from_native(npm_range) @@ -273,10 +237,8 @@ def test_NpmVersionRange_from_native_with_prerelease_carate_range_wihtout_major( npm_range = "^0.2.1-beta" expected = NpmVersionRange( constraints=( - VersionConstraint( - comparator=">=", version=SemverVersion(string="0.2.1-beta")), - VersionConstraint( - comparator="<", version=SemverVersion(string="0.3.0")), + VersionConstraint(comparator=">=", version=SemverVersion(string="0.2.1-beta")), + VersionConstraint(comparator="<", version=SemverVersion(string="0.3.0")), ) ) version_range = NpmVersionRange.from_native(npm_range) @@ -286,10 +248,8 @@ def test_NpmVersionRange_from_native_with_prerelease_carate_range_wihtout_major_ npm_range = "^0.0.2-beta" expected = NpmVersionRange( constraints=( - VersionConstraint( - comparator=">=", version=SemverVersion(string="0.0.2-beta")), - VersionConstraint( - comparator="<", version=SemverVersion(string="0.0.3")), + VersionConstraint(comparator=">=", version=SemverVersion(string="0.0.2-beta")), + VersionConstraint(comparator="<", version=SemverVersion(string="0.0.3")), ) ) version_range = NpmVersionRange.from_native(npm_range) @@ -299,10 +259,8 @@ def test_NpmVersionRange_from_native_with_approximately_equal_to_operator(self): npm_range = "~3.8.2" expected = NpmVersionRange( constraints=( - VersionConstraint( - comparator=">=", version=SemverVersion(string="3.8.2")), - VersionConstraint( - comparator="<", version=SemverVersion(string="3.9.0")), + VersionConstraint(comparator=">=", version=SemverVersion(string="3.8.2")), + VersionConstraint(comparator="<", version=SemverVersion(string="3.9.0")), ) ) version_range = NpmVersionRange.from_native(npm_range) @@ -312,8 +270,7 @@ def test_OpensslVersionRange_from_native_single_legacy(self): openssl_range = "0.9.8j" expected = OpensslVersionRange( constraints=( - VersionConstraint( - comparator="=", version=OpensslVersion(string="0.9.8j")), + VersionConstraint(comparator="=", version=OpensslVersion(string="0.9.8j")), ) ) version_range = OpensslVersionRange.from_native(openssl_range) @@ -322,8 +279,7 @@ def test_OpensslVersionRange_from_native_single_legacy(self): def test_OpensslVersionRange_from_native_single_new_semver(self): openssl_range = "3.0.1" expected = OpensslVersionRange( - constraints=(VersionConstraint(comparator="=", - version=OpensslVersion(string="3.0.1")),) + constraints=(VersionConstraint(comparator="=", version=OpensslVersion(string="3.0.1")),) ) version_range = OpensslVersionRange.from_native(openssl_range) assert version_range == expected @@ -332,10 +288,8 @@ def test_OpensslVersionRange_from_native_mixed(self): openssl_range = "3.0.0, 1.0.1b" expected = OpensslVersionRange( constraints=( - VersionConstraint( - comparator="=", version=OpensslVersion(string="1.0.1b")), - VersionConstraint( - comparator="=", version=OpensslVersion(string="3.0.0")), + VersionConstraint(comparator="=", version=OpensslVersion(string="1.0.1b")), + VersionConstraint(comparator="=", version=OpensslVersion(string="3.0.0")), ) ) version_range = OpensslVersionRange.from_native(openssl_range) @@ -345,16 +299,11 @@ def test_OpensslVersionRange_from_versions(self): sequence = ["3.0.0", "1.0.1b", "3.0.2", "0.9.7a ", "1.1.1ka"] expected = OpensslVersionRange( constraints=( - VersionConstraint( - comparator="=", version=OpensslVersion(string="0.9.7a")), - VersionConstraint( - comparator="=", version=OpensslVersion(string="1.0.1b")), - VersionConstraint( - comparator="=", version=OpensslVersion(string="1.1.1ka")), - VersionConstraint( - comparator="=", version=OpensslVersion(string="3.0.0")), - VersionConstraint( - comparator="=", version=OpensslVersion(string="3.0.2")), + VersionConstraint(comparator="=", version=OpensslVersion(string="0.9.7a")), + VersionConstraint(comparator="=", version=OpensslVersion(string="1.0.1b")), + VersionConstraint(comparator="=", version=OpensslVersion(string="1.1.1ka")), + VersionConstraint(comparator="=", version=OpensslVersion(string="3.0.0")), + VersionConstraint(comparator="=", version=OpensslVersion(string="3.0.2")), ) ) version_range = OpensslVersionRange.from_versions(sequence) @@ -364,10 +313,8 @@ def test_nuget_version_range(self): nuget_range = "[1.0.0, 2.0.0)" expected = NugetVersionRange( constraints=( - VersionConstraint( - comparator=">=", version=NugetVersion(string="1.0.0")), - VersionConstraint( - comparator="<", version=NugetVersion(string="2.0.0")), + VersionConstraint(comparator=">=", version=NugetVersion(string="1.0.0")), + VersionConstraint(comparator="<", version=NugetVersion(string="2.0.0")), ) ) version_range = NugetVersionRange.from_native(nuget_range) @@ -519,23 +466,18 @@ def test_conan_advisory_version_range_parse(test_case): def test_invert(): vers_with_equal_operator = VersionRange.from_string("vers:gem/1.0") assert str(vers_with_equal_operator.invert()) == "vers:gem/!=1.0" - assert VersionRange.from_string( - "vers:gem/!=1.0").invert() == vers_with_equal_operator + assert VersionRange.from_string("vers:gem/!=1.0").invert() == vers_with_equal_operator vers_with_less_than_operator = VersionRange.from_string("vers:gem/<1.0") assert str(vers_with_less_than_operator.invert()) == "vers:gem/>=1.0" - assert VersionRange.from_string( - "vers:gem/>=1.0").invert() == vers_with_less_than_operator + assert VersionRange.from_string("vers:gem/>=1.0").invert() == vers_with_less_than_operator vers_with_greater_than_operator = VersionRange.from_string("vers:gem/>1.0") assert str(vers_with_greater_than_operator.invert()) == "vers:gem/<=1.0" - assert VersionRange.from_string( - "vers:gem/<=1.0").invert() == vers_with_greater_than_operator + assert VersionRange.from_string("vers:gem/<=1.0").invert() == vers_with_greater_than_operator - vers_with_complex_constraints = VersionRange.from_string( - "vers:gem/<=1.0|>=3.0|<4.0|!=5.0") - assert str(vers_with_complex_constraints.invert() - ) == "vers:gem/>1.0|<3.0|>=4.0|5.0" + vers_with_complex_constraints = VersionRange.from_string("vers:gem/<=1.0|>=3.0|<4.0|!=5.0") + assert str(vers_with_complex_constraints.invert()) == "vers:gem/>1.0|<3.0|>=4.0|5.0" vers_with_star_operator = VersionRange.from_string("vers:gem/*") assert vers_with_star_operator.invert() == None @@ -580,8 +522,7 @@ def test_build_range_from_snyk_advisory_string_spaced(): 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"] + known_versions = ["4.0.0", "3.0.0", "1.0.0", "2.0.0", "1.3.0", "1.1.0", "1.2.0"] vr = VersionRange.from_string("vers:pypi/<=1.1.0|>=1.2.0|<=1.3.0|3.0.0") nvr = vr.normalize(known_versions=known_versions) @@ -590,8 +531,7 @@ def test_version_range_normalize_case1(): def test_version_range_normalize_case2(): - known_versions = ["4.0.0", "3.0.0", "1.0.0", - "2.0.0", "1.3.0", "1.1.0", "1.2.0"] + known_versions = ["4.0.0", "3.0.0", "1.0.0", "2.0.0", "1.3.0", "1.1.0", "1.2.0"] vr = VersionRange.from_string("vers:pypi/<=1.3.0|3.0.0") nvr = vr.normalize(known_versions=known_versions) @@ -600,8 +540,7 @@ def test_version_range_normalize_case2(): def test_version_range_normalize_case3(): - known_versions = ["4.0.0", "3.0.0", "1.0.0", - "2.0.0", "1.3.0", "1.1.0", "1.2.0"] + known_versions = ["4.0.0", "3.0.0", "1.0.0", "2.0.0", "1.3.0", "1.1.0", "1.2.0"] vr = VersionRange.from_string("vers:pypi/<2.0.0|3.0.0") nvr = vr.normalize(known_versions=known_versions) diff --git a/tests/test_versions.py b/tests/test_versions.py index 71631307..57ded4c0 100644 --- a/tests/test_versions.py +++ b/tests/test_versions.py @@ -28,8 +28,7 @@ def test_version(): assert Version.is_valid("1.2.3") assert not Version.is_valid(None) assert Version.normalize("v1.2.3") == "1.2.3" - assert Version("1.2.3").satisfies(VersionConstraint( - comparator=">=", version=Version("1.2.3"))) + assert Version("1.2.3").satisfies(VersionConstraint(comparator=">=", version=Version("1.2.3"))) def test_pypi_version(): @@ -79,8 +78,7 @@ def test_semver_version(): assert version.next_patch() == SemverVersion("1.2.3") assert SemverVersion("1.2.3").next_patch() == SemverVersion("1.2.4") assert version.satisfies( - VersionConstraint( - comparator=">=", version=SemverVersion("1.2.3-pre.1+build.1")) + VersionConstraint(comparator=">=", version=SemverVersion("1.2.3-pre.1+build.1")) ) assert SemverVersion("1.0.0") == SemverVersion("1.0") assert SemverVersion("1.2.3+42") != SemverVersion("1.2.3+23")