Spaces:
Running on Zero
Running on Zero
Download tests/test_build.py from RealFalconsAI/DecisionLab: direct link, hf CLI and curl.
- Browser
- Download file 2.99 kB
-
https://huggingface.co/spaces/RealFalconsAI/DecisionLab/resolve/main/tests/test_build.py
- Command line
-
hf download hf://spaces/RealFalconsAI/DecisionLab/tests/test_build.py
-
curl -L -o test_build.py https://huggingface.co/spaces/RealFalconsAI/DecisionLab/resolve/main/tests/test_build.py
2.99 kB
| """Pinned, reproducible build: every dependency version is fixed (sweep 1 open item, closed in 1.7.1). | |
| The Dockerfile and requirement files stay outside the image, so inside the container these tests are skipped. | |
| """ | |
| import re | |
| import unittest | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent.parent | |
| FILES = [ROOT / "requirements-container.txt", ROOT / "constraints.txt", ROOT / "Dockerfile"] | |
| def pins(path: Path) -> dict: | |
| out = {} | |
| for line in path.read_text().splitlines(): | |
| line = line.split("#", 1)[0].strip() | |
| if line: | |
| m = re.fullmatch(r"([A-Za-z0-9_.\-]+)(\[[^\]]+\])?==([^\s;]+)", line) | |
| if not m: | |
| raise AssertionError(f"{path.name}: not an exact pin: {line!r}") | |
| out[m.group(1).lower().replace("_", "-")] = m.group(3) | |
| return out | |
| class PinnedBuildTest(unittest.TestCase): | |
| def test_every_requirement_is_an_exact_pin(self): | |
| self.assertTrue(pins(ROOT / "requirements-container.txt")) | |
| def test_every_constraint_is_an_exact_pin(self): | |
| self.assertGreater(len(pins(ROOT / "constraints.txt")), 30) | |
| def test_requirements_and_constraints_agree(self): | |
| req, con = pins(ROOT / "requirements-container.txt"), pins(ROOT / "constraints.txt") | |
| for name, version in req.items(): | |
| with self.subTest(package=name): | |
| self.assertEqual(con.get(name), version) | |
| def test_torch_is_pinned_in_the_dockerfile_not_the_constraints(self): | |
| self.assertNotIn("torch", pins(ROOT / "constraints.txt")) | |
| self.assertRegex((ROOT / "Dockerfile").read_text(), r"ARG TORCH_VERSION=\d+\.\d+\.\d+\n") | |
| def test_dockerfile_installs_the_exact_set_and_checks_it(self): | |
| df = (ROOT / "Dockerfile").read_text() | |
| self.assertIn('pip install "torch==${TORCH_VERSION}"', df) | |
| self.assertIn("-c constraints.txt", df) | |
| self.assertIn("pip install --no-deps -r constraints.txt", df) | |
| self.assertIn("&& pip check\n", df) # the command, not the comment that mentions it | |
| self.assertIn("COPY requirements-container.txt constraints.txt ./", df) | |
| if __name__ == "__main__": | |
| unittest.main() | |
| class ComposeModelsTest(unittest.TestCase): | |
| """Compose must not override the operator's model list with other repos.""" | |
| def test_compose_does_not_pin_other_repos(self): | |
| compose = (ROOT / "docker-compose.yml").read_text() | |
| self.assertNotIn("laya-v796", compose) | |
| for line in compose.splitlines(): | |
| if line.strip().startswith(("LAYA_REPO:", "LIGHTDEC_ARTHUR_REPO:", "LIGHTDEC_V2_REPO:")): | |
| self.assertIn(line.split(":", 1)[1].split("#")[0].strip(), | |
| ("convaiinnovations/laya", "Falconsai/LightDec_Arthur", "Falconsai/LightDec_V2")) | |