Skip to content

Commit 0385d67

Browse files
Fatsiewhitequark
authored andcommitted
Test positional and keyword argument passing
When functions support positional argument passing both passing the argument by position and by keyword is part of the API. Using both call methods in the unit tests for such arguments will detect possible future backwards compatibility breakage.
1 parent 13a2370 commit 0385d67

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

nmigen_soc/test/test_csr_bus.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_width_wrong(self):
5858
def test_access_wrong(self):
5959
with self.assertRaisesRegex(ValueError,
6060
r"Access mode must be one of \"r\", \"w\", or \"rw\", not 'wo'"):
61-
Element(1, "wo")
61+
Element(width=1, access="wo")
6262

6363

6464
class InterfaceTestCase(unittest.TestCase):
@@ -154,7 +154,7 @@ def test_add_extend(self):
154154
def test_add_wrong(self):
155155
with self.assertRaisesRegex(TypeError,
156156
r"Element must be an instance of csr\.Element, not 'foo'"):
157-
self.dut.add("foo")
157+
self.dut.add(element="foo")
158158

159159
def test_align_to(self):
160160
self.assertEqual(self.dut.add(Element(8, "rw")),
@@ -266,7 +266,7 @@ def test_over_align_to(self):
266266
def test_under_align_to(self):
267267
self.assertEqual(self.dut.add(Element(8, "rw")),
268268
(0, 4))
269-
self.assertEqual(self.dut.align_to(1), 4)
269+
self.assertEqual(self.dut.align_to(alignment=1), 4)
270270
self.assertEqual(self.dut.add(Element(8, "rw")),
271271
(4, 8))
272272

@@ -315,6 +315,7 @@ def test_align_to(self):
315315
self.assertEqual(self.dut.add(sub_1), (0, 0x400, 1))
316316

317317
self.assertEqual(self.dut.align_to(12), 0x1000)
318+
self.assertEqual(self.dut.align_to(alignment=12), 0x1000)
318319

319320
sub_2 = Interface(addr_width=10, data_width=8)
320321
sub_2.memory_map = MemoryMap(addr_width=10, data_width=8)
@@ -329,7 +330,7 @@ def test_add_extend(self):
329330
def test_add_wrong_sub_bus(self):
330331
with self.assertRaisesRegex(TypeError,
331332
r"Subordinate bus must be an instance of csr\.Interface, not 1"):
332-
self.dut.add(1)
333+
self.dut.add(sub_bus=1)
333334

334335
def test_add_wrong_data_width(self):
335336
mux = Multiplexer(addr_width=10, data_width=16)

nmigen_soc/test/test_csr_wishbone.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class WishboneCSRBridgeTestCase(unittest.TestCase):
3333
def test_wrong_csr_bus(self):
3434
with self.assertRaisesRegex(ValueError,
3535
r"CSR bus must be an instance of CSRInterface, not 'foo'"):
36-
WishboneCSRBridge(csr_bus="foo")
36+
WishboneCSRBridge("foo")
3737

3838
def test_wrong_csr_bus_data_width(self):
3939
with self.assertRaisesRegex(ValueError,

nmigen_soc/test/test_event.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_add(self):
5858
src_1 = Source()
5959
event_map = EventMap()
6060
event_map.add(src_0)
61-
event_map.add(src_1)
61+
event_map.add(src=src_1)
6262
self.assertTrue(src_0 in event_map._sources)
6363
self.assertTrue(src_1 in event_map._sources)
6464

@@ -88,7 +88,7 @@ def test_index(self):
8888
event_map.add(src_0)
8989
event_map.add(src_1)
9090
self.assertEqual(event_map.index(src_0), 0)
91-
self.assertEqual(event_map.index(src_1), 1)
91+
self.assertEqual(event_map.index(src=src_1), 1)
9292

9393
def test_index_add_twice(self):
9494
src = Source()
@@ -139,7 +139,7 @@ def test_simple(self):
139139
def test_event_map_wrong(self):
140140
with self.assertRaisesRegex(TypeError,
141141
r"Event map must be an instance of EventMap, not 'foo'"):
142-
dut = Monitor("foo")
142+
dut = Monitor(event_map="foo")
143143

144144
def test_events(self):
145145
sub_0 = Source(trigger="level")

nmigen_soc/test/test_memory.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_set_addr_width_wrong_frozen(self):
8080
def test_add_resource(self):
8181
memory_map = MemoryMap(addr_width=16, data_width=8)
8282
self.assertEqual(memory_map.add_resource("a", size=1), (0, 1))
83-
self.assertEqual(memory_map.add_resource("b", size=2), (1, 3))
83+
self.assertEqual(memory_map.add_resource(resource="b", size=2), (1, 3))
8484

8585
def test_add_resource_map_aligned(self):
8686
memory_map = MemoryMap(addr_width=16, data_width=8, alignment=1)
@@ -197,7 +197,7 @@ def test_add_window_wrong_window(self):
197197
memory_map = MemoryMap(addr_width=16, data_width=8)
198198
with self.assertRaisesRegex(TypeError,
199199
r"Window must be a MemoryMap, not 'a'"):
200-
memory_map.add_window("a")
200+
memory_map.add_window(window="a")
201201

202202
def test_add_window_wrong_wider(self):
203203
memory_map = MemoryMap(addr_width=16, data_width=8)
@@ -284,7 +284,7 @@ def test_align_to_wrong(self):
284284
memory_map = MemoryMap(addr_width=16, data_width=8)
285285
with self.assertRaisesRegex(ValueError,
286286
r"Alignment must be a non-negative integer, not -1"):
287-
memory_map.align_to(-1)
287+
memory_map.align_to(alignment=-1)
288288

289289

290290
class MemoryMapDiscoveryTestCase(unittest.TestCase):
@@ -334,4 +334,4 @@ def test_decode_address(self):
334334
self.assertEqual(self.root.decode_address(end - 1), res)
335335

336336
def test_decode_address_missing(self):
337-
self.assertIsNone(self.root.decode_address(0x00000100))
337+
self.assertIsNone(self.root.decode_address(address=0x00000100))

nmigen_soc/test/test_wishbone_bus.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def test_add_align_to(self):
134134
sub_2.memory_map = MemoryMap(addr_width=16, data_width=16)
135135
self.assertEqual(self.dut.add(sub_1), (0x00000000, 0x00010000, 1))
136136
self.assertEqual(self.dut.align_to(18), 0x000040000)
137+
self.assertEqual(self.dut.align_to(alignment=18), 0x000040000)
137138
self.assertEqual(self.dut.add(sub_2), (0x00040000, 0x00050000, 1))
138139

139140
def test_add_extend(self):
@@ -145,7 +146,7 @@ def test_add_extend(self):
145146
def test_add_wrong(self):
146147
with self.assertRaisesRegex(TypeError,
147148
r"Subordinate bus must be an instance of wishbone\.Interface, not 'foo'"):
148-
self.dut.add("foo")
149+
self.dut.add(sub_bus="foo")
149150

150151
def test_add_wrong_granularity(self):
151152
with self.assertRaisesRegex(ValueError,
@@ -381,7 +382,7 @@ def setUp(self):
381382
def test_add_wrong(self):
382383
with self.assertRaisesRegex(TypeError,
383384
r"Initiator bus must be an instance of wishbone\.Interface, not 'foo'"):
384-
self.dut.add("foo")
385+
self.dut.add(intr_bus="foo")
385386

386387
def test_add_wrong_addr_width(self):
387388
with self.assertRaisesRegex(ValueError,

0 commit comments

Comments
 (0)