summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/bytes_compare2.py1
-rw-r--r--tests/basics/bytes_compare3.py9
-rw-r--r--tests/basics/bytes_compare3.py.exp4
-rw-r--r--tests/basics/bytes_find.py3
-rw-r--r--tests/basics/bytes_partition.py7
-rw-r--r--tests/basics/string_partition.py7
-rw-r--r--tests/basics/string_rpartition.py7
-rw-r--r--tests/extmod/btree1.py12
-rw-r--r--tests/extmod/btree1.py.exp2
-rw-r--r--tests/extmod/machine1.py5
-rw-r--r--tests/extmod/machine_mem.py16
-rw-r--r--tests/extmod/machine_mem.py.exp1
-rw-r--r--tests/extmod/machine_pinbase.py12
-rw-r--r--tests/io/bytesio_ext.py19
-rw-r--r--tests/io/write_ext.py25
-rw-r--r--tests/io/write_ext.py.exp5
-rwxr-xr-xtests/run-tests122
-rw-r--r--tests/unicode/unicode_subscr.py23
18 files changed, 199 insertions, 81 deletions
diff --git a/tests/basics/bytes_compare2.py b/tests/basics/bytes_compare2.py
index 02516de93a..8959da3ae7 100644
--- a/tests/basics/bytes_compare2.py
+++ b/tests/basics/bytes_compare2.py
@@ -1,6 +1,5 @@
print(b"1" == 1)
print(b"123" == bytearray(b"123"))
-print(b"123" == "123")
print(b'123' < bytearray(b"124"))
print(b'123' > bytearray(b"122"))
print(bytearray(b"23") in b"1234")
diff --git a/tests/basics/bytes_compare3.py b/tests/basics/bytes_compare3.py
new file mode 100644
index 0000000000..4b9cbd5b3a
--- /dev/null
+++ b/tests/basics/bytes_compare3.py
@@ -0,0 +1,9 @@
+# Based on MicroPython config option, comparison of str and bytes
+# or vice versa may issue a runtime warning. On CPython, if run as
+# "python3 -b", only comparison of str to bytes issues a warning,
+# not the other way around (while exactly comparison of bytes to
+# str would be the most common error, as in sock.recv(3) == "GET").
+# Update: the issue above with CPython apparently happens in REPL,
+# when run as a script, both lines issue a warning.
+print("123" == b"123")
+print(b"123" == "123")
diff --git a/tests/basics/bytes_compare3.py.exp b/tests/basics/bytes_compare3.py.exp
new file mode 100644
index 0000000000..7b117b9056
--- /dev/null
+++ b/tests/basics/bytes_compare3.py.exp
@@ -0,0 +1,4 @@
+########
+False
+########
+False
diff --git a/tests/basics/bytes_find.py b/tests/basics/bytes_find.py
index 434669a901..75ef9796cd 100644
--- a/tests/basics/bytes_find.py
+++ b/tests/basics/bytes_find.py
@@ -21,3 +21,6 @@ print(b"0000".find(b'-1', 3))
print(b"0000".find(b'1', 3))
print(b"0000".find(b'1', 4))
print(b"0000".find(b'1', 5))
+
+# Non-ascii values (make sure not treated as unicode-like)
+print(b"\x80abc".find(b"a", 1))
diff --git a/tests/basics/bytes_partition.py b/tests/basics/bytes_partition.py
index 3868a81a55..7d3ffaaaaa 100644
--- a/tests/basics/bytes_partition.py
+++ b/tests/basics/bytes_partition.py
@@ -1,3 +1,10 @@
+try:
+ str.partition
+except AttributeError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
print(b"asdf".partition(b'g'))
print(b"asdf".partition(b'a'))
print(b"asdf".partition(b's'))
diff --git a/tests/basics/string_partition.py b/tests/basics/string_partition.py
index fe0070a658..b3b2f0907d 100644
--- a/tests/basics/string_partition.py
+++ b/tests/basics/string_partition.py
@@ -1,3 +1,10 @@
+try:
+ str.partition
+except AttributeError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
print("asdf".partition('g'))
print("asdf".partition('a'))
print("asdf".partition('s'))
diff --git a/tests/basics/string_rpartition.py b/tests/basics/string_rpartition.py
index 656121c94d..84e0031fb0 100644
--- a/tests/basics/string_rpartition.py
+++ b/tests/basics/string_rpartition.py
@@ -1,3 +1,10 @@
+try:
+ str.partition
+except AttributeError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
print("asdf".rpartition('g'))
print("asdf".rpartition('a'))
print("asdf".rpartition('s'))
diff --git a/tests/extmod/btree1.py b/tests/extmod/btree1.py
index 11acd7c98f..c96cce92d6 100644
--- a/tests/extmod/btree1.py
+++ b/tests/extmod/btree1.py
@@ -1,11 +1,15 @@
try:
import btree
+ import uio
except ImportError:
print("SKIP")
import sys
sys.exit()
-db = btree.open(None)
+#f = open("_test.db", "w+b")
+f = uio.BytesIO()
+db = btree.open(f)
+
db[b"foo3"] = b"bar3"
db[b"foo1"] = b"bar1"
db[b"foo2"] = b"bar2"
@@ -57,3 +61,9 @@ print(list(db.values()))
for k in db:
print(k)
+
+print("foo1", "foo1" in db)
+print("foo2", "foo2" in db)
+
+db.close()
+f.close()
diff --git a/tests/extmod/btree1.py.exp b/tests/extmod/btree1.py.exp
index a266d7acfc..2983a09874 100644
--- a/tests/extmod/btree1.py.exp
+++ b/tests/extmod/btree1.py.exp
@@ -30,3 +30,5 @@ KeyError
b'bar1'
b'foo1'
b'foo3'
+foo1 True
+foo2 False
diff --git a/tests/extmod/machine1.py b/tests/extmod/machine1.py
index af4dacd03a..433a180376 100644
--- a/tests/extmod/machine1.py
+++ b/tests/extmod/machine1.py
@@ -1,7 +1,10 @@
# test machine module
try:
- import machine
+ try:
+ import umachine as machine
+ except ImportError:
+ import machine
except ImportError:
print("SKIP")
import sys
diff --git a/tests/extmod/machine_mem.py b/tests/extmod/machine_mem.py
deleted file mode 100644
index 7d8a9ac01e..0000000000
--- a/tests/extmod/machine_mem.py
+++ /dev/null
@@ -1,16 +0,0 @@
-# This test requires root privilege, so is usually skipped
-# It also assumes x86 legacy hardware (with Video BIOS present).
-
-try:
- import machine
-except ImportError:
- print("SKIP")
- import sys
- sys.exit()
-
-try:
- print(hex(machine.mem16[0xc0000]))
-except OSError:
- print("SKIP")
- import sys
- sys.exit()
diff --git a/tests/extmod/machine_mem.py.exp b/tests/extmod/machine_mem.py.exp
deleted file mode 100644
index 371f8fa44d..0000000000
--- a/tests/extmod/machine_mem.py.exp
+++ /dev/null
@@ -1 +0,0 @@
-0xaa55
diff --git a/tests/extmod/machine_pinbase.py b/tests/extmod/machine_pinbase.py
index 07a489a596..5e82823ec0 100644
--- a/tests/extmod/machine_pinbase.py
+++ b/tests/extmod/machine_pinbase.py
@@ -1,10 +1,16 @@
try:
- from umachine import PinBase
+ import umachine as machine
except ImportError:
- from machine import PinBase
+ import machine
+try:
+ machine.PinBase
+except AttributeError:
+ print("SKIP")
+ import sys
+ sys.exit()
-class MyPin(PinBase):
+class MyPin(machine.PinBase):
def __init__(self):
print("__init__")
diff --git a/tests/io/bytesio_ext.py b/tests/io/bytesio_ext.py
new file mode 100644
index 0000000000..30d79fcfcd
--- /dev/null
+++ b/tests/io/bytesio_ext.py
@@ -0,0 +1,19 @@
+# Extended stream operations on io.BytesIO
+try:
+ import uio as io
+except ImportError:
+ import io
+
+a = io.BytesIO()
+print(a.seek(8))
+a.write(b"123")
+print(a.getvalue())
+
+print(a.seek(0, 1))
+
+print(a.seek(-1, 2))
+a.write(b"0")
+print(a.getvalue())
+
+a.flush()
+print(a.getvalue())
diff --git a/tests/io/write_ext.py b/tests/io/write_ext.py
new file mode 100644
index 0000000000..f4ed0d3685
--- /dev/null
+++ b/tests/io/write_ext.py
@@ -0,0 +1,25 @@
+import uio
+
+try:
+ uio.BytesIO
+except AttributeError:
+ import sys
+ print('SKIP')
+ sys.exit()
+
+buf = uio.BytesIO()
+
+buf.write(b"foo", 2)
+print(buf.getvalue())
+
+buf.write(b"foo", 100)
+print(buf.getvalue())
+
+buf.write(b"foobar", 1, 3)
+print(buf.getvalue())
+
+buf.write(b"foobar", 1, 100)
+print(buf.getvalue())
+
+buf.write(b"foobar", 100, 100)
+print(buf.getvalue())
diff --git a/tests/io/write_ext.py.exp b/tests/io/write_ext.py.exp
new file mode 100644
index 0000000000..0f9c6bfbc1
--- /dev/null
+++ b/tests/io/write_ext.py.exp
@@ -0,0 +1,5 @@
+b'fo'
+b'fofoo'
+b'fofoooob'
+b'fofooooboobar'
+b'fofooooboobar'
diff --git a/tests/run-tests b/tests/run-tests
index 02791896b5..32d334a008 100755
--- a/tests/run-tests
+++ b/tests/run-tests
@@ -26,11 +26,35 @@ def rm_f(fname):
if os.path.exists(fname):
os.remove(fname)
+
+# unescape wanted regex chars and escape unwanted ones
+def convert_regex_escapes(line):
+ cs = []
+ escape = False
+ for c in str(line, 'utf8'):
+ if escape:
+ escape = False
+ cs.append(c)
+ elif c == '\\':
+ escape = True
+ elif c in ('(', ')', '[', ']', '{', '}', '.', '*', '+', '^', '$'):
+ cs.append('\\' + c)
+ else:
+ cs.append(c)
+ # accept carriage-return(s) before final newline
+ if cs[-1] == '\n':
+ cs[-1] = '\r*\n'
+ return bytes(''.join(cs), 'utf8')
+
+
def run_micropython(pyb, args, test_file):
+ special_tests = ('micropython/meminfo.py', 'basics/bytes_compare3.py')
+ is_special = False
if pyb is None:
# run on PC
- if test_file.startswith(('cmdline/', 'feature_check/')) or test_file == 'micropython/meminfo.py':
+ if test_file.startswith(('cmdline/', 'feature_check/')) or test_file in special_tests:
# special handling for tests of the unix cmdline program
+ is_special = True
# check for any cmdline options needed for this test
args = [MICROPYTHON]
@@ -80,63 +104,6 @@ def run_micropython(pyb, args, test_file):
except subprocess.CalledProcessError:
return b'CRASH'
- # unescape wanted regex chars and escape unwanted ones
- def convert_regex_escapes(line):
- cs = []
- escape = False
- for c in str(line, 'utf8'):
- if escape:
- escape = False
- cs.append(c)
- elif c == '\\':
- escape = True
- elif c in ('(', ')', '[', ']', '{', '}', '.', '*', '+', '^', '$'):
- cs.append('\\' + c)
- else:
- cs.append(c)
- # accept carriage-return(s) before final newline
- if cs[-1] == '\n':
- cs[-1] = '\r*\n'
- return bytes(''.join(cs), 'utf8')
-
- # convert parts of the output that are not stable across runs
- with open(test_file + '.exp', 'rb') as f:
- lines_exp = []
- for line in f.readlines():
- if line == b'########\n':
- line = (line,)
- else:
- line = (line, re.compile(convert_regex_escapes(line)))
- lines_exp.append(line)
- lines_mupy = [line + b'\n' for line in output_mupy.split(b'\n')]
- if output_mupy.endswith(b'\n'):
- lines_mupy = lines_mupy[:-1] # remove erroneous last empty line
- i_mupy = 0
- for i in range(len(lines_exp)):
- if lines_exp[i][0] == b'########\n':
- # 8x #'s means match 0 or more whole lines
- line_exp = lines_exp[i + 1]
- skip = 0
- while i_mupy + skip < len(lines_mupy) and not line_exp[1].match(lines_mupy[i_mupy + skip]):
- skip += 1
- if i_mupy + skip >= len(lines_mupy):
- lines_mupy[i_mupy] = b'######## FAIL\n'
- break
- del lines_mupy[i_mupy:i_mupy + skip]
- lines_mupy.insert(i_mupy, b'########\n')
- i_mupy += 1
- else:
- # a regex
- if lines_exp[i][1].match(lines_mupy[i_mupy]):
- lines_mupy[i_mupy] = lines_exp[i][0]
- else:
- #print("don't match: %r %s" % (lines_exp[i][1], lines_mupy[i_mupy])) # DEBUG
- pass
- i_mupy += 1
- if i_mupy >= len(lines_mupy):
- break
- output_mupy = b''.join(lines_mupy)
-
else:
# a standard test
try:
@@ -159,6 +126,45 @@ def run_micropython(pyb, args, test_file):
# canonical form for all ports/platforms is to use \n for end-of-line
output_mupy = output_mupy.replace(b'\r\n', b'\n')
+ if is_special or test_file in special_tests:
+ # convert parts of the output that are not stable across runs
+ with open(test_file + '.exp', 'rb') as f:
+ lines_exp = []
+ for line in f.readlines():
+ if line == b'########\n':
+ line = (line,)
+ else:
+ line = (line, re.compile(convert_regex_escapes(line)))
+ lines_exp.append(line)
+ lines_mupy = [line + b'\n' for line in output_mupy.split(b'\n')]
+ if output_mupy.endswith(b'\n'):
+ lines_mupy = lines_mupy[:-1] # remove erroneous last empty line
+ i_mupy = 0
+ for i in range(len(lines_exp)):
+ if lines_exp[i][0] == b'########\n':
+ # 8x #'s means match 0 or more whole lines
+ line_exp = lines_exp[i + 1]
+ skip = 0
+ while i_mupy + skip < len(lines_mupy) and not line_exp[1].match(lines_mupy[i_mupy + skip]):
+ skip += 1
+ if i_mupy + skip >= len(lines_mupy):
+ lines_mupy[i_mupy] = b'######## FAIL\n'
+ break
+ del lines_mupy[i_mupy:i_mupy + skip]
+ lines_mupy.insert(i_mupy, b'########\n')
+ i_mupy += 1
+ else:
+ # a regex
+ if lines_exp[i][1].match(lines_mupy[i_mupy]):
+ lines_mupy[i_mupy] = lines_exp[i][0]
+ else:
+ #print("don't match: %r %s" % (lines_exp[i][1], lines_mupy[i_mupy])) # DEBUG
+ pass
+ i_mupy += 1
+ if i_mupy >= len(lines_mupy):
+ break
+ output_mupy = b''.join(lines_mupy)
+
return output_mupy
def run_tests(pyb, tests, args):
diff --git a/tests/unicode/unicode_subscr.py b/tests/unicode/unicode_subscr.py
new file mode 100644
index 0000000000..a2f434de58
--- /dev/null
+++ b/tests/unicode/unicode_subscr.py
@@ -0,0 +1,23 @@
+a = '¢пр'
+
+print(a[0], a[0:1])
+print(a[1], a[1:2])
+print(a[2], a[2:3])
+try:
+ print(a[3])
+except IndexError:
+ print("IndexError")
+print(a[3:4])
+
+print(a[-1])
+print(a[-2], a[-2:-1])
+print(a[-3], a[-3:-2])
+try:
+ print(a[-4])
+except IndexError:
+ print("IndexError")
+print(a[-4:-3])
+
+print(a[0:2])
+print(a[1:3])
+print(a[2:4])