summaryrefslogtreecommitdiff
path: root/tests/extmod
diff options
context:
space:
mode:
authorBenjamin Shockley <benjaminshockley@hotmail.com>2020-08-20 13:48:15 -0500
committerGitHub <noreply@github.com>2020-08-20 13:48:15 -0500
commit0084f0af24e4e219bc040c52ee723959423de6e2 (patch)
tree1aebdb362f08bf6417caa87836e3e4e739afc964 /tests/extmod
parent9aebe2f1efc99871fcf283c304e3a8700050d736 (diff)
parent4d7b9cde33934a44c4c905a49d2f831339fc8bd2 (diff)
Merge pull request #2 from adafruit/master
Master
Diffstat (limited to 'tests/extmod')
-rw-r--r--tests/extmod/uctypes_array_assign_le.py1
-rw-r--r--tests/extmod/uctypes_byteat.py4
-rw-r--r--tests/extmod/uctypes_error.py10
-rw-r--r--tests/extmod/ujson_dump_iobase.py2
-rw-r--r--tests/extmod/ure1.py13
-rw-r--r--tests/extmod/ure_groups.py33
-rw-r--r--tests/extmod/ure_span.py40
-rw-r--r--tests/extmod/ure_sub.py61
-rw-r--r--tests/extmod/ure_sub_unmatched.py19
-rw-r--r--tests/extmod/ure_sub_unmatched.py.exp1
10 files changed, 175 insertions, 9 deletions
diff --git a/tests/extmod/uctypes_array_assign_le.py b/tests/extmod/uctypes_array_assign_le.py
index 6afa7e0a2..37c52388d 100644
--- a/tests/extmod/uctypes_array_assign_le.py
+++ b/tests/extmod/uctypes_array_assign_le.py
@@ -55,4 +55,3 @@ assert hex(S.arr6[0]) == "0xaabbccdd"
print(S.arr6[0] == S.arr8[0].l)
assert S.arr6[0] == S.arr8[0].l
-
diff --git a/tests/extmod/uctypes_byteat.py b/tests/extmod/uctypes_byteat.py
index ab2535db8..784209f80 100644
--- a/tests/extmod/uctypes_byteat.py
+++ b/tests/extmod/uctypes_byteat.py
@@ -6,5 +6,5 @@ except ImportError:
data = bytearray(b'01234567')
-print(uctypes.bytes_at(uctypes.addressof(data), 4))
-print(uctypes.bytearray_at(uctypes.addressof(data), 4))
+print(uctypes.bytes_at(uctypes.addressof(data), 4))
+print(uctypes.bytearray_at(uctypes.addressof(data), 4))
diff --git a/tests/extmod/uctypes_error.py b/tests/extmod/uctypes_error.py
index 95ba0fad4..2500e2927 100644
--- a/tests/extmod/uctypes_error.py
+++ b/tests/extmod/uctypes_error.py
@@ -9,29 +9,29 @@ except ImportError:
data = bytearray(b"01234567")
# del subscr not supported
-S = uctypes.struct(uctypes.addressof(data), {})
+S = uctypes.struct(uctypes.addressof(data), {})
try:
del S[0]
except TypeError:
print('TypeError')
# list is an invalid descriptor
-S = uctypes.struct(uctypes.addressof(data), [])
+S = uctypes.struct(uctypes.addressof(data), [])
try:
- S.x
+ S.x
except TypeError:
print('TypeError')
# can't access attribute with invalid descriptor
S = uctypes.struct(uctypes.addressof(data), {'x':[]})
try:
- S.x
+ S.x
except TypeError:
print('TypeError')
# can't assign to aggregate
S = uctypes.struct(uctypes.addressof(data), {'x':(uctypes.ARRAY | 0, uctypes.INT8 | 2)})
try:
- S.x = 1
+ S.x = 1
except TypeError:
print('TypeError')
diff --git a/tests/extmod/ujson_dump_iobase.py b/tests/extmod/ujson_dump_iobase.py
index d30d1b561..6280fb11b 100644
--- a/tests/extmod/ujson_dump_iobase.py
+++ b/tests/extmod/ujson_dump_iobase.py
@@ -28,5 +28,5 @@ class S(io.IOBase):
# dump to the user stream
s = S()
-json.dump([123, {}], s)
+json.dump([123, {}], s)
print(s.buf)
diff --git a/tests/extmod/ure1.py b/tests/extmod/ure1.py
index 54471ed4f..710720c8b 100644
--- a/tests/extmod/ure1.py
+++ b/tests/extmod/ure1.py
@@ -28,6 +28,19 @@ try:
except IndexError:
print("IndexError")
+r = re.compile(r"\n")
+m = r.match("\n")
+print(m.group(0))
+m = r.match("\\")
+print(m)
+r = re.compile(r"[\n-\r]")
+m = r.match("\n")
+print(m.group(0))
+r = re.compile(r"[\]]")
+m = r.match("]")
+print(m.group(0))
+print("===")
+
r = re.compile("[a-cu-z]")
m = r.match("a")
print(m.group(0))
diff --git a/tests/extmod/ure_groups.py b/tests/extmod/ure_groups.py
new file mode 100644
index 000000000..4fac896d7
--- /dev/null
+++ b/tests/extmod/ure_groups.py
@@ -0,0 +1,33 @@
+# test match.groups()
+
+try:
+ import ure as re
+except ImportError:
+ try:
+ import re
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+try:
+ m = re.match(".", "a")
+ m.groups
+except AttributeError:
+ print('SKIP')
+ raise SystemExit
+
+
+m = re.match(r'(([0-9]*)([a-z]*)[0-9]*)','1234hello567')
+print(m.groups())
+
+m = re.match(r'([0-9]*)(([a-z]*)([0-9]*))','1234hello567')
+print(m.groups())
+
+# optional group that matches
+print(re.match(r'(a)?b(c)', 'abc').groups())
+
+# optional group that doesn't match
+print(re.match(r'(a)?b(c)', 'bc').groups())
+
+# only a single match
+print(re.match(r'abc', 'abc').groups())
diff --git a/tests/extmod/ure_span.py b/tests/extmod/ure_span.py
new file mode 100644
index 000000000..50f44399c
--- /dev/null
+++ b/tests/extmod/ure_span.py
@@ -0,0 +1,40 @@
+# test match.span(), and nested spans
+
+try:
+ import ure as re
+except ImportError:
+ try:
+ import re
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+try:
+ m = re.match(".", "a")
+ m.span
+except AttributeError:
+ print('SKIP')
+ raise SystemExit
+
+
+def print_spans(match):
+ print('----')
+ try:
+ i = 0
+ while True:
+ print(match.span(i), match.start(i), match.end(i))
+ i += 1
+ except IndexError:
+ pass
+
+m = re.match(r'(([0-9]*)([a-z]*)[0-9]*)','1234hello567')
+print_spans(m)
+
+m = re.match(r'([0-9]*)(([a-z]*)([0-9]*))','1234hello567')
+print_spans(m)
+
+# optional span that matches
+print_spans(re.match(r'(a)?b(c)', 'abc'))
+
+# optional span that doesn't match
+print_spans(re.match(r'(a)?b(c)', 'bc'))
diff --git a/tests/extmod/ure_sub.py b/tests/extmod/ure_sub.py
new file mode 100644
index 000000000..f5a19af8d
--- /dev/null
+++ b/tests/extmod/ure_sub.py
@@ -0,0 +1,61 @@
+try:
+ import ure as re
+except ImportError:
+ try:
+ import re
+ except ImportError:
+ print('SKIP')
+ raise SystemExit
+
+try:
+ re.sub
+except AttributeError:
+ print('SKIP')
+ raise SystemExit
+
+
+def multiply(m):
+ return str(int(m.group(0)) * 2)
+
+print(re.sub("\d+", multiply, "10 20 30 40 50"))
+
+print(re.sub("\d+", lambda m: str(int(m.group(0)) // 2), "10 20 30 40 50"))
+
+def A():
+ return "A"
+print(re.sub('a', A(), 'aBCBABCDabcda.'))
+
+print(
+ re.sub(
+ r'def\s+([a-zA-Z_][a-zA-Z_0-9]*)\s*\(\s*\):',
+ 'static PyObject*\npy_\\1(void){\n return;\n}\n',
+ '\n\ndef myfunc():\n\ndef myfunc1():\n\ndef myfunc2():'
+ )
+)
+
+print(
+ re.compile(
+ '(calzino) (blu|bianco|verde) e (scarpa) (blu|bianco|verde)'
+ ).sub(
+ r'\g<1> colore \2 con \g<3> colore \4? ...',
+ 'calzino blu e scarpa verde'
+ )
+)
+
+# no matches at all
+print(re.sub('a', 'b', 'c'))
+
+# with maximum substitution count specified
+print(re.sub('a', 'b', '1a2a3a', 2))
+
+# invalid group
+try:
+ re.sub('(a)', 'b\\2', 'a')
+except:
+ print('invalid group')
+
+# invalid group with very large number (to test overflow in uPy)
+try:
+ re.sub('(a)', 'b\\199999999999999999999999999999999999999', 'a')
+except:
+ print('invalid group')
diff --git a/tests/extmod/ure_sub_unmatched.py b/tests/extmod/ure_sub_unmatched.py
new file mode 100644
index 000000000..4795b3196
--- /dev/null
+++ b/tests/extmod/ure_sub_unmatched.py
@@ -0,0 +1,19 @@
+# test re.sub with unmatched groups, behaviour changed in CPython 3.5
+
+try:
+ import ure as re
+except ImportError:
+ try:
+ import re
+ except ImportError:
+ print('SKIP')
+ raise SystemExit
+
+try:
+ re.sub
+except AttributeError:
+ print('SKIP')
+ raise SystemExit
+
+# first group matches, second optional group doesn't so is replaced with a blank
+print(re.sub(r'(a)(b)?', r'\2-\1', '1a2'))
diff --git a/tests/extmod/ure_sub_unmatched.py.exp b/tests/extmod/ure_sub_unmatched.py.exp
new file mode 100644
index 000000000..1e5f0fda0
--- /dev/null
+++ b/tests/extmod/ure_sub_unmatched.py.exp
@@ -0,0 +1 @@
+1-a2