Orienter / tests /test_cli_entrypoints.py
stereoid's picture
Add files using upload-large-folder tool
3f3265f verified
Raw
History Blame Contribute Delete
4.78 kB
import json
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
class CliEntrypointTests(unittest.TestCase):
def test_run_vlm_script_path_supports_help(self):
result = subprocess.run(
[sys.executable, str(ROOT / "approach" / "run_vlm.py"), "--help"],
cwd=ROOT,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=False,
)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn("--questions", result.stdout)
def test_run_vlm_returns_nonzero_when_a_record_fails(self):
with tempfile.TemporaryDirectory() as tmpdir:
root = Path(tmpdir)
questions = root / "questions.jsonl"
questions.write_text(
json.dumps(
{
"question_id": 0,
"image": "123_4.jpg",
"image_id": 123004,
"text": "mine",
}
)
+ "\n",
encoding="utf-8",
)
metadata = root / "metadata.json"
metadata.write_text(
json.dumps(
{
"456": {
"app_name": "Different app",
"app_description": "Does not cover the selected screenshot.",
}
}
),
encoding="utf-8",
)
result = subprocess.run(
[
sys.executable,
"-B",
str(ROOT / "approach" / "run_vlm.py"),
"--questions",
str(questions),
"--images-dir",
str(root / "images"),
"--output",
str(root / "answers.jsonl"),
"--app-metadata-cache",
str(metadata),
],
cwd=ROOT,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=False,
)
self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
self.assertEqual(json.loads(result.stdout)["errors"], 1)
def test_run_ape_script_path_supports_help(self):
result = subprocess.run(
[sys.executable, str(ROOT / "approach" / "run_ape.py"), "--help"],
cwd=ROOT,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=False,
)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn("--candidates", result.stdout)
def test_generate_questions_script_path_supports_help(self):
result = subprocess.run(
[sys.executable, str(ROOT / "scripts" / "generate_questions.py"), "--help"],
cwd=ROOT,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=False,
)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn("--images-dir", result.stdout)
def test_environment_check_script_path_supports_help(self):
result = subprocess.run(
[sys.executable, str(ROOT / "scripts" / "check_environment.py"), "--help"],
cwd=ROOT,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=False,
)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn("--allow-no-cuda", result.stdout)
def test_release_test_runner_is_present(self):
self.assertTrue((ROOT / "scripts" / "run_tests.py").is_file())
def test_offline_control_path_smoke(self):
result = subprocess.run(
[sys.executable, str(ROOT / "scripts" / "smoke_control_path.py")],
cwd=ROOT,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=False,
)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn('"status": "ok"', result.stdout)
def test_ape_build_script_has_valid_shell_syntax(self):
result = subprocess.run(
["bash", "-n", str(ROOT / "scripts" / "build_ape_extension.sh")],
cwd=ROOT,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=False,
)
self.assertEqual(result.returncode, 0, result.stderr)
if __name__ == "__main__":
unittest.main()