diff --git a/tests/test_check.py b/tests/test_check.py index e025d3a..08c7126 100644 --- a/tests/test_check.py +++ b/tests/test_check.py @@ -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): @@ -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() diff --git a/tests/test_check_hub.py b/tests/test_check_hub.py index a074525..c632776 100644 --- a/tests/test_check_hub.py +++ b/tests/test_check_hub.py @@ -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.""" @@ -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") diff --git a/tests/test_push_promote.py b/tests/test_push_promote.py index a5ccdbb..7ecbb7a 100644 --- a/tests/test_push_promote.py +++ b/tests/test_push_promote.py @@ -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. @@ -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/ @@ -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: @@ -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}})) diff --git a/tests/test_record.py b/tests/test_record.py index 4048b37..04a09e3 100644 --- a/tests/test_record.py +++ b/tests/test_record.py @@ -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.""" @@ -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)])