Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eloquence committed Oct 4, 2023
1 parent ac2db46 commit f8e2647
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion scripts/build-sync-wheels
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
29 changes: 17 additions & 12 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit f8e2647

Please sign in to comment.