Skip to content

Commit b652ee7

Browse files
committed
tests/bytes_compare: Rework test for bytes <-> str comparison.
This may produce a warning, depending on MicroPython configuration.
1 parent 40214b9 commit b652ee7

4 files changed

Lines changed: 15 additions & 2 deletions

File tree

tests/basics/bytes_compare2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
print(b"1" == 1)
22
print(b"123" == bytearray(b"123"))
3-
print(b"123" == "123")
43
print(b'123' < bytearray(b"124"))
54
print(b'123' > bytearray(b"122"))
65
print(bytearray(b"23") in b"1234")

tests/basics/bytes_compare3.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Based on MicroPython config option, comparison of str and bytes
2+
# or vice versa may issue a runtime warning. On CPython, if run as
3+
# "python3 -b", only comparison of str to bytes issues a warning,
4+
# not the other way around (while exactly comparison of bytes to
5+
# str would be the most common error, as in sock.recv(3) == "GET").
6+
# Update: the issue above with CPython apparently happens in REPL,
7+
# when run as a script, both lines issue a warning.
8+
print("123" == b"123")
9+
print(b"123" == "123")

tests/basics/bytes_compare3.py.exp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
########
2+
False
3+
########
4+
False

tests/run-tests

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ def rm_f(fname):
2727
os.remove(fname)
2828

2929
def run_micropython(pyb, args, test_file):
30+
special_tests = ('micropython/meminfo.py', 'basics/bytes_compare3.py')
3031
if pyb is None:
3132
# run on PC
32-
if test_file.startswith(('cmdline/', 'feature_check/')) or test_file == 'micropython/meminfo.py':
33+
if test_file.startswith(('cmdline/', 'feature_check/')) or test_file in special_tests :
3334
# special handling for tests of the unix cmdline program
3435

3536
# check for any cmdline options needed for this test

0 commit comments

Comments
 (0)