Skip to content

Commit 023e272

Browse files
authored
Merge pull request #323 from kosarev/use_exceptions_to_stop_emulation
[Tests] Use exceptions for quitting from the emulation loop.
2 parents 9c473b2 + 273a446 commit 023e272

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

tests/runtime/check_test.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import zx
66

77

8+
class Stop(Exception):
9+
pass
10+
11+
812
class Tester(zx.Emulator):
913
def __init__(self):
1014
# speed_factor=None results in maximum speed and
@@ -13,7 +17,7 @@ def __init__(self):
1317
super().__init__(speed_factor=None)
1418

1519
def on_breakpoint(self):
16-
self.stop()
20+
raise Stop
1721

1822
def run_test(self, tape_filename, ram_filename):
1923
# Auto-load the tape.
@@ -22,8 +26,11 @@ def run_test(self, tape_filename, ram_filename):
2226
# Catch the end of test.
2327
self.set_breakpoint(8)
2428

25-
# Run the main loop until self.done is raised.
26-
self.run()
29+
# Run the main loop.
30+
try:
31+
self.run()
32+
except Stop:
33+
pass
2734

2835
# Get view to the video memory.
2936
screen = self.get_memory_view(0x4000, 6 * 1024 + 768)

tests/runtime/update_test.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import zx
99

1010

11+
class Stop(Exception):
12+
pass
13+
14+
1115
class TakeSnapshot(zx.Emulator):
1216
def __init__(self):
1317
# speed_factor=None results in maximum speed and
@@ -25,13 +29,16 @@ def run_test(self, filename):
2529
# Catch the end of test.
2630
self.set_breakpoint(8)
2731

28-
# Run the main loop until self.done is raised.
29-
self.run()
32+
# Run the main loop.
33+
try:
34+
self.run()
35+
except Stop:
36+
pass
3037

3138
# Get view to the video memory.
3239
screen = self.get_memory_view(0x4000, 6 * 1024 + 768)
3340

34-
# Compare it with the etalon screenshot.
41+
# Take screenshot.
3542
with open(filename + '.scr', 'wb') as f:
3643
f.write(screen)
3744

0 commit comments

Comments
 (0)