File size: 2,621 Bytes
8e9aba4
2a98f83
976f8d8
4726b4a
976f8d8
3555cfd
 
 
 
 
 
 
 
 
 
 
 
2a98f83
 
 
 
 
9b3be67
2a98f83
 
9b3be67
 
2a98f83
3555cfd
 
9b3be67
2a98f83
3555cfd
 
2a98f83
 
 
 
9b3be67
2a98f83
 
9b3be67
 
 
 
 
2a98f83
3555cfd
 
9b3be67
2a98f83
 
 
 
 
 
 
9b3be67
2a98f83
dd9c3ed
 
2a98f83
 
9b3be67
2a98f83
 
 
9b3be67
2a98f83
3555cfd
 
 
 
 
 
 
 
 
 
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
import unittest
from textwrap import dedent

from click import testing as click_testing


def get_runtests():
    # Lazy load to avoid circular imports.

    from .._cli.main import pysr

    class TestCli(unittest.TestCase):
        # TODO: Include test for custom project here.
        def setUp(self):
            self.cli_runner = click_testing.CliRunner()

        def test_help_on_all_commands(self):
            expected = dedent(
                """
                    Usage: pysr [OPTIONS] COMMAND [ARGS]...

                    Options:
                      --help  Show this message and exit.

                    Commands:
                      install  DEPRECATED (dependencies are now installed at import).
                      test     Run parts of the PySR test suite.
                """
            )
            result = self.cli_runner.invoke(pysr, ["--help"])
            self.assertEqual(result.output.strip(), expected.strip())
            self.assertEqual(result.exit_code, 0)

        def test_help_on_install(self):
            expected = dedent(
                """
                Usage: pysr install [OPTIONS]

                  DEPRECATED (dependencies are now installed at import).

                Options:
                  -p, --project TEXT
                  -q, --quiet         Disable logging.
                  --precompile
                  --no-precompile
                  --help              Show this message and exit.
                """
            )
            result = self.cli_runner.invoke(pysr, ["install", "--help"])
            self.assertEqual(result.output.strip(), expected.strip())
            self.assertEqual(result.exit_code, 0)

        def test_help_on_test(self):
            expected = dedent(
                """
                Usage: pysr test [OPTIONS] TESTS

                  Run parts of the PySR test suite.

                  Choose from main, jax, torch, cli, and startup. You can give multiple tests,
                  separated by commas.

                Options:
                  --help  Show this message and exit.
                """
            )
            result = self.cli_runner.invoke(pysr, ["test", "--help"])
            self.assertEqual(result.output.strip(), expected.strip())
            self.assertEqual(result.exit_code, 0)

    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)

    return runtests