Skip to content

Commit

Permalink
Fix tests for script changes
Browse files Browse the repository at this point in the history
Notably remove test_wheel_builds_are_reproducible, which is always
skipped.
  • Loading branch information
legoktm committed Sep 27, 2022
1 parent 536b80a commit b57f343
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 44 deletions.
40 changes: 1 addition & 39 deletions tests/test_reproducible_wheels.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
import subprocess
import os


# These are the SDW repositories that we build wheels for.
Expand All @@ -12,47 +11,10 @@
]


def get_repo_root():
cmd = "git rev-parse --show-toplevel".split()
top_level = subprocess.check_output(cmd).decode("utf-8").rstrip()
return top_level


@pytest.mark.skip(reason="Comparing to version control is sufficient")
@pytest.mark.parametrize("repo_name", REPOS_WITH_WHEELS)
def test_wheel_builds_are_reproducible(repo_name):
"""
Uses 'reprotest' to confirm that the wheel build process, per repo,
is deterministic, i.e. all .whl files are created with the same checksum
across multiple builds.
Explanations of the excluded reproducibility checks:
* user_group: As tar command will fail for random user/groups
* time: breaks HTTPS, so pip calls fail
* locales: some locales fail, would be nice to fix, but low priority
* kernel: x86_64 is the supported architecture, we don't ship others
"""
repo_url = f"https://github.com/freedomofpress/{repo_name}"
cmd_env = os.environ.copy()
cmd_env["TERM"] = "xterm-256color"
cmd = [
"reprotest",
"-c",
f"./scripts/build-sync-wheels -p {repo_url} --clobber",
"--variations",
"-user_group, -time, -locales, -kernel",
".",
"localwheels/*.whl",
]
repo_root = get_repo_root()
subprocess.check_call(cmd, env=cmd_env, cwd=repo_root)


@pytest.mark.parametrize("repo_name", REPOS_WITH_WHEELS)
def test_wheel_builds_match_version_control(repo_name):
repo_url = f"https://github.com/freedomofpress/{repo_name}"
build_cmd = f"./scripts/build-sync-wheels -p {repo_url} --clobber".split()
build_cmd = f"./scripts/build-sync-wheels --pkg-dir {repo_url} --project {repo_name} --clobber".split()
subprocess.check_call(build_cmd)
# Check for modified files (won't catch new, untracked files)
subprocess.check_call("git diff --exit-code".split())
Expand Down
10 changes: 5 additions & 5 deletions tests/test_update_requirements.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import imp
import os
import pytest
from pathlib import Path


# This below stanza is necessary because the scripts are not
Expand All @@ -20,7 +21,7 @@ def test_build_fails_if_sha256_sums_absent(tmpdir, mocker):
mocker.patch('os.path.exists', return_value=False)

with pytest.raises(SystemExit) as exc_info:
update_requirements.verify_sha256sums_file()
update_requirements.verify_sha256sums_file(Path("foo"))

exit_code = exc_info.value.args[0]
assert exit_code == 1
Expand All @@ -30,7 +31,7 @@ def test_build_fails_if_sha256_signature_absent(tmpdir, mocker):
mocker.patch('os.path.exists', side_effect=[True, False])

with pytest.raises(SystemExit) as exc_info:
update_requirements.verify_sha256sums_file()
update_requirements.verify_sha256sums_file(Path("foo"))

exit_code = exc_info.value.args[0]
assert exit_code == 1
Expand All @@ -46,7 +47,7 @@ def test_shasums_skips_sources(tmpdir):
requirements_lines = ["{}=={}".format(requirement_name, requirement_version)]
path_result = os.path.join(tmpdir, "test-req.txt")

update_requirements.add_sha256sums(path_result, requirements_lines, path_test_shasums)
update_requirements.add_sha256sums(Path(path_result), requirements_lines, Path(path_test_shasums), Path("foo"))

with open(path_result, 'r') as f:
result = f.read()
Expand All @@ -56,7 +57,6 @@ def test_shasums_skips_sources(tmpdir):


def test_build_fails_if_missing_wheels(tmpdir):
os.environ["PKG_DIR"] = 'foo'
path_test_shasums = os.path.join(tmpdir, 'test-shasums.txt')
with open(path_test_shasums, 'w') as f:
f.writelines([])
Expand All @@ -67,7 +67,7 @@ def test_build_fails_if_missing_wheels(tmpdir):
path_result = os.path.join(tmpdir, "test-req.txt")

with pytest.raises(SystemExit) as exc_info:
update_requirements.add_sha256sums(path_result, requirements_lines, path_test_shasums)
update_requirements.add_sha256sums(Path(path_result), requirements_lines, Path(path_test_shasums), Path("foo"))

exit_code = exc_info.value.args[0]
assert exit_code == 1

0 comments on commit b57f343

Please sign in to comment.