diff --git a/scripts/build-sync-wheels b/scripts/build-sync-wheels index 8409480f..ef4507da 100755 --- a/scripts/build-sync-wheels +++ b/scripts/build-sync-wheels @@ -19,7 +19,7 @@ if os.geteuid() == 0: # sys.exit(1) if "VIRTUAL_ENV" not in os.environ: print( - "This script should be run in a virtualenv: " "`source .venv/bin/activate`", + "This script should be run in a virtualenv: `source .venv/bin/activate`", file=sys.stderr, ) sys.exit(1) diff --git a/scripts/utils.py b/scripts/utils.py index 2c43c8b5..d6d45161 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -108,7 +108,7 @@ def get_poetry_hashes( Get a dictionary for all main (non-development) dependencies and their valid hashes as defined in a set of requirements as defined in pyproject.toml/poetry.lock. This includes transitive dependencies of - main depenencies. + main dependencies. """ dependencies = {} relevant_dependencies = get_relevant_poetry_dependencies( diff --git a/tests/test_utils.py b/tests/test_utils.py index 3f07e670..eabc5c2c 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -30,41 +30,46 @@ ("cowsay", "6.0"), ("soupsieve", "2.5"), ] +EXPECTED_DEPENDENCY_NAMES = [name for name, _ in EXPECTED_DEPENDENCIES] EXPECTED_KEYS = [f"{name}=={version}" for name, version in EXPECTED_DEPENDENCIES] def test_get_requirements_names_and_versions(): - assert ( - get_requirements_names_and_versions(REQUIREMENTS_TXT_PATH) - == EXPECTED_DEPENDENCIES + assert sorted(get_requirements_names_and_versions(REQUIREMENTS_TXT_PATH)) == sorted( + EXPECTED_DEPENDENCIES ) def test_get_poetry_names_and_versions(): output = get_poetry_names_and_versions(POETRY_LOCK_PATH, PYPROJECT_TOML_PATH) - assert output == EXPECTED_DEPENDENCIES + assert sorted(output) == sorted(EXPECTED_DEPENDENCIES) def test_get_relevant_poetry_dependencies(): - expected_output = ["colorama", "cowsay", "beautifulsoup4", "soupsieve"] output = get_relevant_poetry_dependencies(PYPROJECT_TOML_PATH, POETRY_LOCK_PATH) # Ensure we correctly ignore development-only dependencies assert "pytest" not in output - assert sorted(output) == sorted(expected_output) + assert sorted(output) == sorted(EXPECTED_DEPENDENCY_NAMES) + + +def _check_hashes(output): + assert sorted(list(output)) == sorted(EXPECTED_KEYS) + for dep in output.keys(): + # We should have at least one hash per dependency + assert len(output[dep]) > 0 + # Hex-encoded SHA-256 hashes are 64 characters long + for hash in output[dep]: + assert len(hash) == 64 def test_get_poetry_hashes(): output = get_poetry_hashes(POETRY_LOCK_PATH, PYPROJECT_TOML_PATH) - assert list(output.keys()) == EXPECTED_KEYS - assert all(len(output[dep]) > 0 for dep in output.keys()) - assert all(all(len(hash) == 64 for hash in output[dep]) for dep in output.keys()) + _check_hashes(output) def test_get_requirements_hashes(): output = get_requirements_hashes(REQUIREMENTS_TXT_PATH) - assert list(output.keys()) == EXPECTED_KEYS - assert all(len(output[dep]) > 0 for dep in output.keys()) - assert all(all(len(hash) == 64 for hash in output[dep]) for dep in output.keys()) + _check_hashes(output) def test_get_requirements_from_poetry():