Skip to content

Commit 19143f2

Browse files
committed
Clean up test suite and get it running
1 parent 74bd48c commit 19143f2

File tree

9 files changed

+264
-429
lines changed

9 files changed

+264
-429
lines changed

chipflow_lib/steps/silicon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def elaborate(self, platform: SiliconPlatform):
3737

3838
# heartbeat led (to confirm clock/reset alive)
3939
if (self._config.chipflow.silicon.debug and
40-
self._config.chipflow.silicon.debug.heartbeat):
40+
self._config.chipflow.silicon.debug.get('heartbeat', False)):
4141
heartbeat_ctr = Signal(23)
4242
m.d.sync += heartbeat_ctr.eq(heartbeat_ctr + 1)
4343
m.d.comb += platform.request("heartbeat").o.eq(heartbeat_ctr[-1])

pdm.lock

Lines changed: 23 additions & 122 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies = [
2626
"doit>=0.36.0",
2727
"requests>=2.20",
2828
"python-dotenv>=1.0.1",
29-
"pydantic>=2.8",
29+
"pydantic>=2.11",
3030
"halo>=0.0.31",
3131
"pyrefly>=0.21.0",
3232
"amaranth-stubs>=0.1.1",

tests/test_cli.py

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from chipflow_lib import ChipFlowError
88
from chipflow_lib.cli import run
9-
9+
from chipflow_lib.config_models import Config, ChipFlowConfig
1010

1111
class 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

2629
class 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

tests/test_init.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import tempfile
66
from unittest import mock
77

8-
98
from chipflow_lib import (
109
ChipFlowError,
1110
_get_cls_by_reference,
1211
_ensure_chipflow_root,
13-
_parse_config_file,
1412
_parse_config
1513
)
16-
from chipflow_lib.config_model import Config, ChipFlowConfig
14+
from chipflow_lib.config import _parse_config_file
15+
from chipflow_lib.config_models import Config, ChipFlowConfig
16+
from chipflow_lib.platforms import Process
1717

1818

1919
class TestCoreUtilities(unittest.TestCase):
@@ -106,15 +106,16 @@ def test_parse_config_file_valid(self):
106106
config = _parse_config_file(config_path)
107107

108108
assert config.chipflow
109+
assert config.chipflow.silicon
109110
self.assertEqual(config.chipflow.project_name, "test_project")
110-
self.assertEqual(config.chipflow.silicon.process, "sky130")
111+
self.assertEqual(config.chipflow.silicon.process, Process.SKY130)
111112

112113
@mock.patch("chipflow_lib._ensure_chipflow_root")
113-
@mock.patch("chipflow_lib._parse_config_file")
114+
@mock.patch("chipflow_lib.config._parse_config_file")
114115
def test_parse_config(self, mock_parse_config_file, mock_ensure_chipflow_root):
115116
"""Test _parse_config which uses _ensure_chipflow_root and _parse_config_file"""
116117
mock_ensure_chipflow_root.return_value = "/mock/chipflow/root"
117-
mock_parse_config_file.return_value = Config(chipflow=ChipFlowConfig(project_name='test', top={'test','test'}))
118+
mock_parse_config_file.return_value = Config(chipflow=ChipFlowConfig(project_name='test', top={'test': 'test'}))
118119

119120
config = _parse_config()
120121

@@ -125,4 +126,4 @@ def test_parse_config(self, mock_parse_config_file, mock_ensure_chipflow_root):
125126
else mock_parse_config_file.call_args[0][0],
126127
"/mock/chipflow/root/chipflow.toml")
127128
self.assertEqual(config.chipflow.project_name, "test")
128-
self.assertEqual(config.chipflow.project_name.top, {'test': 'test'})
129+
self.assertEqual(config.chipflow.top, {'test': 'test'})

0 commit comments

Comments
 (0)