summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/class_store_class.py47
-rw-r--r--tests/basics/frozenset1.py14
-rw-r--r--tests/basics/frozenset_add.py12
-rw-r--r--tests/basics/frozenset_binop.py36
-rw-r--r--tests/basics/frozenset_copy.py12
-rw-r--r--tests/basics/frozenset_difference.py21
-rw-r--r--tests/basics/int1.py1
-rw-r--r--tests/basics/list_slice_assign.py36
-rw-r--r--tests/basics/namedtuple1.py2
-rw-r--r--tests/basics/string_partition.py11
-rw-r--r--tests/basics/string_strip.py10
-rw-r--r--tests/basics/string_upperlow.py4
-rw-r--r--tests/basics/subclass-native5.py12
-rw-r--r--tests/basics/subclass_native_cmp.py9
-rw-r--r--tests/basics/subclass_native_specmeth.py18
-rw-r--r--tests/pyb/rtc.py22
-rw-r--r--tests/pyb/rtc.py.exp14
-rwxr-xr-xtests/run-tests18
18 files changed, 296 insertions, 3 deletions
diff --git a/tests/basics/class_store_class.py b/tests/basics/class_store_class.py
new file mode 100644
index 0000000000..60f65220d9
--- /dev/null
+++ b/tests/basics/class_store_class.py
@@ -0,0 +1,47 @@
+# Inspired by urlparse.py from CPython 3.3 stdlib
+# There was a bug in MicroPython that under some conditions class stored
+# in instance attribute later was returned "bound" as if it was a method,
+# which caused class constructor to receive extra argument.
+try:
+ from collections import namedtuple
+except ImportError:
+ from _collections import namedtuple
+
+_DefragResultBase = namedtuple('DefragResult', 'foo bar')
+
+class _ResultMixinStr(object):
+ def encode(self):
+ return self._encoded_counterpart(*(x.encode() for x in self))
+
+class _ResultMixinBytes(object):
+ def decode(self):
+ return self._decoded_counterpart(*(x.decode() for x in self))
+
+class DefragResult(_DefragResultBase, _ResultMixinStr):
+ pass
+
+class DefragResultBytes(_DefragResultBase, _ResultMixinBytes):
+ pass
+
+
+DefragResult._encoded_counterpart = DefragResultBytes
+DefragResultBytes._decoded_counterpart = DefragResult
+
+# Due to differences in type and native subclass printing,
+# the best thing we can do here is to just test that no exceptions
+# happen
+
+#print(DefragResult, DefragResult._encoded_counterpart)
+#print(DefragResultBytes, DefragResultBytes._decoded_counterpart)
+
+o1 = DefragResult("a", "b")
+#print(o1, type(o1))
+o2 = DefragResultBytes("a", "b")
+#print(o2, type(o2))
+
+#print(o1._encoded_counterpart)
+_o1 = o1.encode()
+print(_o1[0], _o1[1])
+#print(_o1, type(_o1))
+
+print("All's ok")
diff --git a/tests/basics/frozenset1.py b/tests/basics/frozenset1.py
new file mode 100644
index 0000000000..02a5bf8c56
--- /dev/null
+++ b/tests/basics/frozenset1.py
@@ -0,0 +1,14 @@
+# basic sets
+
+try:
+ frozenset
+except NameError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
+s = frozenset({1})
+print(s)
+
+s = frozenset({3, 4, 3, 1})
+print(sorted(s))
diff --git a/tests/basics/frozenset_add.py b/tests/basics/frozenset_add.py
new file mode 100644
index 0000000000..50615775bd
--- /dev/null
+++ b/tests/basics/frozenset_add.py
@@ -0,0 +1,12 @@
+try:
+ frozenset
+except NameError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
+s = frozenset({1, 2, 3, 4})
+try:
+ print(s.add(5))
+except AttributeError:
+ print("AttributeError")
diff --git a/tests/basics/frozenset_binop.py b/tests/basics/frozenset_binop.py
new file mode 100644
index 0000000000..5cc07e9e15
--- /dev/null
+++ b/tests/basics/frozenset_binop.py
@@ -0,0 +1,36 @@
+try:
+ frozenset
+except NameError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
+sets = [
+ frozenset(), frozenset({1}), frozenset({1, 2}), frozenset({1, 2, 3}), frozenset({2, 3}),
+ frozenset({2, 3, 5}), frozenset({5}), frozenset({7})
+]
+for s in sets:
+ for t in sets:
+ print(sorted(s), '|', sorted(t), '=', sorted(s | t))
+ print(sorted(s), '^', sorted(t), '=', sorted(s ^ t))
+ print(sorted(s), '&', sorted(t), '=', sorted(s & t))
+ print(sorted(s), '-', sorted(t), '=', sorted(s - t))
+ u = s.copy()
+ u |= t
+ print(sorted(s), "|=", sorted(t), '-->', sorted(u))
+ u = s.copy()
+ u ^= t
+ print(sorted(s), "^=", sorted(t), '-->', sorted(u))
+ u = s.copy()
+ u &= t
+ print(sorted(s), "&=", sorted(t), "-->", sorted(u))
+ u = s.copy()
+ u -= t
+ print(sorted(s), "-=", sorted(t), "-->", sorted(u))
+
+ print(sorted(s), '==', sorted(t), '=', s == t)
+ print(sorted(s), '!=', sorted(t), '=', s != t)
+ print(sorted(s), '>', sorted(t), '=', s > t)
+ print(sorted(s), '>=', sorted(t), '=', s >= t)
+ print(sorted(s), '<', sorted(t), '=', s < t)
+ print(sorted(s), '<=', sorted(t), '=', s <= t)
diff --git a/tests/basics/frozenset_copy.py b/tests/basics/frozenset_copy.py
new file mode 100644
index 0000000000..92e115d346
--- /dev/null
+++ b/tests/basics/frozenset_copy.py
@@ -0,0 +1,12 @@
+try:
+ frozenset
+except NameError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
+s = frozenset({1, 2, 3, 4})
+t = s.copy()
+print(type(t))
+for i in s, t:
+ print(sorted(i))
diff --git a/tests/basics/frozenset_difference.py b/tests/basics/frozenset_difference.py
new file mode 100644
index 0000000000..3d142f9595
--- /dev/null
+++ b/tests/basics/frozenset_difference.py
@@ -0,0 +1,21 @@
+try:
+ frozenset
+except NameError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
+l = [1, 2, 3, 4]
+s = frozenset(l)
+outs = [s.difference(),
+ s.difference(frozenset({1})),
+ s.difference(frozenset({1}), [1, 2]),
+ s.difference(frozenset({1}), {1, 2}, {2, 3})]
+for out in outs:
+ print(type(out), sorted(out))
+
+s = frozenset(l)
+try:
+ print(s.difference_update({1}))
+except AttributeError:
+ print("AttributeError")
diff --git a/tests/basics/int1.py b/tests/basics/int1.py
index 2daef9bf0e..e8a0a04683 100644
--- a/tests/basics/int1.py
+++ b/tests/basics/int1.py
@@ -46,6 +46,7 @@ print(int('0B100', 2))
print(int('0100', 2))
print(int(' \t 0o12', 8))
print(int('0o12 \t ', 8))
+print(int(b"12", 10))
def test(value, base):
diff --git a/tests/basics/list_slice_assign.py b/tests/basics/list_slice_assign.py
new file mode 100644
index 0000000000..baa9a00810
--- /dev/null
+++ b/tests/basics/list_slice_assign.py
@@ -0,0 +1,36 @@
+# test slices; only 2 argument version supported by Micro Python at the moment
+x = list(range(10))
+
+# Assignment
+l = list(x)
+l[1:3] = [10, 20]
+print(l)
+l = list(x)
+l[1:3] = [10]
+print(l)
+l = list(x)
+l[1:3] = []
+print(l)
+l = list(x)
+del l[1:3]
+print(l)
+
+l = list(x)
+l[:3] = [10, 20]
+print(l)
+l = list(x)
+l[:3] = []
+print(l)
+l = list(x)
+del l[:3]
+print(l)
+
+l = list(x)
+l[:-3] = [10, 20]
+print(l)
+l = list(x)
+l[:-3] = []
+print(l)
+l = list(x)
+del l[:-3]
+print(l)
diff --git a/tests/basics/namedtuple1.py b/tests/basics/namedtuple1.py
index 98628cc545..05dd15bd17 100644
--- a/tests/basics/namedtuple1.py
+++ b/tests/basics/namedtuple1.py
@@ -16,6 +16,8 @@ print(bool(t))
print(t + t)
print(t * 3)
+print([f for f in t])
+
print(isinstance(t, tuple))
try:
diff --git a/tests/basics/string_partition.py b/tests/basics/string_partition.py
index ad70d02509..fe0070a658 100644
--- a/tests/basics/string_partition.py
+++ b/tests/basics/string_partition.py
@@ -27,3 +27,14 @@ except ValueError:
print("Raised ValueError")
else:
print("Did not raise ValueError")
+
+# Bytes
+print(b"abba".partition(b'b'))
+try:
+ print(b"abba".partition('b'))
+except TypeError:
+ print("Raised TypeError")
+try:
+ print("abba".partition(b'b'))
+except TypeError:
+ print("Raised TypeError")
diff --git a/tests/basics/string_strip.py b/tests/basics/string_strip.py
index 8e03eff93a..4684c2a248 100644
--- a/tests/basics/string_strip.py
+++ b/tests/basics/string_strip.py
@@ -10,3 +10,13 @@ print('www.example.com'.lstrip('cmowz.'))
print(' spacious '.rstrip())
print('mississippi'.rstrip('ipz'))
+
+print(b'mississippi'.rstrip(b'ipz'))
+try:
+ print(b'mississippi'.rstrip('ipz'))
+except TypeError:
+ print("TypeError")
+try:
+ print('mississippi'.rstrip(b'ipz'))
+except TypeError:
+ print("TypeError")
diff --git a/tests/basics/string_upperlow.py b/tests/basics/string_upperlow.py
new file mode 100644
index 0000000000..950ea24d11
--- /dev/null
+++ b/tests/basics/string_upperlow.py
@@ -0,0 +1,4 @@
+print("".lower())
+print(" t\tn\nr\rv\vf\f".upper())
+print(" T E S T".lower())
+print("*@a1b2cabc_[]/\\".upper())
diff --git a/tests/basics/subclass-native5.py b/tests/basics/subclass-native5.py
new file mode 100644
index 0000000000..6127dae33d
--- /dev/null
+++ b/tests/basics/subclass-native5.py
@@ -0,0 +1,12 @@
+# Subclass from 2 bases explicitly subclasses from object
+
+class Base1(object):
+ pass
+
+class Base2(object):
+ pass
+
+class Sub(Base1, Base2):
+ pass
+
+o = Sub()
diff --git a/tests/basics/subclass_native_cmp.py b/tests/basics/subclass_native_cmp.py
new file mode 100644
index 0000000000..1a095bfa1a
--- /dev/null
+++ b/tests/basics/subclass_native_cmp.py
@@ -0,0 +1,9 @@
+# Test calling non-special method inherited from native type
+
+class mytuple(tuple):
+ pass
+
+t = mytuple((1, 2, 3))
+print(t)
+print(t == (1, 2, 3))
+print((1, 2, 3) == t)
diff --git a/tests/basics/subclass_native_specmeth.py b/tests/basics/subclass_native_specmeth.py
new file mode 100644
index 0000000000..91ffc9624b
--- /dev/null
+++ b/tests/basics/subclass_native_specmeth.py
@@ -0,0 +1,18 @@
+# Test calling non-special method inherited from native type
+
+class mylist(list):
+ pass
+
+l = mylist([1, 2, 3])
+print(l)
+print([e for e in l])
+
+
+class mylist2(list):
+
+ def __iter__(self):
+ return iter([10, 20, 30])
+
+l = mylist2([1, 2, 3])
+print(l)
+print([e for e in l])
diff --git a/tests/pyb/rtc.py b/tests/pyb/rtc.py
index 853aa79577..219d0791af 100644
--- a/tests/pyb/rtc.py
+++ b/tests/pyb/rtc.py
@@ -3,6 +3,28 @@ from pyb import RTC
rtc = RTC()
print(rtc)
+
+# make sure that 1 second passes correctly
rtc.datetime((2014, 1, 1, 1, 0, 0, 0, 0))
pyb.delay(1000)
print(rtc.datetime()[:7])
+
+def set_and_print(datetime):
+ rtc.datetime(datetime)
+ print(rtc.datetime()[:7])
+
+# make sure that setting works correctly
+set_and_print((2000, 1, 1, 1, 0, 0, 0, 0))
+set_and_print((2000, 1, 31, 1, 0, 0, 0, 0))
+set_and_print((2000, 12, 31, 1, 0, 0, 0, 0))
+set_and_print((2016, 12, 31, 1, 0, 0, 0, 0))
+set_and_print((2016, 12, 31, 7, 0, 0, 0, 0))
+set_and_print((2016, 12, 31, 7, 1, 0, 0, 0))
+set_and_print((2016, 12, 31, 7, 12, 0, 0, 0))
+set_and_print((2016, 12, 31, 7, 13, 0, 0, 0))
+set_and_print((2016, 12, 31, 7, 23, 0, 0, 0))
+set_and_print((2016, 12, 31, 7, 23, 1, 0, 0))
+set_and_print((2016, 12, 31, 7, 23, 59, 0, 0))
+set_and_print((2016, 12, 31, 7, 23, 59, 1, 0))
+set_and_print((2016, 12, 31, 7, 23, 59, 59, 0))
+set_and_print((2099, 12, 31, 7, 23, 59, 59, 0))
diff --git a/tests/pyb/rtc.py.exp b/tests/pyb/rtc.py.exp
index d1ea2d9590..43ea70d95e 100644
--- a/tests/pyb/rtc.py.exp
+++ b/tests/pyb/rtc.py.exp
@@ -1,2 +1,16 @@
<RTC>
(2014, 1, 1, 1, 0, 0, 1)
+(2000, 1, 1, 1, 0, 0, 0)
+(2000, 1, 31, 1, 0, 0, 0)
+(2000, 12, 31, 1, 0, 0, 0)
+(2016, 12, 31, 1, 0, 0, 0)
+(2016, 12, 31, 7, 0, 0, 0)
+(2016, 12, 31, 7, 1, 0, 0)
+(2016, 12, 31, 7, 12, 0, 0)
+(2016, 12, 31, 7, 13, 0, 0)
+(2016, 12, 31, 7, 23, 0, 0)
+(2016, 12, 31, 7, 23, 1, 0)
+(2016, 12, 31, 7, 23, 59, 0)
+(2016, 12, 31, 7, 23, 59, 1)
+(2016, 12, 31, 7, 23, 59, 59)
+(2099, 12, 31, 7, 23, 59, 59)
diff --git a/tests/run-tests b/tests/run-tests
index 9e837c3cb2..102655abea 100755
--- a/tests/run-tests
+++ b/tests/run-tests
@@ -25,6 +25,7 @@ def run_tests(pyb, tests):
testcase_count = 0
passed_count = 0
failed_tests = []
+ skipped_tests = []
running_under_travis = os.getenv('TRAVIS') == 'true'
@@ -34,6 +35,7 @@ def run_tests(pyb, tests):
for test_file in tests:
if running_under_travis and test_file in skip_travis_tests:
print("skip ", test_file)
+ skipped_tests.append(test_name)
continue
# get expected output
@@ -42,8 +44,10 @@ def run_tests(pyb, tests):
# expected output given by a file, so read that in
with open(test_file_expected, 'rb') as f:
output_expected = f.read()
+ if os.name == 'nt':
+ output_expected = output_expected.replace(b'\n', b'\r\n')
else:
- # run CPython to work out expeceted output
+ # run CPython to work out expected output
try:
output_expected = subprocess.check_output([CPYTHON3, '-B', test_file])
except subprocess.CalledProcessError:
@@ -64,10 +68,16 @@ def run_tests(pyb, tests):
except pyboard.PyboardError:
output_mupy = b'CRASH'
- testcase_count += len(output_expected.splitlines())
-
test_basename = os.path.basename(test_file)
test_name = os.path.splitext(test_basename)[0]
+
+ if output_mupy == b'SKIP\n':
+ print("skip ", test_file)
+ skipped_tests.append(test_name)
+ continue
+
+ testcase_count += len(output_expected.splitlines())
+
filename_expected = test_basename + ".exp"
filename_mupy = test_basename + ".out"
@@ -89,6 +99,8 @@ def run_tests(pyb, tests):
print("{} tests performed ({} individual testcases)".format(test_count, testcase_count))
print("{} tests passed".format(passed_count))
+ if len(skipped_tests) > 0:
+ print("{} tests skipped: {}".format(len(skipped_tests), ' '.join(skipped_tests)))
if len(failed_tests) > 0:
print("{} tests failed: {}".format(len(failed_tests), ' '.join(failed_tests)))
return False