Download scripts/codex_package/test_zsh.py from SaylorTwift/codex: direct link, hf CLI and curl.
- Browser
- Download file 2.64 kB
-
https://huggingface.co/SaylorTwift/codex/resolve/main/scripts/codex_package/test_zsh.py
- Command line
-
hf download hf://SaylorTwift/codex/scripts/codex_package/test_zsh.py
-
curl -L -o test_zsh.py https://huggingface.co/SaylorTwift/codex/resolve/main/scripts/codex_package/test_zsh.py
2.64 kB
| #!/usr/bin/env python3 | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import sys | |
| import tarfile | |
| import tempfile | |
| import unittest | |
| from unittest.mock import patch | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | |
| from codex_package.targets import TARGET_SPECS | |
| from codex_package.zsh import resolve_zsh_bin | |
| class ResolveZshBinTest(unittest.TestCase): | |
| def test_uses_prebuilt_executable_override(self) -> None: | |
| with tempfile.TemporaryDirectory() as temp_dir: | |
| signed_zsh = Path(temp_dir) / "signed-zsh" | |
| signed_zsh.write_bytes(b"signed zsh binary") | |
| signed_zsh.chmod(0o755) | |
| with patch("codex_package.zsh.fetch_dotslash_executable") as fetch: | |
| zsh_bin = resolve_zsh_bin( | |
| TARGET_SPECS["aarch64-apple-darwin"], zsh_bin=signed_zsh | |
| ) | |
| self.assertEqual(zsh_bin, signed_zsh.resolve()) | |
| fetch.assert_not_called() | |
| def test_uses_manifest_override(self) -> None: | |
| with tempfile.TemporaryDirectory() as temp_dir: | |
| root = Path(temp_dir) | |
| archive = root / "codex-zsh.tar.gz" | |
| source = root / "zsh" | |
| source.write_bytes(b"standalone zsh") | |
| with tarfile.open(archive, "w:gz") as tar: | |
| tar.add(source, arcname="codex-zsh/bin/zsh") | |
| manifest = root / "codex-zsh" | |
| manifest.write_text( | |
| json.dumps( | |
| { | |
| "platforms": { | |
| "linux-x86_64": { | |
| "size": archive.stat().st_size, | |
| "hash": "sha256", | |
| "digest": hashlib.sha256( | |
| archive.read_bytes() | |
| ).hexdigest(), | |
| "format": "tar.gz", | |
| "path": "codex-zsh/bin/zsh", | |
| "providers": [{"url": archive.as_uri()}], | |
| } | |
| } | |
| } | |
| ), | |
| encoding="utf-8", | |
| ) | |
| with patch( | |
| "codex_package.dotslash.default_cache_root", | |
| return_value=root / "cache", | |
| ): | |
| zsh_bin = resolve_zsh_bin( | |
| TARGET_SPECS["x86_64-unknown-linux-musl"], manifest | |
| ) | |
| self.assertIsNotNone(zsh_bin) | |
| assert zsh_bin is not None | |
| self.assertEqual(zsh_bin.read_bytes(), b"standalone zsh") | |
| if __name__ == "__main__": | |
| unittest.main() | |