Skip to content

Commit adeeacf

Browse files
committed
Refactored the test suite
1 parent a1f1316 commit adeeacf

File tree

4 files changed

+27
-53
lines changed

4 files changed

+27
-53
lines changed

numba_rvsdg/tests/test_byteflow.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -114,29 +114,29 @@ def test_constructor(self):
114114
name=name_gen.new_block_name(block_names.PYTHON_BYTECODE),
115115
begin=0,
116116
end=8,
117-
_jump_targets=(),
118-
backedges=(),
117+
_jump_targets=[],
118+
backedges=[],
119119
)
120120
self.assertEqual(block.name, "python_bytecode_block_0")
121121
self.assertEqual(block.begin, 0)
122122
self.assertEqual(block.end, 8)
123123
self.assertFalse(block.fallthrough)
124124
self.assertTrue(block.is_exiting)
125-
self.assertEqual(block.jump_targets, ())
126-
self.assertEqual(block.backedges, ())
125+
self.assertEqual(block.jump_targets, [])
126+
self.assertEqual(block.backedges, [])
127127

128128
def test_is_jump_target(self):
129129
name_gen = NameGenerator()
130130
block = PythonBytecodeBlock(
131131
name=name_gen.new_block_name(block_names.PYTHON_BYTECODE),
132132
begin=0,
133133
end=8,
134-
_jump_targets=(
134+
_jump_targets=[
135135
name_gen.new_block_name(block_names.PYTHON_BYTECODE),
136-
),
137-
backedges=(),
136+
],
137+
backedges=[],
138138
)
139-
self.assertEqual(block.jump_targets, ("python_bytecode_block_1",))
139+
self.assertEqual(block.jump_targets, ["python_bytecode_block_1"])
140140
self.assertFalse(block.is_exiting)
141141

142142
def test_get_instructions(self):
@@ -145,8 +145,8 @@ def test_get_instructions(self):
145145
name=name_gen.new_block_name(block_names.PYTHON_BYTECODE),
146146
begin=0,
147147
end=8,
148-
_jump_targets=(),
149-
backedges=(),
148+
_jump_targets=[],
149+
backedges=[],
150150
)
151151
expected = [
152152
Instruction(
@@ -242,8 +242,8 @@ def test_build_basic_blocks(self):
242242
name=new_name,
243243
begin=0,
244244
end=10,
245-
_jump_targets=(),
246-
backedges=(),
245+
_jump_targets=[],
246+
backedges=[],
247247
)
248248
}
249249
)
@@ -266,8 +266,8 @@ def test_from_bytecode(self):
266266
name=new_name,
267267
begin=0,
268268
end=10,
269-
_jump_targets=(),
270-
backedges=(),
269+
_jump_targets=[],
270+
backedges=[],
271271
)
272272
}
273273
)

numba_rvsdg/tests/test_figures.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def test_figure_3(self):
440440
flow = FlowInfo.from_bytecode(bc)
441441
scfg = flow.build_basicblocks()
442442
byteflow = ByteFlow(bc=bc, scfg=scfg)
443-
byteflow = byteflow.restructure()
443+
byteflow.restructure()
444444

445445
x, _ = SCFG.from_yaml(fig_3_yaml)
446446
self.assertSCFGEqual(x, byteflow.scfg)
@@ -473,7 +473,7 @@ def test_figure_4(self):
473473
flow = FlowInfo.from_bytecode(bc)
474474
scfg = flow.build_basicblocks()
475475
byteflow = ByteFlow(bc=bc, scfg=scfg)
476-
byteflow = byteflow.restructure()
476+
byteflow.restructure()
477477

478478
x, _ = SCFG.from_yaml(fig_4_yaml)
479479
self.assertSCFGEqual(x, byteflow.scfg)

