Skip to content

Commit db6f854

Browse files
committed
Fix up tests for reduce API
1 parent d31d0ec commit db6f854

File tree

9 files changed

+120
-1223
lines changed

9 files changed

+120
-1223
lines changed

tests/test_config_models.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import os
33
import unittest
44

5-
from chipflow_lib.config_models import PadConfig
6-
75

86
class ConfigModelsTestCase(unittest.TestCase):
97
def setUp(self):
@@ -36,15 +34,6 @@ def test_config_validation(self):
3634
# self.assertEqual(config.chipflow.silicon.process, Process.SKY130)
3735
self.skipTest("Config validation temporarily disabled")
3836

39-
def test_pad_config(self):
40-
"""Test validation of pad configuration."""
41-
pad = PadConfig(type="clock", loc="114")
42-
self.assertEqual(pad.type, "clock")
43-
self.assertEqual(pad.loc, "114")
44-
45-
# Test validation of loc format
46-
with self.assertRaises(ValueError):
47-
PadConfig(type="clock", loc="invalid-format")
4837

4938
def test_nested_structure(self):
5039
"""Test the nested structure of the Config model."""

tests/test_init.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
)
1616
from chipflow_lib.config import _parse_config_file
1717
from chipflow_lib.config_models import Config, ChipFlowConfig
18-
from chipflow_lib.platforms import Process
18+
# Process is not part of the public API, so we won't test it here
1919

2020

2121
class TestCoreUtilities(unittest.TestCase):
@@ -110,7 +110,8 @@ def test_parse_config_file_valid(self):
110110
assert config.chipflow
111111
assert config.chipflow.silicon
112112
self.assertEqual(config.chipflow.project_name, "test_project")
113-
self.assertEqual(config.chipflow.silicon.process, Process.SKY130)
113+
# Process enum is not part of the public API, so we just check that process has a string value
114+
self.assertEqual(str(config.chipflow.silicon.process), "sky130")
114115

115116
@mock.patch("chipflow_lib._ensure_chipflow_root")
116117
@mock.patch("chipflow_lib.config._parse_config_file")

tests/test_package_pins.py

Lines changed: 17 additions & 249 deletions
Original file line numberDiff line numberDiff line change
@@ -1,252 +1,20 @@
11
# SPDX-License-Identifier: BSD-2-Clause
22
import unittest
33

