diff options
| author | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-07-03 15:05:08 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott@chickadee.tech> | 2017-08-11 17:16:13 -0700 |
| commit | fab634e3eeb456e9d5dffa2cabb9ded39c45d6b6 (patch) | |
| tree | 4f1926142546130d7bd0388303ebe0cd2ab1181c /tests | |
| parent | f6a702538a0b3dd72879d65e3acc32520d4371f5 (diff) | |
Turn on Rosie CI testing to test new builds on real hardware.
This introduces a skip_if module that can be used by tests to
determine when they should be skipped due to the environment.
Some tests have been split in order to have finer grained skip
control.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/basics/array_intbig.py | 2 | ||||
| -rw-r--r-- | tests/basics/builtin_reversed.py | 8 | ||||
| -rw-r--r-- | tests/basics/bytearray_intbig.py | 11 | ||||
| -rw-r--r-- | tests/basics/class_store_class.py | 3 | ||||
| -rw-r--r-- | tests/basics/dict_fromkeys2.py | 7 | ||||
| -rw-r--r-- | tests/basics/dict_fromkeys_reversed.py | 7 | ||||
| -rw-r--r-- | tests/basics/int_big_zeroone.py | 11 | ||||
| -rw-r--r-- | tests/basics/int_bytes.py | 3 | ||||
| -rw-r--r-- | tests/basics/int_bytes_intbig.py | 3 | ||||
| -rw-r--r-- | tests/basics/int_longint_bytes.py | 15 | ||||
| -rw-r--r-- | tests/basics/memoryview1.py | 48 | ||||
| -rw-r--r-- | tests/basics/memoryview1_slice_assign.py | 58 | ||||
| -rw-r--r-- | tests/basics/namedtuple1.py | 5 | ||||
| -rw-r--r-- | tests/basics/namedtuple1_cpython_compat.py | 20 | ||||
| -rw-r--r-- | tests/basics/print.py | 1 | ||||
| -rw-r--r-- | tests/basics/self_type_check.py | 2 | ||||
| -rw-r--r-- | tests/circuitpython/blinky.py | 2 | ||||
| -rwxr-xr-x | tests/run-tests | 32 | ||||
| -rw-r--r-- | tests/skip_if.py | 80 |
19 files changed, 242 insertions, 76 deletions
diff --git a/tests/basics/array_intbig.py b/tests/basics/array_intbig.py index 5702a8ae6..ef3b56793 100644 --- a/tests/basics/array_intbig.py +++ b/tests/basics/array_intbig.py @@ -1,4 +1,6 @@ # test array types QqLl that require big-ints +import skip_if +skip_if.no_bigint() try: from array import array diff --git a/tests/basics/builtin_reversed.py b/tests/basics/builtin_reversed.py index f43505a8b..6f07beaad 100644 --- a/tests/basics/builtin_reversed.py +++ b/tests/basics/builtin_reversed.py @@ -1,9 +1,5 @@ -# test the builtin reverse() function -try: - reversed -except: - print("SKIP") - raise SystemExit +import skip_if +skip_if.no_reversed() # list print(list(reversed([]))) diff --git a/tests/basics/bytearray_intbig.py b/tests/basics/bytearray_intbig.py index 334eabe12..77bcf2225 100644 --- a/tests/basics/bytearray_intbig.py +++ b/tests/basics/bytearray_intbig.py @@ -1 +1,12 @@ +# Skip if long ints are not supported. +try: + # We have to use variables because 1 << 40 causes an exception on parse and + # cannot be caught. + x = 40 + x = 1 << x +except OverflowError: + print("SKIP") + import sys + sys.exit(1) + print(bytearray(2**65 - (2**65 - 1))) diff --git a/tests/basics/class_store_class.py b/tests/basics/class_store_class.py index 797f88f85..8f3e542d1 100644 --- a/tests/basics/class_store_class.py +++ b/tests/basics/class_store_class.py @@ -11,6 +11,9 @@ except ImportError: print("SKIP") raise SystemExit +import skip_if +skip_if.no_cpython_compat() + _DefragResultBase = namedtuple('DefragResult', [ 'foo', 'bar' ]) class _ResultMixinStr(object): diff --git a/tests/basics/dict_fromkeys2.py b/tests/basics/dict_fromkeys2.py index dce1e8ef5..a5371bc53 100644 --- a/tests/basics/dict_fromkeys2.py +++ b/tests/basics/dict_fromkeys2.py @@ -1,8 +1,5 @@ -try: - reversed -except: - print("SKIP") - raise SystemExit +import skip_if +skip_if.no_reversed() # argument to fromkeys has no __len__ d = dict.fromkeys(reversed(range(1))) diff --git a/tests/basics/dict_fromkeys_reversed.py b/tests/basics/dict_fromkeys_reversed.py new file mode 100644 index 000000000..34b0ed129 --- /dev/null +++ b/tests/basics/dict_fromkeys_reversed.py @@ -0,0 +1,7 @@ +# Skip this test if reversed() isn't built in. +import skip_if +skip_if.no_reversed() + +# argument to fromkeys has no __len__ +d = dict.fromkeys(reversed(range(1))) +print(d) diff --git a/tests/basics/int_big_zeroone.py b/tests/basics/int_big_zeroone.py index 7e0b7a720..131d96c76 100644 --- a/tests/basics/int_big_zeroone.py +++ b/tests/basics/int_big_zeroone.py @@ -1,5 +1,16 @@ # test [0,-0,1,-1] edge cases of bignum +# Skip if long ints are not supported. +try: + # We have to use variables because 1 << 40 causes an exception on parse and + # cannot be caught. + x = 40 + x = 1 << x +except OverflowError: + print("SKIP") + import sys + sys.exit(1) + long_zero = (2**64) >> 65 long_neg_zero = -long_zero long_one = long_zero + 1 diff --git a/tests/basics/int_bytes.py b/tests/basics/int_bytes.py index 93c00bba1..a96a4e65f 100644 --- a/tests/basics/int_bytes.py +++ b/tests/basics/int_bytes.py @@ -1,9 +1,6 @@ print((10).to_bytes(1, "little")) print((111111).to_bytes(4, "little")) print((100).to_bytes(10, "little")) -print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) -print(int.from_bytes(b"\x01\0\0\0\0\0\0\0", "little")) -print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) # check that extra zero bytes don't change the internal int value print(int.from_bytes(bytes(20), "little") == 0) diff --git a/tests/basics/int_bytes_intbig.py b/tests/basics/int_bytes_intbig.py index 0e0ad1cbb..7c8a7f4af 100644 --- a/tests/basics/int_bytes_intbig.py +++ b/tests/basics/int_bytes_intbig.py @@ -1,3 +1,6 @@ +import skip_if +skip_if.no_bigint() + print((2**64).to_bytes(9, "little")) b = bytes(range(20)) diff --git a/tests/basics/int_longint_bytes.py b/tests/basics/int_longint_bytes.py new file mode 100644 index 000000000..31510d75a --- /dev/null +++ b/tests/basics/int_longint_bytes.py @@ -0,0 +1,15 @@ +# Skip if long ints are not supported. +try: + # We have to use variables because 1 << 40 causes an exception on parse and + # cannot be caught. + x = 40 + x = 1 << x +except OverflowError: + print("SKIP") + import sys + sys.exit(1) + +print((2**64).to_bytes(9, "little")) +print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) +print(int.from_bytes(b"\x01\0\0\0\0\0\0\0", "little")) +print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) diff --git a/tests/basics/memoryview1.py b/tests/basics/memoryview1.py index c4cc6ffab..3e5c86768 100644 --- a/tests/basics/memoryview1.py +++ b/tests/basics/memoryview1.py @@ -46,51 +46,3 @@ print(list(m)) print(list(m[1:-1])) m[2] = 6 print(a) - -# test slice assignment between memoryviews -b1 = bytearray(b'1234') -b2 = bytearray(b'5678') -b3 = bytearray(b'5678') -m1 = memoryview(b1) -m2 = memoryview(b2) -m3 = memoryview(b3) -m2[1:3] = m1[0:2] -print(b2) -b3[1:3] = m1[0:2] -print(b3) -m1[2:4] = b3[1:3] -print(b1) - -try: - m2[1:3] = b1[0:4] -except ValueError: - print("ValueError") - -try: - m2[1:3] = m1[0:4] -except ValueError: - print("ValueError") - -try: - m2[0:4] = m1[1:3] -except ValueError: - print("ValueError") - -# test memoryview of arrays with items sized larger than 1 -a1 = array.array('i', [0]*5) -m4 = memoryview(a1) -a2 = array.array('i', [3]*5) -m5 = memoryview(a2) -m4[1:3] = m5[1:3] -print(a1) - -try: - m4[1:3] = m2[1:3] -except ValueError: - print("ValueError") - -# invalid assignment on RHS -try: - memoryview(array.array('i'))[0:2] = b'1234' -except ValueError: - print('ValueError') diff --git a/tests/basics/memoryview1_slice_assign.py b/tests/basics/memoryview1_slice_assign.py new file mode 100644 index 000000000..f272fd392 --- /dev/null +++ b/tests/basics/memoryview1_slice_assign.py @@ -0,0 +1,58 @@ +import skip_if + +try: + memoryview +except: + skip_if.skip() + +skip_if.no_slice_assign() + +# test slice assignment between memoryviews +b1 = bytearray(b'1234') +b2 = bytearray(b'5678') +b3 = bytearray(b'5678') +m1 = memoryview(b1) +m2 = memoryview(b2) +m3 = memoryview(b3) +m2[1:3] = m1[0:2] +print(b2) +b3[1:3] = m1[0:2] +print(b3) +m1[2:4] = b3[1:3] +print(b1) + +try: + m2[1:3] = b1[0:4] +except ValueError: + print("ValueError") + +try: + m2[1:3] = m1[0:4] +except ValueError: + print("ValueError") + +try: + m2[0:4] = m1[1:3] +except ValueError: + print("ValueError") + +import array + +# test memoryview of arrays with items sized larger than 1 +a1 = array.array('i', [0]*5) +m4 = memoryview(a1) +a2 = array.array('i', [3]*5) +m5 = memoryview(a2) +m4[1:3] = m5[1:3] +print(a1) + +try: + m4[1:3] = m2[1:3] +except ValueError: + print("ValueError") + +# invalid assignment on RHS +try: + memoryview(array.array('i'))[0:2] = b'1234' +except ValueError: + print('ValueError') diff --git a/tests/basics/namedtuple1.py b/tests/basics/namedtuple1.py index b9a007240..56c29ddda 100644 --- a/tests/basics/namedtuple1.py +++ b/tests/basics/namedtuple1.py @@ -65,11 +65,6 @@ try: except TypeError: print("TypeError") -# Try single string -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) diff --git a/tests/basics/namedtuple1_cpython_compat.py b/tests/basics/namedtuple1_cpython_compat.py new file mode 100644 index 000000000..a1b852d90 --- /dev/null +++ b/tests/basics/namedtuple1_cpython_compat.py @@ -0,0 +1,20 @@ +import skip_if +skip_if.no_cpython_compat() + +try: + try: + from collections import namedtuple + except ImportError: + from ucollections import namedtuple +except ImportError: + skip_if.skip() + +# Try single string +T3 = namedtuple("TupComma", "foo bar") +t = T3(1, 2) +print(t.foo, t.bar) + +# Try single string with comma field separator +# Not implemented so far +#T2 = namedtuple("TupComma", "foo,bar") +#t = T2(1, 2) diff --git a/tests/basics/print.py b/tests/basics/print.py index 880aaf44f..8b53e32c9 100644 --- a/tests/basics/print.py +++ b/tests/basics/print.py @@ -1,5 +1,6 @@ # test builtin print function +print("break the test") print() print(None) print('') diff --git a/tests/basics/self_type_check.py b/tests/basics/self_type_check.py index 947e362cd..206678e25 100644 --- a/tests/basics/self_type_check.py +++ b/tests/basics/self_type_check.py @@ -1,4 +1,6 @@ # make sure type of first arg (self) to a builtin method is checked +import skip_if +skip_if.board_in("gemma_m0", "trinket_m0") list.append diff --git a/tests/circuitpython/blinky.py b/tests/circuitpython/blinky.py new file mode 100644 index 000000000..a9412b07c --- /dev/null +++ b/tests/circuitpython/blinky.py @@ -0,0 +1,2 @@ +import digitalio +import board diff --git a/tests/run-tests b/tests/run-tests index f24fc0961..a45477dea 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -123,9 +123,13 @@ def run_micropython(pyb, args, test_file, is_special=False): cmdlist.append(test_file) # run the actual test - try: - output_mupy = subprocess.check_output(cmdlist) - except subprocess.CalledProcessError: + e = {"MICROPYPATH": os.getcwd() + ":", "LANG": "en_US.UTF-8"} + p = subprocess.Popen(cmdlist, env=e, stdout=subprocess.PIPE) + output_mupy = b'' + while p.poll() is None: + output_mupy += p.stdout.read() + output_mupy += p.stdout.read() + if p.returncode != 0: output_mupy = b'CRASH' # clean up if we had an intermediate .mpy file @@ -368,13 +372,19 @@ def run_tests(pyb, tests, args, base_path="."): output_expected = f.read() else: # run CPython to work out expected output - try: - output_expected = subprocess.check_output([CPYTHON3, '-B', test_file]) - if args.write_exp: - with open(test_file_expected, 'wb') as f: - f.write(output_expected) - except subprocess.CalledProcessError: + e = {"PYTHONPATH": os.getcwd(), + "PATH": os.environ["PATH"], + "LANG": "en_US.UTF-8"} + p = subprocess.Popen([CPYTHON3, '-B', test_file], env=e, stdout=subprocess.PIPE) + output_expected = b'' + while p.poll() is None: + output_expected += p.stdout.read() + output_expected += p.stdout.read() + if p.returncode != 0: output_expected = b'CPYTHON3 CRASH' + elif args.write_exp: + with open(test_file_expected, 'wb') as f: + f.write(output_expected) # canonical form for all host platforms is to use \n for end-of-line output_expected = output_expected.replace(b'\r\n', b'\n') @@ -405,6 +415,10 @@ def run_tests(pyb, tests, args, base_path="."): f.write(output_expected) with open(filename_mupy, "wb") as f: f.write(output_mupy) + print("### Expected") + print(output_expected) + print("### Actual") + print(output_mupy) print("FAIL ", test_file) failed_tests.append(test_name) diff --git a/tests/skip_if.py b/tests/skip_if.py new file mode 100644 index 000000000..f6d22b4c1 --- /dev/null +++ b/tests/skip_if.py @@ -0,0 +1,80 @@ +# The MIT License (MIT) +# +# Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# This must be on one line so its skipped when built into tests. +"""This file provides helpers to detect particular running conditions and skip the test when appropriate.""" + +def skip(): + print("SKIP") + raise SystemExit + +def no_reversed(): + import builtins + if "reversed" not in dir(builtins): + skip() + +def no_bigint(): + try: + # We have to use variables because 1 << 40 causes an exception on parse and + # cannot be caught. + x = 40 + x = 1 << x + except OverflowError: + skip() + +def board_in(*board): + try: + import test_env + except ImportError: + class Env: + def __init__(self, board): + self.board = board + test_env = Env("unknown") + if test_env.board in board: + skip() + +def no_cpython_compat(): + try: + try: + from collections import namedtuple + except ImportError: + from ucollections import namedtuple + except ImportError: + skip() + try: + T3 = namedtuple("TupComma", "foo bar") + except TypeError: + skip() + +def no_slice_assign(): + try: + memoryview + except: + skip() + b1 = bytearray(b'1234') + b2 = bytearray(b'5678') + m1 = memoryview(b1) + m2 = memoryview(b2) + try: + m2[1:3] = m1[0:2] + except TypeError: + skip() |
