1- from unittest .mock import patch
2-
3- from rich .console import Console
41from typer .testing import CliRunner
52
63import idom
74from 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
107
118
129cli_runner = CliRunner ()
1310
1411
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
3114
3215
33- @with_large_console
3416def test_install ():
3517 cli_runner .invoke (main , ["restore" ])
3618 assert cli_runner .invoke (main , ["install" , "jquery" ]).exit_code == 0
@@ -44,54 +26,12 @@ def test_install():
4426 assert web_module_exists ("jquery" )
4527
4628
47- @with_large_console
4829def test_restore ():
4930 assert cli_runner .invoke (main , ["restore" ]).exit_code == 0
5031
5132
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