File size: 4,776 Bytes
3f3265f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | 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()
|