Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ jobs:
python-version: ["3.11", "3.12"]
steps:
- uses: actions/checkout@v4
with:
# tests/test_osf_deposit.py reads the frozen prereg-v1 commit
# (0a5e794) from git; the default depth-1 checkout lacks it.
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
Expand Down
36 changes: 36 additions & 0 deletions tests/test_osf_deposit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Frozen prereg hashes must match git at 0a5e794. No network."""

import subprocess

from tpl.io.osf_deposit import (
FROZEN_COMMIT,
FROZEN_SHA256,
Expand All @@ -10,6 +12,38 @@
import pytest


def _frozen_commit_available():
"""True if FROZEN_COMMIT is in the git repository of the current directory.

osf_deposit reads the frozen files with `git show` from the current
directory, so the check runs there too. It is false in a shallow clone
(CI checkout at depth 1), in a release zip/tarball (no .git), or when git
is not installed.
"""
try:
subprocess.run(
["git", "cat-file", "-e", f"{FROZEN_COMMIT}^{{commit}}"],
check=True,
capture_output=True,
)
except (OSError, subprocess.CalledProcessError):
return False
return True


# Skip rather than fail: the hashes cannot be checked without the commit, and a
# missing commit says nothing about whether they match. Run from a full clone
# (`git fetch --unshallow` in a shallow one) to exercise these tests.
requires_frozen_commit = pytest.mark.skipif(
not _frozen_commit_available(),
reason=(
f"frozen commit {FROZEN_COMMIT[:7]} (prereg-v1) is not in this checkout "
"(shallow clone or release archive); clone the full history to run"
),
)


@requires_frozen_commit
def test_snapshot_matches_pinned_hashes():
snap = snapshot()
assert set(snap) == set(FROZEN_SHA256)
Expand All @@ -18,6 +52,7 @@ def test_snapshot_matches_pinned_hashes():
assert rec["nbytes"] == len(rec["bytes"])


@requires_frozen_commit
def test_manifest_points_at_the_freeze_not_head():
man = manifest()
assert man["commit"] == FROZEN_COMMIT
Expand All @@ -30,6 +65,7 @@ def test_upload_refuses_an_empty_token():
upload("")


@requires_frozen_commit
def test_write_bundle_matches_git(tmp_path):
from tpl.io.osf_deposit import write_bundle

Expand Down
Loading