Skip to content

Commit b636d02

Browse files
committed
Make pyboard.py have its own exception; update run-tests for pyboard.
1 parent d240ff8 commit b636d02

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

tests/run-tests

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,21 @@ for test_file in tests:
4646
output_expected = b'CPYTHON3 CRASH'
4747

4848
# run Micro Python
49-
try:
50-
if test_on_pyboard:
51-
pyb.enter_raw_repl()
52-
output_mupy = pyb.execfile(test_file).replace(b'\r\n', b'\n')
53-
else:
49+
if test_on_pyboard:
50+
pyb.enter_raw_repl()
51+
try:
52+
if test_file == 'basics/math-fun.py':
53+
# this test crashes the pyboard
54+
output_mupy = b'CRASH'
55+
else:
56+
output_mupy = pyb.execfile(test_file).replace(b'\r\n', b'\n')
57+
except pyboard.PyboardError:
58+
output_mupy = b'CRASH\n' + output_mupy
59+
else:
60+
try:
5461
output_mupy = subprocess.check_output([MP_PY, '-X', 'emit=bytecode', test_file])
55-
except subprocess.CalledProcessError:
56-
output_mupy = b'CRASH'
62+
except subprocess.CalledProcessError:
63+
output_mupy = b'CRASH'
5764

5865
testcase_count += len(output_expected.splitlines())
5966

tools/pyboard.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import time
2323
import serial
2424

25+
class PyboardError(BaseException):
26+
pass
27+
2528
class Pyboard:
2629
def __init__(self, serial_device):
2730
self.serial = serial.Serial(serial_device)
@@ -38,7 +41,7 @@ def enter_raw_repl(self):
3841
time.sleep(0.1)
3942
if not data.endswith(b'raw REPL; CTRL-B to exit\r\n>'):
4043
print(data)
41-
raise Exception('could not enter raw repl')
44+
raise PyboardError('could not enter raw repl')
4245

4346
def exit_raw_repl(self):
4447
self.serial.write(b'\r\x02') # ctrl-B: enter friendly REPL
@@ -56,7 +59,7 @@ def exec(self, command):
5659
self.serial.write(b'\x04')
5760
data = self.serial.read(2)
5861
if data != b'OK':
59-
raise Exception('could not exec command')
62+
raise PyboardError('could not exec command')
6063
data = self.serial.read(2)
6164
timeout = 0
6265
while True:
@@ -72,10 +75,10 @@ def exec(self, command):
7275
time.sleep(0.1)
7376
if not data.endswith(b'\x04>'):
7477
print(data)
75-
raise Exception('timeout waiting for EOF reception')
78+
raise PyboardError('timeout waiting for EOF reception')
7679
if data.startswith(b'Traceback') or data.startswith(b' File '):
7780
print(data)
78-
raise Exception('command failed')
81+
raise PyboardError('command failed')
7982
return data[:-2]
8083

8184
def execfile(self, filename):

0 commit comments

Comments
 (0)