Spaces:
Runtime error
Runtime error
Download test_workspace.py from Expanded-Repetition/ammo-card: direct link, hf CLI and curl.
- Browser
- Download file 2.25 kB
-
https://huggingface.co/spaces/Expanded-Repetition/ammo-card/resolve/main/test_workspace.py
- Command line
-
hf download hf://spaces/Expanded-Repetition/ammo-card/test_workspace.py
-
curl -L -o test_workspace.py https://huggingface.co/spaces/Expanded-Repetition/ammo-card/resolve/main/test_workspace.py
2.25 kB
| from pathlib import Path | |
| import pytest | |
| from amo.workspace import WORKSPACE_ROOT, compile_workspace_python, list_workspace, read_workspace_file, write_workspace_file, resolve_workspace_path | |
| def test_workspace_write_read_and_backup(tmp_path, monkeypatch): | |
| monkeypatch.setattr("amo.workspace.WORKSPACE_ROOT", tmp_path) | |
| tmp_path.mkdir(exist_ok=True) | |
| first = write_workspace_file("demo.py", "def f():\n return 1\n") | |
| assert first.startswith("تم حفظ") | |
| assert "return 1" in read_workspace_file("demo.py") | |
| second = write_workspace_file("demo.py", "def f():\n return 2\n") | |
| assert "النسخة السابقة محفوظة" in second | |
| assert list((tmp_path / ".amo_backups").iterdir()) | |
| def test_path_traversal_is_rejected(tmp_path, monkeypatch): | |
| monkeypatch.setattr("amo.workspace.WORKSPACE_ROOT", tmp_path) | |
| tmp_path.mkdir(exist_ok=True) | |
| with pytest.raises(ValueError): | |
| resolve_workspace_path("../escape.txt") | |
| with pytest.raises(ValueError): | |
| resolve_workspace_path("/tmp/secret.txt") | |
| def test_syntax_check_reports_invalid_python(tmp_path, monkeypatch): | |
| monkeypatch.setattr("amo.workspace.WORKSPACE_ROOT", tmp_path) | |
| tmp_path.mkdir(exist_ok=True) | |
| (tmp_path / "bad.py").write_text("def broken(:\n pass\n", encoding="utf-8") | |
| result = compile_workspace_python(".") | |
| assert "SyntaxError" in result or "invalid syntax" in result | |
| def test_workspace_unittest_runs_inseparate_process(tmp_path, monkeypatch): | |
| from amo.workspace import run_workspace_unittests | |
| monkeypatch.setattr("amo.workspace.WORKSPACE_ROOT", tmp_path) | |
| (tmp_path / "test_demo.py").write_text( | |
| "import unittest\nclass Demo(unittest.TestCase):\n def test_ok(self):\n self.assertEqual(2 + 2, 4)\n", | |
| encoding="utf-8", | |
| ) | |
| result = run_workspace_unittests(".") | |
| assert "Ran 1 test" in result | |
| assert "OK" in result | |
| def test_linux_tool_is_allowlisted(monkeypatch, tmp_path): | |
| from amo.workspace import linux_safe_task | |
| monkeypatch.setattr("amo.workspace.WORKSPACE_ROOT", tmp_path) | |
| result = linux_safe_task("python_version") | |
| assert "python_version" in result | |
| denied = linux_safe_task("rm -rf /") | |
| assert "غير مسموحة" in denied | |