66
77from chipflow_lib import ChipFlowError
88from chipflow_lib .cli import run
9-
9+ from chipflow_lib . config_models import Config , ChipFlowConfig
1010
1111class MockCommand :
1212 """Mock command for testing CLI"""
@@ -22,6 +22,9 @@ def run_cli(self, args):
2222 raise ValueError ("Unexpected error" )
2323 # Valid action does nothing
2424
25+ MOCK_CONFIG = Config (chipflow = ChipFlowConfig (project_name = "test" ,
26+ steps = {"test" : "test:MockStep" }
27+ ))
2528
2629class TestCLI (unittest .TestCase ):
2730 @mock .patch ("chipflow_lib.cli._parse_config" )
@@ -30,14 +33,7 @@ class TestCLI(unittest.TestCase):
3033 def test_run_success (self , mock_get_cls , mock_pin_command , mock_parse_config ):
3134 """Test CLI run with successful command execution"""
3235 # Setup mocks
33- mock_config = {
34- "chipflow" : {
35- "steps" : {
36- "test" : "test:MockStep"
37- }
38- }
39- }
40- mock_parse_config .return_value = mock_config
36+ mock_parse_config .return_value = MOCK_CONFIG
4137
4238 mock_pin_cmd = MockCommand ()
4339 mock_pin_command .return_value = mock_pin_cmd
@@ -59,14 +55,7 @@ def test_run_success(self, mock_get_cls, mock_pin_command, mock_parse_config):
5955 def test_run_command_error (self , mock_get_cls , mock_pin_command , mock_parse_config ):
6056 """Test CLI run with command raising ChipFlowError"""
6157 # Setup mocks
62- mock_config = {
63- "chipflow" : {
64- "steps" : {
65- "test" : "test:MockStep"
66- }
67- }
68- }
69- mock_parse_config .return_value = mock_config
58+ mock_parse_config .return_value = MOCK_CONFIG
7059
7160 mock_pin_cmd = MockCommand ()
7261 mock_pin_command .return_value = mock_pin_cmd
@@ -93,14 +82,7 @@ def test_run_command_error(self, mock_get_cls, mock_pin_command, mock_parse_conf
9382 def test_run_unexpected_error (self , mock_get_cls , mock_pin_command , mock_parse_config ):
9483 """Test CLI run with command raising unexpected exception"""
9584 # Setup mocks
96- mock_config = {
97- "chipflow" : {
98- "steps" : {
99- "test" : "test:MockStep"
100- }
101- }
102- }
103- mock_parse_config .return_value = mock_config
85+ mock_parse_config .return_value = MOCK_CONFIG
10486
10587 mock_pin_cmd = MockCommand ()
10688 mock_pin_command .return_value = mock_pin_cmd
@@ -127,14 +109,7 @@ def test_run_unexpected_error(self, mock_get_cls, mock_pin_command, mock_parse_c
127109 def test_step_init_error (self , mock_pin_command , mock_parse_config ):
128110 """Test CLI run with error initializing step"""
129111 # Setup mocks
130- mock_config = {
131- "chipflow" : {
132- "steps" : {
133- "test" : "test:MockStep"
134- }
135- }
136- }
137- mock_parse_config .return_value = mock_config
112+ mock_parse_config .return_value = MOCK_CONFIG
138113
139114 mock_pin_cmd = MockCommand ()
140115 mock_pin_command .return_value = mock_pin_cmd
@@ -154,14 +129,7 @@ def test_step_init_error(self, mock_pin_command, mock_parse_config):
154129 def test_build_parser_error (self , mock_get_cls , mock_pin_command , mock_parse_config ):
155130 """Test CLI run with error building CLI parser"""
156131 # Setup mocks
157- mock_config = {
158- "chipflow" : {
159- "steps" : {
160- "test" : "test:MockStep"
161- }
162- }
163- }
164- mock_parse_config .return_value = mock_config
132+ mock_parse_config .return_value = MOCK_CONFIG
165133
166134 # Make pin command raise an error during build_cli_parser
167135 mock_pin_cmd = mock .Mock ()
@@ -183,14 +151,7 @@ def test_build_parser_error(self, mock_get_cls, mock_pin_command, mock_parse_con
183151# def test_verbosity_flags(self, mock_get_cls, mock_pin_command, mock_parse_config):
184152# """Test CLI verbosity flags"""
185153# # Setup mocks
186- # mock_config = {
187- # "chipflow": {
188- # "steps": {
189- # "test": "test:MockStep"
190- # }
191- # }
192- # }
193- # mock_parse_config.return_value = mock_config
154+ # mock_parse_config.return_value = MOCK_CONFIG
194155#
195156# mock_pin_cmd = MockCommand()
196157# mock_pin_command.return_value = mock_pin_cmd
0 commit comments