1
- from unittest .mock import patch
2
-
3
- from rich .console import Console
4
1
from typer .testing import CliRunner
5
2
6
3
import idom
7
4
from idom .cli import main
8
- from idom .client .manage import _private , web_module_exists
9
- from idom .config import IDOM_CLIENT_BUILD_DIR , IDOM_DEBUG_MODE
5
+ from idom .client .manage import web_module_exists
6
+ from idom .config import all_options
10
7
11
8
12
9
cli_runner = CliRunner ()
13
10
14
11
15
- with_large_console = patch ("idom.cli.console" , Console (width = 10000 ))
16
-
17
-
18
- def assert_rich_table_equals (stdout , expected_header , expected_rows ):
19
- parsed_lines = []
20
- for line in stdout .split ("\n " ):
21
- maybe_row = list (
22
- map (str .strip , filter (None , line .replace ("┃" , "│" ).split ("│" )))
23
- )
24
- if len (maybe_row ) > 1 :
25
- parsed_lines .append (maybe_row )
26
-
27
- actual_header , * actual_rows = parsed_lines
28
-
29
- assert actual_header == list (map (str , expected_header ))
30
- assert actual_rows == [list (map (str , row )) for row in expected_rows ]
12
+ def test_root ():
13
+ assert idom .__version__ in cli_runner .invoke (main , ["--version" ]).stdout
31
14
32
15
33
- @with_large_console
34
16
def test_install ():
35
17
cli_runner .invoke (main , ["restore" ])
36
18
assert cli_runner .invoke (main , ["install" , "jquery" ]).exit_code == 0
@@ -44,54 +26,12 @@ def test_install():
44
26
assert web_module_exists ("jquery" )
45
27
46
28
47
- @with_large_console
48
29
def test_restore ():
49
30
assert cli_runner .invoke (main , ["restore" ]).exit_code == 0
50
31
51
32
52
- @with_large_console
53
- def test_show_version ():
54
- terse_result = cli_runner .invoke (main , ["version" ])
55
- assert idom .__version__ in terse_result .stdout
56
-
57
- verbose_result = cli_runner .invoke (main , ["version" , "--verbose" ])
58
-
59
- assert_rich_table_equals (
60
- verbose_result .stdout ,
61
- ["Package" , "Version" , "Language" ],
62
- (
63
- [["idom" , idom .__version__ , "Python" ]]
64
- + [
65
- [js_pkg , js_ver , "Javascript" ]
66
- for js_pkg , js_ver in _private .build_dependencies ().items ()
67
- ]
68
- ),
69
- )
70
-
71
-
72
- @with_large_console
73
- def test_show_options ():
74
- assert_rich_table_equals (
75
- cli_runner .invoke (main , ["options" ]).stdout ,
76
- ["Name" , "Value" , "Default" , "Mutable" ],
77
- [
78
- [
79
- "IDOM_CLIENT_BUILD_DIR" ,
80
- IDOM_CLIENT_BUILD_DIR .current ,
81
- IDOM_CLIENT_BUILD_DIR .default ,
82
- "True" ,
83
- ],
84
- [
85
- "IDOM_DEBUG_MODE" ,
86
- IDOM_DEBUG_MODE .current ,
87
- IDOM_DEBUG_MODE .default ,
88
- "False" ,
89
- ],
90
- [
91
- "IDOM_FEATURE_INDEX_AS_DEFAULT_KEY" ,
92
- "False" ,
93
- "False" ,
94
- "False" ,
95
- ],
96
- ],
97
- )
33
+ def test_options ():
34
+ assert cli_runner .invoke (main , ["options" ]).stdout .strip ().split ("\n " ) == [
35
+ f"{ opt .name } = { opt .current } "
36
+ for opt in sorted (all_options (), key = lambda o : o .name )
37
+ ]
0 commit comments