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
3 changes: 2 additions & 1 deletion tests/test_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
from helpers import TINY, copy_of, git
import check # noqa: E402
ORG = check.hub_org() # hub.toml's organization: a fork with its own is its own store

class CheckTests(unittest.TestCase):
def test_frontmatter_reads_the_five_fields(self):
Expand Down Expand Up @@ -58,7 +59,7 @@ def test_scan_finds_credential_shapes(self):
self.assertEqual(check.scan("nothing here"), [])

def test_hub_toml_names_the_org_and_the_shed(self):
self.assertEqual((check.hub_org(), check.toolshed_registry()), ("brineylab", "ghcr.io/brineylab/toolshed"))
self.assertRegex(check.hub_org(), r"^[a-z0-9][a-z0-9-]*$"); self.assertEqual(check.toolshed_registry(), "ghcr.io/brineylab/toolshed")

if __name__ == "__main__":
unittest.main()
5 changes: 3 additions & 2 deletions tests/test_check_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from unittest import mock
from helpers import FIXTURES, TINY, copy_of
import check # noqa: E402
ORG = check.hub_org() # hub.toml's organization: a fork with its own is its own store

RESULTS = FIXTURES / "results"
HUB = FIXTURES / "hub"
RECORD = check.parse_record(RESULTS / "tiny" / "1.0.0.txt") if hasattr(check, "parse_record") else {"commit": ""}
API = "https://huggingface.co/api/datasets/brineylab/tiny"
API = f"https://huggingface.co/api/datasets/{ORG}/tiny"

class HubTests(unittest.TestCase):
"""check.fetch answers from tests/fixtures/hub/, by URL; anything else is absent, as a 404 is."""
Expand Down Expand Up @@ -52,7 +53,7 @@ def test_a_file_on_the_hub_the_record_lacks_is_refused(self):

def test_a_record_whose_commit_is_not_on_the_hub_is_refused(self):
del self.answers[f"{API}/tree/{RECORD['commit']}?recursive=true"]
self.assertIn(f"the record's commit {RECORD['commit']} is not on brineylab/tiny", check.hub_problems(TINY, RESULTS))
self.assertIn(f"the record's commit {RECORD['commit']} is not on {ORG}/tiny", check.hub_problems(TINY, RESULTS))

def test_a_record_with_a_nonzero_exit_is_refused(self):
text = (RESULTS / "tiny" / "1.0.0.txt").read_text().replace("exit: 0", "exit: 1")
Expand Down
7 changes: 4 additions & 3 deletions tests/test_push_promote.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from helpers import ROOT, TINY, git
import check # noqa: E402
ORG = check.hub_org() # hub.toml's organization: a fork with its own is its own store

STUBS = ROOT / "tests" / "stubs"
# Each script runs as `python3 -I` does, with the fake huggingface_hub first on sys.path, which -I would not take from PYTHONPATH.
Expand Down Expand Up @@ -39,7 +40,7 @@ def test_push_creates_the_repo_replaces_the_candidate_and_prints_the_manifest(se
r = self.run_script("scripts/push", "tiny", self.out)
self.assertEqual(r.returncode, 0, r.stderr)
out, s = r.stdout.splitlines(), self.state()
self.assertEqual(s["calls"][:4], [["create_repo", "brineylab/tiny"], ["list_repo_refs", "brineylab/tiny"], ["delete_branch", self.branch], ["create_branch", self.branch]])
self.assertEqual(s["calls"][:4], [["create_repo", f"{ORG}/tiny"], ["list_repo_refs", f"{ORG}/tiny"], ["delete_branch", self.branch], ["create_branch", self.branch]])
self.assertEqual(out[:2], [f"file eval.txt 6 {self.sha('eval.txt')}", f"file train.txt 18 {self.sha('train.txt')}"])
self.assertEqual(out[2], f"commit: {s['branches'][self.branch]}"); self.assertRegex(out[2], r"^commit: [0-9a-f]{40}$"); self.assertEqual(len(out), 3)
self.assertEqual(s["uploaded"], ["eval.txt", "train.txt"]) # not .work/
Expand Down Expand Up @@ -100,7 +101,7 @@ def test_the_card_carries_the_license_and_the_skills_body(self):
def record(self, commit, merged=True):
"""The record, committed; merged, origin/main holds that commit, as after the pull request's merge."""
(self.repo / "results/tiny").mkdir(parents=True)
(self.repo / "results/tiny/1.0.0.txt").write_text(f"---\ndataset: tiny\nversion: 1.0.0\nhub: brineylab/tiny\nbranch: {self.branch}\n"
(self.repo / "results/tiny/1.0.0.txt").write_text(f"---\ndataset: tiny\nversion: 1.0.0\nhub: {ORG}/tiny\nbranch: {self.branch}\n"
f"commit: {commit}\ntree: {self.tree}\nexit: 0\n---\ncommit: {commit}\n")
git(self.repo, "add", "results"); git(self.repo, "commit", "-qm", "record")
if merged:
Expand Down Expand Up @@ -134,7 +135,7 @@ def test_promote_tags_the_records_commit_and_deletes_the_branch(self):
self.assertEqual(r.returncode, 0, r.stderr)
s = self.state()
self.assertEqual(s["tags"]["v1.0.0"], "c" * 40); self.assertNotIn(self.branch, s["branches"])
self.assertEqual(r.stdout.splitlines()[-1], f"promoted: brineylab/tiny v1.0.0 at {'c' * 40}")
self.assertEqual(r.stdout.splitlines()[-1], f"promoted: {ORG}/tiny v1.0.0 at {'c' * 40}")

def test_promote_never_moves_an_existing_tag(self):
self.hub.write_text(json.dumps({"branches": {self.branch: "c" * 40}, "tags": {"v1.0.0": "x" * 40}}))
Expand Down
3 changes: 2 additions & 1 deletion tests/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from helpers import ROOT, TINY, git
import check # noqa: E402
ORG = check.hub_org() # hub.toml's organization: a fork with its own is its own store

class RecordTests(unittest.TestCase):
"""The real scripts/record in a temporary repository holding the tiny fixture as datasets/tiny, committed."""
Expand All @@ -24,7 +25,7 @@ def test_record_writes_the_format_and_refuses_a_credential(self):
r = self.run_script("tiny", "a" * 40, "0", "podman", "laptop", "2026-11-05T00:00:00Z", input=out)
self.assertEqual((r.returncode, r.stdout.strip()), (0, "results/tiny/1.0.0.txt"), r.stderr)
path = self.repo / "results/tiny/1.0.0.txt"
self.assertEqual(path.read_text(), f"---\ndataset: tiny\nversion: 1.0.0\nhub: brineylab/tiny\nbranch: candidate-{self.tree}\n"
self.assertEqual(path.read_text(), f"---\ndataset: tiny\nversion: 1.0.0\nhub: {ORG}/tiny\nbranch: candidate-{self.tree}\n"
f"commit: {'a' * 40}\ntree: {self.tree}\ntools: hello@1.0.1\nrunner: podman\nhost: laptop\n"
f"started: 2026-11-05T00:00:00Z\nexit: 0\n---\n{out}")
self.assertEqual(check.parse_record(path)["files"], [("train.txt", 18, "c" * 64)])
Expand Down
Loading