numba_rvsdg/tests/test_scfg.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_scfg_iter(self):
160160
block_0 = name_gen.new_block_name(block_names.BASIC)
161161
block_1 = name_gen.new_block_name(block_names.BASIC)
162162
expected = [
163-
(block_0, BasicBlock(name=block_0, _jump_targets=(block_1,))),
163+
(block_0, BasicBlock(name=block_0, _jump_targets=[block_1])),
164164
(block_1, BasicBlock(name=block_1)),
165165
]
166166
scfg, _ = SCFG.from_yaml(
@@ -192,17 +192,14 @@ def foo(n):
192192

193193
def test_concealed_region_view_iter(self):
194194
flow = ByteFlow.from_bytecode(self.foo)
195-
restructured = flow._restructure_loop()
195+
flow._restructure_loop()
196196
expected = [
197197
("python_bytecode_block_0", PythonBytecodeBlock),
198198
("loop_region_0", RegionBlock),
199199
("python_bytecode_block_3", PythonBytecodeBlock),
200200
]
201201
received = list(
202-
(
203-
(k, type(v))
204-
for k, v in restructured.scfg.concealed_region_view.items()
205-
)
202+
((k, type(v)) for k, v in flow.scfg.concealed_region_view.items())
206203
)
207204
self.assertEqual(expected, received)
208205

numba_rvsdg/tests/test_simulate.py

+8-31
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,6 @@
22
from numba_rvsdg.tests.simulator import Simulator
33
import unittest
44

5-
# flow = ByteFlow.from_bytecode(foo)
6-
# #pprint(flow.scfg)
7-
# flow = flow.restructure()
8-
# #pprint(flow.scfg)
9-
# # pprint(rtsflow.scfg)
10-
# ByteFlowRenderer().render_byteflow(flow).view()
11-
# print(dis(foo))
12-
#
13-
# sim = Simulator(flow, foo.__globals__)
14-
# ret = sim.run(dict(x=1))
15-
# assert ret == foo(x=1)
16-
#
17-
# #sim = Simulator(flow, foo.__globals__)
18-
# #ret = sim.run(dict(x=100))
19-
# #assert ret == foo(x=100)
20-
21-
# You can use the following snipppet to visually debug the restructured
22-
# byteflow:
23-
#
24-
# ByteFlowRenderer().render_byteflow(flow).view()
25-
#
26-
#
27-
285

296
class SimulatorTest(unittest.TestCase):
307
def _run(self, func, flow, kwargs):
@@ -42,7 +19,7 @@ def foo(x):
4219
return c
4320

4421
flow = ByteFlow.from_bytecode(foo)
45-
flow = flow.restructure()
22+
flow.restructure()
4623

4724
# if case
4825
self._run(foo, flow, {"x": 1})
@@ -57,7 +34,7 @@ def foo(x):
5734
return c
5835

5936
flow = ByteFlow.from_bytecode(foo)
60-
flow = flow.restructure()
37+
flow.restructure()
6138

6239
# loop bypass case
6340
self._run(foo, flow, {"x": 0})
@@ -76,7 +53,7 @@ def foo(x):
7653
return c
7754

7855
flow = ByteFlow.from_bytecode(foo)
79-
flow = flow.restructure()
56+
flow.restructure()
8057

8158
# loop bypass case
8259
self._run(foo, flow, {"x": 0})
@@ -95,7 +72,7 @@ def foo(x):
9572
return c
9673

9774
flow = ByteFlow.from_bytecode(foo)
98-
flow = flow.restructure()
75+
flow.restructure()
9976

10077
# loop bypass case
10178
self._run(foo, flow, {"x": 0})
@@ -119,7 +96,7 @@ def foo(x):
11996
return c
12097

12198
flow = ByteFlow.from_bytecode(foo)
122-
flow = flow.restructure()
99+
flow.restructure()
123100

124101
# no loop
125102
self._run(foo, flow, {"x": 0})
@@ -143,7 +120,7 @@ def foo(x):
143120
return c
144121

145122
flow = ByteFlow.from_bytecode(foo)
146-
flow = flow.restructure()
123+
flow.restructure()
147124

148125
# loop bypass
149126
self._run(foo, flow, {"x": 0})
@@ -159,7 +136,7 @@ def foo(x, y):
159136
return (x > 0 and x < 10) or (y > 0 and y < 10)
160137

161138
flow = ByteFlow.from_bytecode(foo)
162-
flow = flow.restructure()
139+
flow.restructure()
163140

164141
self._run(foo, flow, {"x": 5, "y": 5})
165142

@@ -173,7 +150,7 @@ def foo(s, e):
173150
return c
174151

175152
flow = ByteFlow.from_bytecode(foo)
176-
flow = flow.restructure()
153+
flow.restructure()
177154

178155
# no looping
179156
self._run(foo, flow, {"s": 0, "e": 0})

0 commit comments

Comments
 (0)