Skip to content

Commit 43ce5bc

Browse files
committed
Refactored the test suite
1 parent 4a0b3a9 commit 43ce5bc

File tree

4 files changed

+27
-53
lines changed

4 files changed

+27
-53
lines changed

numba_rvsdg/tests/test_byteflow.py

Lines changed: 14 additions & 14 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def test_figure_3(self):
442442
flow = FlowInfo.from_bytecode(bc)
443443
scfg = flow.build_basicblocks()
444444
byteflow = ByteFlow(bc=bc, scfg=scfg)
445-
byteflow = byteflow.restructure()
445+
byteflow.restructure()
446446

447447
x, _ = SCFG.from_yaml(fig_3_yaml)
448448
self.assertSCFGEqual(x, byteflow.scfg)
@@ -475,7 +475,7 @@ def test_figure_4(self):
475475
flow = FlowInfo.from_bytecode(bc)
476476
scfg = flow.build_basicblocks()
477477
byteflow = ByteFlow(bc=bc, scfg=scfg)
478-
byteflow = byteflow.restructure()
478+
byteflow.restructure()
479479

480480
x, _ = SCFG.from_yaml(fig_4_yaml)
481481
self.assertSCFGEqual(x, byteflow.scfg)

numba_rvsdg/tests/test_scfg.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def test_scfg_iter(self):
162162
block_0 = name_gen.new_block_name(block_names.BASIC)
163163
block_1 = name_gen.new_block_name(block_names.BASIC)
164164
expected = [
165-
(block_0, BasicBlock(name=block_0, _jump_targets=(block_1,))),
165+
(block_0, BasicBlock(name=block_0, _jump_targets=[block_1])),
166166
(block_1, BasicBlock(name=block_1)),
167167
]
168168
scfg, _ = SCFG.from_yaml(
@@ -194,17 +194,14 @@ def foo(n):
194194

195195
def test_concealed_region_view_iter(self):
196196
flow = ByteFlow.from_bytecode(self.foo)
197-
restructured = flow._restructure_loop()
197+
flow._restructure_loop()
198198
expected = [
199199
("python_bytecode_block_0", PythonBytecodeBlock),
200200
("loop_region_0", RegionBlock),
201201
("python_bytecode_block_3", PythonBytecodeBlock),
202202
]
203203
received = list(
204-
(
205-
(k, type(v))
206-
for k, v in restructured.scfg.concealed_region_view.items()
207-
)
204+
((k, type(v)) for k, v in flow.scfg.concealed_region_view.items())
208205
)
209206
self.assertEqual(expected, received)
210207

numba_rvsdg/tests/test_simulate.py

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,6 @@
44
from numba_rvsdg.tests.simulator import Simulator
55
import unittest
66

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

318
class SimulatorTest(unittest.TestCase):
329
def _run(self, func, flow, kwargs):
@@ -44,7 +21,7 @@ def foo(x):
4421
return c
4522

4623
flow = ByteFlow.from_bytecode(foo)
47-
flow = flow.restructure()
24+
flow.restructure()
4825

4926
# if case
5027
self._run(foo, flow, {"x": 1})
@@ -59,7 +36,7 @@ def foo(x):
5936
return c
6037

6138
flow = ByteFlow.from_bytecode(foo)
62-
flow = flow.restructure()
39+
flow.restructure()
6340

6441
# loop bypass case
6542
self._run(foo, flow, {"x": 0})
@@ -78,7 +55,7 @@ def foo(x):
7855
return c
7956

8057
flow = ByteFlow.from_bytecode(foo)
81-
flow = flow.restructure()
58+
flow.restructure()
8259

8360
# loop bypass case
8461
self._run(foo, flow, {"x": 0})
@@ -97,7 +74,7 @@ def foo(x):
9774
return c
9875

9976
flow = ByteFlow.from_bytecode(foo)
100-
flow = flow.restructure()
77+
flow.restructure()
10178

10279
# loop bypass case
10380
self._run(foo, flow, {"x": 0})
@@ -121,7 +98,7 @@ def foo(x):
12198
return c
12299

123100
flow = ByteFlow.from_bytecode(foo)
124-
flow = flow.restructure()
101+
flow.restructure()
125102

126103
# no loop
127104
self._run(foo, flow, {"x": 0})
@@ -145,7 +122,7 @@ def foo(x):
145122
return c
146123

147124
flow = ByteFlow.from_bytecode(foo)
148-
flow = flow.restructure()
125+
flow.restructure()
149126

150127
# loop bypass
151128
self._run(foo, flow, {"x": 0})
@@ -161,7 +138,7 @@ def foo(x, y):
161138
return (x > 0 and x < 10) or (y > 0 and y < 10)
162139

163140
flow = ByteFlow.from_bytecode(foo)
164-
flow = flow.restructure()
141+
flow.restructure()
165142

166143
self._run(foo, flow, {"x": 5, "y": 5})
167144

@@ -175,7 +152,7 @@ def foo(s, e):
175152
return c
176153

177154
flow = ByteFlow.from_bytecode(foo)
178-
flow = flow.restructure()
155+
flow.restructure()
179156

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

0 commit comments

Comments
 (0)