Spaces:
Sleeping
Sleeping
MilesCranmer
commited on
Commit
•
b1518ce
1
Parent(s):
ceb3c10
Create CLI for running PySR tests
Browse files- pysr/test/__main__.py +41 -0
pysr/test/__main__.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""CLI for running PySR's test suite."""
|
2 |
+
import argparse
|
3 |
+
import os
|
4 |
+
|
5 |
+
from . import *
|
6 |
+
|
7 |
+
if __name__ == "__main__":
|
8 |
+
# Get args:
|
9 |
+
parser = argparse.ArgumentParser()
|
10 |
+
parser.usage = "python -m pysr.test [tests...]"
|
11 |
+
parser.add_argument(
|
12 |
+
"test",
|
13 |
+
nargs="*",
|
14 |
+
help="Test to run. One or more of 'main', 'env', 'jax', 'torch'.",
|
15 |
+
)
|
16 |
+
|
17 |
+
# Parse args:
|
18 |
+
args = parser.parse_args()
|
19 |
+
tests = args.test
|
20 |
+
|
21 |
+
if len(tests) == 0:
|
22 |
+
# Raise help message:
|
23 |
+
parser.print_help()
|
24 |
+
raise SystemExit(1)
|
25 |
+
|
26 |
+
# Run tests:
|
27 |
+
for test in tests:
|
28 |
+
if test in {"main", "env", "jax", "torch"}:
|
29 |
+
cur_dir = os.path.dirname(os.path.abspath(__file__))
|
30 |
+
print(f"Running test from {cur_dir}")
|
31 |
+
if test == "main":
|
32 |
+
runtests()
|
33 |
+
elif test == "env":
|
34 |
+
runtests_env()
|
35 |
+
elif test == "jax":
|
36 |
+
runtests_jax()
|
37 |
+
elif test == "torch":
|
38 |
+
runtests_torch()
|
39 |
+
else:
|
40 |
+
parser.print_help()
|
41 |
+
raise SystemExit(1)
|