| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
""" |
| 4 |
This script will run the tests for a given file. |
| 5 |
""" |
| 6 |
|
| 7 |
import subprocess |
| 8 |
import sys |
| 9 |
from pathlib import Path |
| 10 |
|
| 11 |
|
| 12 |
def main(): |
| 13 |
if len(sys.argv) < 2: |
| 14 |
print("Usage: script/test_file <path> [--select-language]") |
| 15 |
sys.exit(1) |
| 16 |
|
| 17 |
target_path = Path(sys.argv[1]) |
| 18 |
select_language = len(sys.argv) > 2 and sys.argv[2] == "--select-language" |
| 19 |
|
| 20 |
if len(target_path.parts) != 3 or target_path.parts[0] not in ( |
| 21 |
"sentences", |
| 22 |
"responses", |
| 23 |
"tests", |
| 24 |
): |
| 25 |
print("Error: File must be in the sentences, responses or tests directory") |
| 26 |
sys.exit(2) |
| 27 |
|
| 28 |
language = target_path.parts[1] |
| 29 |
file_name = target_path.parts[2] |
| 30 |
|
| 31 |
test_cmd = [ |
| 32 |
"pytest", |
| 33 |
"-vv", |
| 34 |
"--language", |
| 35 |
language, |
| 36 |
] |
| 37 |
|
| 38 |
if select_language or file_name in ("_fixtures.yaml", "_common.yaml"): |
| 39 |
print(f"Running all tests for {language.upper()}") |
| 40 |
test_cmd.extend(["-n", "auto"]) |
| 41 |
|
| 42 |
else: |
| 43 |
print("Running tests for file", file_name) |
| 44 |
test_cmd.extend(["-k", target_path.stem]) |
| 45 |
|
| 46 |
print() |
| 47 |
|
| 48 |
try: |
| 49 |
subprocess.run( |
| 50 |
[ |
| 51 |
sys.executable, |
| 52 |
"-m", |
| 53 |
"script.intentfest", |
| 54 |
"validate", |
| 55 |
"--language", |
| 56 |
language, |
| 57 |
], |
| 58 |
cwd=Path(__file__).parent.parent, |
| 59 |
check=True, |
| 60 |
) |
| 61 |
except subprocess.CalledProcessError as err: |
| 62 |
sys.exit(err.returncode) |
| 63 |
|
| 64 |
try: |
| 65 |
subprocess.run( |
| 66 |
test_cmd, |
| 67 |
cwd=Path(__file__).parent.parent, |
| 68 |
check=True, |
| 69 |
) |
| 70 |
except subprocess.CalledProcessError as err: |
| 71 |
sys.exit(err.returncode) |
| 72 |
|
| 73 |
|
| 74 |
main() |