Skip to content

Commit 96581ff

Browse files
author
Filip Jagodzinski
committed
Tests: USB: Fix Python 3 compatibility
Use integer division explicitly in basic test. Convert bytes to str for Python 3 in serial test.
1 parent d0b5ba6 commit 96581ff

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

TESTS/host_tests/pyusb_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ def ep_test_abort(dev, log, verbose=False):
13691369
payload_size = (NUM_PACKETS_UNTIL_ABORT + NUM_PACKETS_AFTER_ABORT) * ep_out.wMaxPacketSize
13701370
num_bytes_written = 0
13711371
while num_bytes_written < payload_size:
1372-
payload_out = array.array('B', (num_bytes_written/ep_out.wMaxPacketSize
1372+
payload_out = array.array('B', (num_bytes_written//ep_out.wMaxPacketSize
13731373
for _ in range(ep_out.wMaxPacketSize)))
13741374
try:
13751375
num_bytes_written += ep_out.write(payload_out)

TESTS/host_tests/usb_device_serial.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ def usb_serial_name(serial_number):
6464
return None
6565

6666

67+
if sys.version_info < (3,):
68+
def bytes2str(source):
69+
"""Return a string decoded from source."""
70+
return source
71+
else:
72+
def bytes2str(source):
73+
"""Return a string decoded from source."""
74+
return source.decode()
75+
76+
6777
class RetryError(Exception):
6878
"""Exception raised by retry_fun_call()."""
6979

@@ -268,7 +278,7 @@ def change_line_coding(self):
268278
mbed_serial.reset_output_buffer()
269279
mbed_serial.dtr = True
270280
try:
271-
payload = mbed_serial.read(LINE_CODING_STRLEN)
281+
payload = bytes2str(mbed_serial.read(LINE_CODING_STRLEN))
272282
while len(payload) == LINE_CODING_STRLEN:
273283
baud, bits, parity, stop = (int(i) for i in payload.split(','))
274284
new_line_coding = {
@@ -277,7 +287,7 @@ def change_line_coding(self):
277287
'parity': self._PARITIES[parity],
278288
'stopbits': self._STOPBITS[stop]}
279289
mbed_serial.apply_settings(new_line_coding)
280-
payload = mbed_serial.read(LINE_CODING_STRLEN)
290+
payload = bytes2str(mbed_serial.read(LINE_CODING_STRLEN))
281291
except serial.SerialException as exc:
282292
self.log('TEST ERROR: {}'.format(exc))
283293
self.notify_complete(False)

0 commit comments

Comments
 (0)