File size: 2,461 Bytes
8e9aba4
 
 
 
 
82f5f4d
 
 
8e9aba4
 
 
 
82f5f4d
 
 
8e9aba4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82f5f4d
8e9aba4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92ac433
 
 
 
 
 
 
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
import subprocess
import unittest


def run_command(command):
    """
    Retrieve output of a command string, decode and convert from CRLF to LF formatting
    """
    return subprocess.run(command.split(" "), stdout=subprocess.PIPE).stdout.decode("utf-8").replace("\r\n", "\n")


def make_command(command):
    """
    Convert string into list with LF formatting (for unix systems), using \n delimiter
    """
    return "\n".join(command)


class TestCli(unittest.TestCase):

    def test_help_on_all_commands(self):
        command_to_test = "python -m pysr --help"
        expected_lines = ["Usage: pysr [OPTIONS] COMMAND [ARGS]...",
                          "",
                          "Options:",
                          "  --help  Show this message and exit.",
                          "",
                          "Commands:",
                          "  install  Install Julia dependencies for PySR.",
                          ""]

        expected = make_command(expected_lines)
        actual = run_command(command_to_test)
        self.assertEqual(expected, actual)

    def test_help_on_install(self):
        command_to_test = "python -m pysr install --help"
        expected_lines = ["Usage: pysr install [OPTIONS]",
                          "",
                          "  Install Julia dependencies for PySR.",
                          "",
                          "Options:",
                          "  -p, --project PROJECT_DIRECTORY",
                          "                                  Install in a specific Julia project (e.g., a",
                          "                                  local copy of SymbolicRegression.jl).",
                          "  -q, --quiet                     Disable logging.",
                          "  --precompile                    Force precompilation of Julia libraries.",
                          "  --no-precompile                 Disable precompilation.",
                          "  --help                          Show this message and exit.",
                          ""]

        expected = make_command(expected_lines)
        actual = run_command(command_to_test)
        self.assertEqual(expected, actual)


def runtests():
    """Run all tests in cliTest.py."""
    loader = unittest.TestLoader()
    suite = unittest.TestSuite()
    suite.addTests(loader.loadTestsFromTestCase(TestCli))
    runner = unittest.TextTestRunner()
    return runner.run(suite)