Spaces:
Sleeping
Sleeping
WilliamBChf
commited on
Commit
•
8e9aba4
1
Parent(s):
58c93fa
Added tests to check help messages
Browse files- pysr/test/cliTest.py +54 -0
pysr/test/cliTest.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import io
|
2 |
+
import subprocess
|
3 |
+
import sys
|
4 |
+
import unittest
|
5 |
+
|
6 |
+
|
7 |
+
def run_command(command):
|
8 |
+
return subprocess.run(command.split(" "), stdout=subprocess.PIPE).stdout.decode("utf-8").replace("\r\n", "\n")
|
9 |
+
|
10 |
+
|
11 |
+
def make_command(command):
|
12 |
+
return "\n".join(command)
|
13 |
+
|
14 |
+
|
15 |
+
class TestCli(unittest.TestCase):
|
16 |
+
|
17 |
+
def test_help_on_all_commands(self):
|
18 |
+
command_to_test = "python -m pysr --help"
|
19 |
+
expected_lines = ["Usage: pysr [OPTIONS] COMMAND [ARGS]...",
|
20 |
+
"",
|
21 |
+
"Options:",
|
22 |
+
" --help Show this message and exit.",
|
23 |
+
"",
|
24 |
+
"Commands:",
|
25 |
+
" install Install Julia dependencies for PySR.",
|
26 |
+
""]
|
27 |
+
|
28 |
+
expected = make_command(expected_lines)
|
29 |
+
actual = run_command(command_to_test)
|
30 |
+
self.assertEqual(expected, actual) # add assertion here
|
31 |
+
|
32 |
+
def test_help_on_install(self):
|
33 |
+
command_to_test = "python -m pysr install --help"
|
34 |
+
expected_lines = ["Usage: pysr install [OPTIONS]",
|
35 |
+
"",
|
36 |
+
" Install Julia dependencies for PySR.",
|
37 |
+
"",
|
38 |
+
"Options:",
|
39 |
+
" -p, --project PROJECT_DIRECTORY",
|
40 |
+
" Install in a specific Julia project (e.g., a",
|
41 |
+
" local copy of SymbolicRegression.jl).",
|
42 |
+
" -q, --quiet Disable logging.",
|
43 |
+
" --precompile Force precompilation of Julia libraries.",
|
44 |
+
" --no-precompile Disable precompilation.",
|
45 |
+
" --help Show this message and exit.",
|
46 |
+
""]
|
47 |
+
|
48 |
+
expected = make_command(expected_lines)
|
49 |
+
actual = run_command(command_to_test)
|
50 |
+
self.assertEqual(expected, actual)
|
51 |
+
|
52 |
+
|
53 |
+
if __name__ == '__main__':
|
54 |
+
unittest.main()
|