diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basics/fun_calldblstar3.py | 16 | ||||
-rw-r--r-- | tests/basics/int_big_div.py | 7 | ||||
-rw-r--r-- | tests/basics/int_big_mod.py | 11 | ||||
-rw-r--r-- | tests/basics/memoryview2.py | 13 | ||||
-rw-r--r-- | tests/basics/namedtuple1.py | 5 | ||||
-rw-r--r-- | tests/basics/string_center.py | 14 | ||||
-rw-r--r-- | tests/basics/string_splitlines.py | 29 | ||||
-rw-r--r-- | tests/basics/struct1.py | 6 | ||||
-rw-r--r-- | tests/basics/struct2.py | 28 | ||||
-rw-r--r-- | tests/extmod/vfs_fat_ramdisk.py | 13 | ||||
-rw-r--r-- | tests/extmod/vfs_fat_ramdisk.py.exp | 3 | ||||
-rw-r--r-- | tests/misc/recursive_iternext.py | 15 | ||||
-rw-r--r-- | tests/pyb/can.py | 1 | ||||
-rw-r--r-- | tests/pyb/halerror.py.exp | 2 | ||||
-rw-r--r-- | tests/pyb/rtc.py | 1 | ||||
-rwxr-xr-x | tests/run-tests | 5 |
16 files changed, 159 insertions, 10 deletions
diff --git a/tests/basics/fun_calldblstar3.py b/tests/basics/fun_calldblstar3.py new file mode 100644 index 0000000000..4367e68df7 --- /dev/null +++ b/tests/basics/fun_calldblstar3.py @@ -0,0 +1,16 @@ +# test passing a user-defined mapping as the argument to ** + +def foo(**kw): + print(sorted(kw.items())) + +class Mapping: + def keys(self): + return ['a', 'b', 'c'] + + def __getitem__(self, key): + if key == 'a': + return 1 + else: + return 2 + +foo(**Mapping()) diff --git a/tests/basics/int_big_div.py b/tests/basics/int_big_div.py index 8dacf495db..642f051d41 100644 --- a/tests/basics/int_big_div.py +++ b/tests/basics/int_big_div.py @@ -1,3 +1,10 @@ for lhs in (1000000000000000000000000, 10000000000100000000000000, 10012003400000000000000007, 12349083434598210349871029923874109871234789): for rhs in range(1, 555): print(lhs // rhs) + +# these check an edge case on 64-bit machines where two mpz limbs +# are used and the most significant one has the MSB set +x = 0x8000000000000000 +print((x + 1) // x) +x = 0x86c60128feff5330 +print((x + 1) // x) diff --git a/tests/basics/int_big_mod.py b/tests/basics/int_big_mod.py index 77c0ffc468..e87221c1c7 100644 --- a/tests/basics/int_big_mod.py +++ b/tests/basics/int_big_mod.py @@ -4,7 +4,14 @@ delta = 100000000000000000000000000000012345 for i in range(11): for j in range(11): - x = delta * (i)# - 5) # TODO reinstate negative number test when % is working with sign correctly - y = delta * (j)# - 5) # TODO reinstate negative number test when % is working with sign correctly + x = delta * (i - 5) + y = delta * (j - 5) if y != 0: print(x % y) + +# these check an edge case on 64-bit machines where two mpz limbs +# are used and the most significant one has the MSB set +x = 0x8000000000000000 +print((x + 1) % x) +x = 0x86c60128feff5330 +print((x + 1) % x) diff --git a/tests/basics/memoryview2.py b/tests/basics/memoryview2.py new file mode 100644 index 0000000000..5117d7a680 --- /dev/null +++ b/tests/basics/memoryview2.py @@ -0,0 +1,13 @@ +# test memoryview accessing maximum values for signed/unsigned elements + +from array import array + +print(list(memoryview(b'\x7f\x80\x81\xff'))) +print(list(memoryview(array('b', [0x7f, -0x80])))) +print(list(memoryview(array('B', [0x7f, 0x80, 0x81, 0xff])))) +print(list(memoryview(array('h', [0x7f00, -0x8000])))) +print(list(memoryview(array('H', [0x7f00, 0x8000, 0x8100, 0xffff])))) + +# these constructors give an internal overflow in uPy +#print(list(memoryview(array('i', [0x7f000000, -0x80000000])))) +#print(list(memoryview(array('I', [0x7f000000, 0x80000000, 0x81000000, 0xffffffff])))) diff --git a/tests/basics/namedtuple1.py b/tests/basics/namedtuple1.py index dfbb79f2eb..346e32fbfc 100644 --- a/tests/basics/namedtuple1.py +++ b/tests/basics/namedtuple1.py @@ -66,6 +66,11 @@ T3 = namedtuple("TupComma", "foo bar") t = T3(1, 2) print(t.foo, t.bar) +# Try tuple +T4 = namedtuple("TupTuple", ("foo", "bar")) +t = T4(1, 2) +print(t.foo, t.bar) + # Try single string with comma field seperator # Not implemented so far #T2 = namedtuple("TupComma", "foo,bar") diff --git a/tests/basics/string_center.py b/tests/basics/string_center.py new file mode 100644 index 0000000000..a2739201ac --- /dev/null +++ b/tests/basics/string_center.py @@ -0,0 +1,14 @@ +try: + str.center +except: + import sys + print("SKIP") + sys.exit() + +print("foo".center(0)) +print("foo".center(1)) +print("foo".center(3)) +print("foo".center(4)) +print("foo".center(5)) +print("foo".center(6)) +print("foo".center(20)) diff --git a/tests/basics/string_splitlines.py b/tests/basics/string_splitlines.py index cb4dacef9f..1d08f6e6d7 100644 --- a/tests/basics/string_splitlines.py +++ b/tests/basics/string_splitlines.py @@ -1,3 +1,5 @@ +# test string.splitlines() method + try: str.splitlines except: @@ -5,9 +7,32 @@ except: print("SKIP") sys.exit() +# test \n as newline print("foo\nbar".splitlines()) print("foo\nbar\n".splitlines()) +print("foo and\nbar\n".splitlines()) +print("foo\nbar\n\n".splitlines()) +print("foo\n\nbar\n\n".splitlines()) +print("\nfoo\nbar\n".splitlines()) + +# test \r as newline +print("foo\rbar\r".splitlines()) +print("\rfoo and\r\rbar\r".splitlines()) + +# test \r\n as newline +print("foo\r\nbar\r\n".splitlines()) +print("\r\nfoo and\r\n\r\nbar\r\n".splitlines()) + +# test keepends arg print("foo\nbar".splitlines(True)) print("foo\nbar\n".splitlines(True)) -print("foo\nbar".splitlines(keepends=True)) -print("foo\nbar\n".splitlines(keepends=True)) +print("foo\nbar\n\n".splitlines(True)) +print("foo\rbar".splitlines(keepends=True)) +print("foo\rbar\r\r".splitlines(keepends=True)) +print("foo\r\nbar".splitlines(keepends=True)) +print("foo\r\nbar\r\n\r\n".splitlines(keepends=True)) + +# test splitting bytes objects +print(b"foo\nbar".splitlines()) +print(b"foo\nbar\n".splitlines()) +print(b"foo\r\nbar\r\n\r\n".splitlines(True)) diff --git a/tests/basics/struct1.py b/tests/basics/struct1.py index 1afea5a96f..857e171c10 100644 --- a/tests/basics/struct1.py +++ b/tests/basics/struct1.py @@ -62,6 +62,12 @@ try: except TypeError: print('TypeError') +# make sure that unknown types are detected +try: + struct.pack("z", 1) +except: + print("Unknown type") + # Initially repitition counters were supported only for strings, # but later were implemented for all. print(struct.unpack("<3B2h", b"foo\x12\x34\xff\xff")) diff --git a/tests/basics/struct2.py b/tests/basics/struct2.py new file mode 100644 index 0000000000..f438bb55d2 --- /dev/null +++ b/tests/basics/struct2.py @@ -0,0 +1,28 @@ +# test ustruct with a count specified before the type + +try: + import ustruct as struct +except: + import struct + +print(struct.calcsize('0s')) +print(struct.unpack('0s', b'')) +print(struct.pack('0s', b'123')) + +print(struct.calcsize('2s')) +print(struct.unpack('2s', b'12')) +print(struct.pack('2s', b'123')) + +print(struct.calcsize('2H')) +print(struct.unpack('<2H', b'1234')) +print(struct.pack('<2H', 258, 515)) + +print(struct.calcsize('0s1s0H2H')) +print(struct.unpack('<0s1s0H2H', b'01234')) +print(struct.pack('<0s1s0H2H', b'abc', b'abc', 258, 515)) + +# check that zero of an unknown type raises an exception +try: + struct.calcsize('0z') +except: + print('Exception') diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py index 72eda8b6d0..7860d68124 100644 --- a/tests/extmod/vfs_fat_ramdisk.py +++ b/tests/extmod/vfs_fat_ramdisk.py @@ -45,6 +45,8 @@ assert b"hello!" not in bdev.data vfs = uos.VfsFat(bdev, "/ramdisk") +print("getcwd:", vfs.getcwd()) + f = vfs.open("foo_file.txt", "w") f.write("hello!") f.close() @@ -71,3 +73,14 @@ assert vfs.listdir("foo_dir") == ['file-in-dir.txt'] vfs.rename("foo_dir/file-in-dir.txt", "moved-to-root.txt") assert vfs.listdir() == ['foo_dir', 'moved-to-root.txt'] + +vfs.chdir("foo_dir") +print("getcwd:", vfs.getcwd()) +assert vfs.listdir() == [] + +with vfs.open("sub_file.txt", "w") as f: + f.write("test2") +assert vfs.listdir() == ["sub_file.txt"] + +vfs.chdir("..") +print("getcwd:", vfs.getcwd()) diff --git a/tests/extmod/vfs_fat_ramdisk.py.exp b/tests/extmod/vfs_fat_ramdisk.py.exp index 4effa19f4f..b6079ad3b6 100644 --- a/tests/extmod/vfs_fat_ramdisk.py.exp +++ b/tests/extmod/vfs_fat_ramdisk.py.exp @@ -1 +1,4 @@ +getcwd: /ramdisk hello! +getcwd: /ramdisk/foo_dir +getcwd: /ramdisk diff --git a/tests/misc/recursive_iternext.py b/tests/misc/recursive_iternext.py index 2723d3c10c..376c45b3c7 100644 --- a/tests/misc/recursive_iternext.py +++ b/tests/misc/recursive_iternext.py @@ -1,10 +1,19 @@ # This tests that recursion with iternext doesn't lead to segfault. +# We need to pick an N that is large enough to hit the recursion +# limit, but not too large that we run out of heap memory. try: - [0] * 10000 - N = 1000 + # large stack/heap, eg unix + [0] * 80000 + N = 2000 except: - N = 100 + try: + # medium, eg pyboard + [0] * 10000 + N = 1000 + except: + # small, eg esp8266 + N = 100 try: x = (1, 2) diff --git a/tests/pyb/can.py b/tests/pyb/can.py index cf8089a3bd..594d1d5093 100644 --- a/tests/pyb/can.py +++ b/tests/pyb/can.py @@ -8,6 +8,7 @@ for bus in (-1, 0, 1, 2, 3, "YA", "YB", "YC"): print("CAN", bus) except ValueError: print("ValueError", bus) +CAN(1).deinit() CAN.initfilterbanks(14) can = CAN(1) diff --git a/tests/pyb/halerror.py.exp b/tests/pyb/halerror.py.exp index 09c9f7ad92..0f3f26253d 100644 --- a/tests/pyb/halerror.py.exp +++ b/tests/pyb/halerror.py.exp @@ -1,2 +1,2 @@ OSError(5,) -OSError(116,) +OSError(110,) diff --git a/tests/pyb/rtc.py b/tests/pyb/rtc.py index 09af52629f..300c956342 100644 --- a/tests/pyb/rtc.py +++ b/tests/pyb/rtc.py @@ -2,6 +2,7 @@ import pyb, stm from pyb import RTC rtc = RTC() +rtc.init() print(rtc) # make sure that 1 second passes correctly diff --git a/tests/run-tests b/tests/run-tests index fd4063dc91..649f1789fa 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -351,14 +351,15 @@ def main(): cmd_parser.add_argument('files', nargs='*', help='input test files') args = cmd_parser.parse_args() - if args.target in ('pyboard', 'wipy', 'esp8266'): + EXTERNAL_TARGETS = ('pyboard', 'wipy', 'esp8266') + if args.target in EXTERNAL_TARGETS: import pyboard pyb = pyboard.Pyboard(args.device, args.baudrate, args.user, args.password) pyb.enter_raw_repl() elif args.target == 'unix': pyb = None else: - raise ValueError('target must be either unix, pyboard or wipy') + raise ValueError('target must be either %s or unix' % ", ".join(EXTERNAL_TARGETS)) if len(args.files) == 0: if args.test_dirs is None: |