4-
from chipflow_lib.platforms.utils import (
5-
BareDiePackageDef, QuadPackageDef, Package, GAPackageDef, GALayout, GAPin
6-
)
7-
8-
9-
class TestBareDiePackage(unittest.TestCase):
10-
def setUp(self):
11-
self.package = BareDiePackageDef(name="test_package", width=8, height=4)
12-
13-
def test_basic_properties(self):
14-
"""Test basic package properties"""
15-
self.assertEqual(self.package.name, "test_package")
16-
self.assertEqual(self.package.width, 8)
17-
self.assertEqual(self.package.height, 4)
18-
self.assertEqual(self.package.package_type, "BareDiePackageDef")
19-
20-
def test_bringup_pins(self):
21-
"""Test bringup pins configuration"""
22-
bringup_pins = self.package.bringup_pins
23-
24-
# Test that we have the required bringup pin categories
25-
self.assertIsNotNone(bringup_pins.core_power)
26-
self.assertIsNotNone(bringup_pins.core_clock)
27-
self.assertIsNotNone(bringup_pins.core_reset)
28-
self.assertIsNotNone(bringup_pins.core_heartbeat)
29-
self.assertIsNotNone(bringup_pins.core_jtag)
30-
31-
# Test that power pins are structured correctly
32-
self.assertGreaterEqual(len(bringup_pins.core_power), 1)
33-
34-
# Test that JTAG pins have all required signals
35-
jtag = bringup_pins.core_jtag
36-
self.assertIsNotNone(jtag.trst)
37-
self.assertIsNotNone(jtag.tck)
38-
self.assertIsNotNone(jtag.tms)
39-
self.assertIsNotNone(jtag.tdi)
40-
self.assertIsNotNone(jtag.tdo)
41-
42-
43-
class TestQuadPackage(unittest.TestCase):
44-
def setUp(self):
45-
self.package = QuadPackageDef(name="test_package", width=36, height=36)
46-
47-
def test_basic_properties(self):
48-
"""Test basic package properties"""
49-
self.assertEqual(self.package.name, "test_package")
50-
self.assertEqual(self.package.width, 36)
51-
self.assertEqual(self.package.height, 36)
52-
self.assertEqual(self.package.package_type, "QuadPackageDef")
53-
54-
def test_bringup_pins(self):
55-
"""Test bringup pins configuration"""
56-
bringup_pins = self.package.bringup_pins
57-
58-
# Test that we have the required bringup pin categories
59-
self.assertIsNotNone(bringup_pins.core_power)
60-
self.assertIsNotNone(bringup_pins.core_clock)
61-
self.assertIsNotNone(bringup_pins.core_reset)
62-
self.assertIsNotNone(bringup_pins.core_heartbeat)
63-
self.assertIsNotNone(bringup_pins.core_jtag)
64-
65-
# Test that power pins are structured correctly
66-
self.assertGreaterEqual(len(bringup_pins.core_power), 1)
67-
68-
# Test that JTAG pins have all required signals
69-
jtag = bringup_pins.core_jtag
70-
self.assertIsNotNone(jtag.trst)
71-
self.assertIsNotNone(jtag.tck)
72-
self.assertIsNotNone(jtag.tms)
73-
self.assertIsNotNone(jtag.tdi)
74-
self.assertIsNotNone(jtag.tdo)
75-
76-
77-
class TestPackage(unittest.TestCase):
78-
def setUp(self):
79-
self.package_def = BareDiePackageDef(name="test_package", width=8, height=4)
80-
self.package = Package(type=self.package_def)
81-
82-
def test_package_initialization(self):
83-
"""Test basic package initialization"""
84-
self.assertIsNotNone(self.package.type)
85-
self.assertEqual(self.package.type.name, "test_package")
86-
self.assertEqual(self.package.type.width, 8)
87-
self.assertEqual(self.package.type.height, 4)
88-
89-
def test_package_type_access(self):
90-
"""Test accessing package type properties through Package"""
91-
# Should be able to access package type bringup pins
92-
bringup_pins = self.package.type.bringup_pins
93-
self.assertIsNotNone(bringup_pins)
94-
95-
# Test package discriminator
96-
self.assertEqual(self.package.type.package_type, "BareDiePackageDef")
97-
98-
99-
class TestGAPackage(unittest.TestCase):
100-
def test_gapin_creation(self):
101-
"""Test GAPin creation and equality"""
102-
pin1 = GAPin(h="A", w=1)
103-
pin2 = GAPin(h="A", w=1)
104-
pin3 = GAPin(h="B", w=2)
105-
106-
# Test equality
107-
self.assertEqual(pin1, pin2)
108-
self.assertNotEqual(pin1, pin3)
109-
110-
# Test attributes
111-
self.assertEqual(pin1.h, "A")
112-
self.assertEqual(pin1.w, 1)
113-
self.assertEqual(pin3.h, "B")
114-
self.assertEqual(pin3.w, 2)
115-
116-
def test_galayout_enum_values(self):
117-
"""Test GALayout enum values"""
118-
self.assertEqual(GALayout.FULL, "full")
119-
self.assertEqual(GALayout.PERIMETER, "perimeter")
120-
self.assertEqual(GALayout.CHANNEL, "channel")
121-
self.assertEqual(GALayout.ISLAND, "island")
122-
123-
def test_gapackagedef_class_structure(self):
124-
"""Test GAPackageDef class structure and type"""
125-
# Test that we can import and access the class
126-
from chipflow_lib.platforms.utils import BasePackageDef
127-
128-
# Test that GAPackageDef inherits from BasePackageDef
129-
self.assertTrue(issubclass(GAPackageDef, BasePackageDef))
130-
131-
# Test that it has the correct type discriminator
132-
self.assertEqual(GAPackageDef.model_fields['package_type'].default, 'GAPackageDef')
133-
134-
def test_gapackagedef_field_types(self):
135-
"""Test GAPackageDef field definitions"""
136-
137-
# Test that fields exist
138-
fields = GAPackageDef.model_fields
139-
self.assertIn('name', fields)
140-
self.assertIn('width', fields)
141-
self.assertIn('height', fields)
142-
self.assertIn('layout_type', fields)
143-
self.assertIn('channel_width', fields)
144-
self.assertIn('island_width', fields)
145-
self.assertIn('missing_pins', fields)
146-
self.assertIn('additional_pins', fields)
147-
148-
def test_gapackagedef_pydantic_model(self):
149-
"""Test GAPackageDef as a Pydantic model"""
150-
151-
# Test that it's a Pydantic model
152-
import pydantic
153-
self.assertTrue(issubclass(GAPackageDef, pydantic.BaseModel))
154-
155-
# Test that it has the expected type field in model_fields
156-
self.assertIn('package_type', GAPackageDef.model_fields)
157-
158-
def test_missing_pins_configuration(self):
159-
"""Test missing pins configuration"""
160-
# Since GAPin is not hashable, test individual pins
161-
pin1 = GAPin(h="A", w=1)
162-
pin2 = GAPin(h="B", w=2)
163-
pin3 = GAPin(h="C", w=3)
164-
165-
# Test that pins can be created correctly
166-
self.assertEqual(pin1.h, "A")
167-
self.assertEqual(pin1.w, 1)
168-
self.assertEqual(pin2.h, "B")
169-
self.assertEqual(pin2.w, 2)
170-
self.assertEqual(pin3.h, "C")
171-
self.assertEqual(pin3.w, 3)
172-
173-
# Test that pins are equal to themselves
174-
self.assertEqual(pin1, GAPin(h="A", w=1))
175-
self.assertEqual(pin2, GAPin(h="B", w=2))
176-
177-
def test_additional_pins_configuration(self):
178-
"""Test additional pins configuration"""
179-
# Since GAPin is not hashable, test individual pins
180-
pin1 = GAPin(h="D", w=4)
181-
pin2 = GAPin(h="E", w=5)
182-
183-
# Test that additional pins can be created correctly
184-
self.assertEqual(pin1.h, "D")
185-
self.assertEqual(pin1.w, 4)
186-
self.assertEqual(pin2.h, "E")
187-
self.assertEqual(pin2.w, 5)
188-
189-
# Test equality
190-
self.assertEqual(pin1, GAPin(h="D", w=4))
191-
self.assertEqual(pin2, GAPin(h="E", w=5))
192-
193-
def test_layout_type_values(self):
194-
"""Test different layout type values"""
195-
# Test that GALayout values are correct
196-
self.assertEqual(GALayout.FULL.value, "full")
197-
self.assertEqual(GALayout.PERIMETER.value, "perimeter")
198-
self.assertEqual(GALayout.CHANNEL.value, "channel")
199-
self.assertEqual(GALayout.ISLAND.value, "island")
200-
201-
def test_package_public_api_methods(self):
202-
"""Test that expected public API methods exist"""
203-
204-
# Test that expected methods exist
205-
self.assertTrue(hasattr(GAPackageDef, 'allocate_pins'))
206-
self.assertTrue(hasattr(GAPackageDef, 'bringup_pins'))
207-
self.assertTrue(hasattr(GAPackageDef, 'heartbeat'))
208-
self.assertTrue(hasattr(GAPackageDef, '_power'))
209-
self.assertTrue(hasattr(GAPackageDef, '_jtag'))
210-
211-
# Test that these are callable or properties
212-
self.assertTrue(callable(GAPackageDef.allocate_pins))
213-
# bringup_pins, heartbeat, _power, _jtag are properties
214-
215-
def test_gapin_equality_operations(self):
216-
"""Test that GAPin equality works correctly"""
217-
pin1 = GAPin(h="A", w=1)
218-
pin2 = GAPin(h="A", w=1) # Duplicate
219-
pin3 = GAPin(h="B", w=2)
220-
221-
# Test that GAPin equality works correctly
222-
self.assertEqual(pin1, pin2) # pin1 and pin2 are equal
223-
self.assertNotEqual(pin1, pin3) # pin1 and pin3 are different
224-
self.assertNotEqual(pin2, pin3) # pin2 and pin3 are different
225-
226-
# Test that different coordinates create different pins
227-
self.assertNotEqual(GAPin(h="A", w=1), GAPin(h="A", w=2))
228-
self.assertNotEqual(GAPin(h="A", w=1), GAPin(h="B", w=1))
229-
230-
def test_gapin_string_representation(self):
231-
"""Test GAPin string representation"""
232-
pin = GAPin(h="A", w=1)
233-
234-
# Test that pin has reasonable string representation
235-
str_repr = str(pin)
236-
self.assertIn("A", str_repr)
237-
self.assertIn("1", str_repr)
238-
239-
def test_inheritance_from_basepackagedef(self):
240-
"""Test that GAPackageDef properly inherits from BasePackageDef"""
241-
from chipflow_lib.platforms.utils import BasePackageDef
242-
243-
# Test inheritance
244-
self.assertTrue(issubclass(GAPackageDef, BasePackageDef))
245-
246-
# Test that abstract methods are implemented
247-
base_methods = [method for method in dir(BasePackageDef)
248-
if not method.startswith('_') and callable(getattr(BasePackageDef, method, None))]
249-
250-
for method in base_methods:
251-
self.assertTrue(hasattr(GAPackageDef, method),
252-
f"GAPackageDef should implement {method} from BasePackageDef")
4+
from chipflow_lib.platforms import PACKAGE_DEFINITIONS
5+
6+
7+
class TestPackageDefinitions(unittest.TestCase):
8+
def test_package_definitions_available(self):
9+
"""Test that package definitions are available through public API"""
10+
self.assertIsInstance(PACKAGE_DEFINITIONS, dict)
11+
self.assertIn('pga144', PACKAGE_DEFINITIONS)
12+
self.assertIn('cf20', PACKAGE_DEFINITIONS)
13+
14+
def test_package_definitions_structure(self):
15+
"""Test basic structure of package definitions"""
16+
for name, package_def in PACKAGE_DEFINITIONS.items():
17+
self.assertIsNotNone(package_def)
18+
self.assertTrue(hasattr(package_def, 'name'))
19+
# Package names might have different cases
20+
self.assertEqual(package_def.name.lower(), name.lower())

0 commit comments

Comments
 (0)