diff options
| author | Damien George <damien.p.george@gmail.com> | 2017-08-30 11:04:47 +1000 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2017-08-30 11:04:47 +1000 |
| commit | c7d334e047ce5a36bd6d4979a5331719dd480a2b (patch) | |
| tree | 3dbb206e3075eb5f1778389f1399c28d3fd88d34 /tests | |
| parent | 25e24b2c3c63e035b4c145f743f5cd7b02a23fc0 (diff) | |
| parent | 1f78e7a43130acfa4bedf16c1007a1b0f37c75c3 (diff) | |
Merge tag 'v1.9.2' into parse-bytecode
Double precision math library and support on pyboard, and improved ussl
This release brings general improvements and bug fixes to the core and
various ports, as well as documentation additions, clean-ups and better
consistency. And effort has been made to clean up the source code to
make it more consistent across the core and all ports.
There is a new tool "mpy_bin2res.py" to convert arbitrary (binary) files
to Python resources for inclusion in source code (frozen or otherwise).
The ussl module has seen improvements, including implementation of
server_hostname (for axtls) and server_side mode (for mbedtls).
There is now a double-precision float math library and stmhal has support
to build firmware with software or hardware double-precision.
A detailed list of changes follows.
py core:
- formatfloat: fix number of digits and exponent sign when rounding
- modthread: raise RuntimeError in release() if lock is not acquired
- compile: raise SyntaxError if positional args are given after */**
- objint: support "big" byte-order in int.to_bytes()
- objint: in to_bytes(), allow length arg to be any int and check sign
- compile: fix bug with break/continue in else of optimised for-range
- compile: optimise emitter label indices to save a word of heap
- builtinimport: remove unreachable code for relative imports
- objnamedtuple: simplify and remove use of alloca building namedtuple
- mpprint: remove unreachable check for neg return of mp_format_float
- binary: add missing "break" statements
- runtime: mark m_malloc_fail() as NORETURN
- objstr: remove unnecessary "sign" variable in formatting code
- vm: make "if" control flow more obvious in YIELD_FROM opcode
- modmath: check for zero division in log with 2 args
- makeversionhdr.py: update to parse new release line in docs/conf.py
- objdict: factorise dict accessor helper to reduce code size
- change mp_uint_t to size_t in builtins code
- repl: change mp_uint_t to size_t in repl helpers
- compile: combine arith and bit-shift ops into 1 compile routine
- compile: use switch-case to match token and operator
- objgenerator: allow to hash generators and generator instances
- gc: refactor assertions in gc_free function
- vm: make n_state variable local to just set-up part of VM
- asmx64: support moving a 64-bit immediate to one of top 8 registers
- modmicropython: cast stack_limit value so it prints correctly
- builtinevex: add typechecking of globals/locals args to eval/exec
- py.mk: make berkeley-db C-defs apply only to relevant source files
- mperrno: allow mperrno.h to be correctly included before other hdrs
- mpz: make mpz_is_zero() an inline function
- implement raising a big-int to a negative power
- mkrules.mk: show frozen modules sizes together with executable size
- objtuple: allow to use inplace-multiplication operator on tuples
- objstr: raise an exception for wrong type on RHS of str binary op
- modsys: initial implementation of sys.getsizeof()
- binary.c: fix bug when packing big-endian 'Q' values
- add verbose debug compile-time flag MICROPY_DEBUG_VERBOSE
- binary: change internal bytearray typecode from 0 to 1
- objstringio: prevent offset wraparound for io.BytesIO objects
- objstringio: fix regression with handling SEEK_SET
- stream: seek: Consistently handle negative offset for SEEK_SET
- mkrules.mk: use "find -path" when searching for frozen obj files
- compile: remove unused pn_colon code when compiling func params
- objcomplex: remove unnecessary assignment of variable
- formatfloat: don't post-increment variable that won't be used again
- use "static inline" for funcs that should be inline
- asmthumb: use existing macro to properly clear the D-cache
extmod:
- modussl_axtls: update for axTLS 2.1.3
- modussl_axtls: implement server_hostname arg to wrap_socket()
- move modonewire.c from esp8266 to extmod directory
- modure: if input string is bytes, return bytes results too
- modubinascii: add check for empty buffer passed to hexlify
- modussl_axtls: allow to close ssl stream multiple times
- modussl_mbedtls: support server_side mode
- modussl_mbedtls: when reading and peer wants to close, return 0
- modframebuf: fix invalid stride for odd widths in GS4_HMSB fmt
- modussl_mbedtls: make socket.close() free all TLS resources
- modframebuf: consistently use "col" as name for colour variables
- modussl_mbedtls: implement non-blocking SSL sockets
- machine_signal: fix parsing of invert arg when Pin is first arg
- modframebuf: use correct initialization for .locals_dict
- modlwip: implement setsockopt(IP_ADD_MEMBERSHIP)
- modussl_mbedtls.c: add ussl.getpeercert() method
- modubinascii: rewrite mod_binascii_a2b_base64
- modubinascii: don't post-increment variable that won't be used
- modonewire: rename public module to mp_module_onewire
- for uos.stat interpret st_size member as an unsigned int
- use "static inline" for funcs that should be inline
lib:
- axtls: upgrade to axTLS 2.1.3 + MicroPython patchset
- libm/math: remove implementations of float conversion functions
- add libm_dbl, a double-precision math library, from musl-1.1.16
drivers:
- onewire: move onewire.py, ds18x20.py from esp8266 to drivers
- onewire: enable pull-up when init'ing the 1-wire pin
tools:
- gen-cpydiff: use case description as 3rd-level heading
- pyboard: add license header
- mpy_bin2res: tools to convert binary resources to Python module
- mpy-tool.py: don't generate const_table if it's empty
- mpy-tool.py: fix missing argument in dump() function
tests:
- net_inet/test_tls_sites.py: integration test for SSL connections
- net_inet: add tests for accept and connect in nonblocking mode
- basics: add tests for for-else statement
- net_inet: move tests which don't require full Internet to net_hosted
- connect_nonblock: refactor towards real net_hosted test
- auto detect floating point capabilites of the target
- import: add a test for the builtin __import__ function
- import: update comment now that uPy raises correct exception
- basics/namedtuple1: add test for creating with pos and kw args
- unix/extra_coverage: add test for mp_vprintf with bad fmt spec
- basics: add tests for arithmetic operators precedence
- cpydiff/modules_deque: elaborate workaround
- cpydiff/core_class_mro: move under Classes, add workaround
- cpydiff/core_arguments: move under Functions subsection
- cpydiff/core_class_supermultiple: same cause as core_class_mro
- cpydiff: improve wording, add more workarounds
- cpydiff: add case for str.ljust/rjust
- rename exec1.py to builtin_exec.py
- basics/builtin_exec: test various globals/locals args to exec()
minimal port:
- Makefile: enable gc-sections to remove unused code
- remove unused stmhal include from Makefile
- use size_t for mp_builtin_open argument
unix port:
- modtime: replace strftime() with localtime()
- mpconfigport.mk: update descriptions of readline and TLS options
- Makefile: disable assertions in the standard unix executable
- modjni: convert to mp_rom_map_elem_t
- for uos.stat interpret st_size member as an unsigned int
stmhal port:
- mpconfigport.h: remove config of PY_THREAD_GIL to use default
- make error messages more consistent across peripherals
- add initial implementation of Pin.irq() method
- add .value() method to Switch object, to mirror Pin and Signal
- move pybstdio.c to lib/utils/sys_stdio_mphal.c for common use
- add "quiet timing" enter/exit functions
- make available the _onewire module, for low-level bus control
- modules: provide sym-link to onewire.py driver
- boards/stm32f405.ld: increase FLASH_TEXT to end of 1MiB flash
- sdcard: allow a board to customise the SDIO pins
- add possibility to build with double-precision floating point
- boards: enable double-prec FP on F76x boards
- Makefile: use hardware double-prec FP for MCUs that support it
- Makefile: rename FLOAT_IMPL to MICROPY_FLOAT_IMPL to match C name
- Makefile: add CFLAGS_EXTRA to CFLAGS so cmdline can add options
- mpconfigport.h: allow MICROPY_PY_THREAD to be overridden
- boards: add configuration files for NUCLEO_F429ZI
- boards/NUCLEO_F429ZI: change USB config from HS to FS peripheral
- reduce size of ESPRUINO_PICO build so it fits in flash
- servo: make pyb.Servo(n) map to Pin('Xn') on all MCUs
- servo: don't compile servo code when it's not enabled
- use "static inline" for funcs that should be inline
cc3200 port:
- modusocket: simplify socket.makefile() function
- make non-zero socket timeout work with connect/accept/send
- modusocket: fix connect() when in non-blocking or timeout mode
- use the name MicroPython consistently in code
esp8266 port:
- Makefile: bump axTLS TLS record buffer size to 5K
- Makefile: allow FROZEN_DIR,FROZEN_MPY_DIR to be overridden
- Makefile: add LIB_SRC_C variable to qstr auto-extraction list
- make onewire module and support code usable by other ports
- modonewire: move low-level 1-wire bus code to modonewire.c
- modonewire: make timings static and remove onewire.timings func
- reinstate 1-wire scripts by sym-linking to drivers/onewire/
- move mp_hal_pin_open_drain from esp_mphal.c to machine_pin.c
- enable MICROPY_ENABLE_FINALISER
- README: make "Documentation" a top-level section
- machine_rtc: use correct arithmetic for aligning RTC mem len
- mpconfigport_512k: use terse error messages to get 512k to fit
- mpconfigport.h: make socket a weak link
- modesp: remove unused constants: STA_MODE, etc
- general: add known issue of WiFi RX buffers overflow
- use size_t for mp_builtin_open argument
- fix UART stop bit constants
zephyr port:
- Makefile: rework dependencies and "clean" target
- Makefile: revert prj.conf construction rule to the previous state
- remove long-obsolete machine_ptr_t typedef's
- Makefile: explicitly define default target as "all"
- modusocket: allow to use socketized net_context in upstream
- modusocket: socket, close: switch to native Zephyr socket calls
- modusocket: bind, connect, listen, accept: Swtich to native sockets
- modusocket: send: switch to native sockets
- modusocket: recv: switch to native sockets
- modusocket: fully switch to native Zephyr sockets
- modzephyr: add current_tid() and stacks_analyze() functions
- prj_base.conf: enable CONFIG_INIT_STACKS
- modusocket: update struct sockaddr family field name
- prj_96b_carbon.conf: re-enable networking on Carbon
- modzephyr: add shell_net_iface() function
docs:
- btree: add hints about opening db file and need to flush db
- select: rename to uselect, to match the actual module name
- license: update copyright year
- esp8266/tutorial/intro: discourage use of 512kb firmwares
- esp8266/tutorial/intro: Sphinx requires blank lines around literal blocks
- conf.py: include 3 levels of ToC in latexpdf output
- gc: mark mem_alloc()/mem_free() as uPy-specific
- gc: document gc.threshold() function
- builtins: list builtin exceptions
- conf.py: set default_role = 'any'
- lcd160cr: group related constants together and use full sentences
- ref/speed_python: update and make more hardware-neutral
- library/gc: fix grammar and improve readability of gc.threshold()
- move all ports docs to the single ToC
- topindex.html: remove link to wipy.io, it's no longer available
- conf.py: add .venv dir to exclude_patterns
- move topindex.html to templates/ subdir
- differences/index_template: use consistent heading casing
- builtins: add AssertionError, SyntaxError, ZeroDivisionError
- add glossary
- conf.py: switch to "new" format of intersphinx_mapping
- conf.py: add file for global replacements definition
- library: add CPython docs xref to each pertinent module
- replace.inc: add |see_cpython|, to xref individual symbols from CPython
- conf.py: set "version" and "release" to the same value
- *_index: drop "Indices and tables" pseudo-section
- pyboard: move hardware info into General Info chapter
- uerrno: document "uerrno" module
- esp8266/general.rst: fix name of NTP module
- pyboard: move info about using Windows from topindex to general
- uzlib: update description of decompress() and mention DecompIO
- pyboard/tutorial/amp_skin: add example for playing large WAV files
- library/ubinascii: update base64 docs
- library/usocket: move socket.error to its own section
- library/usocket: describe complete information on address formats
- glossary: elaborate on possible MicroPython port differences
- glossary: fix typos in micropython-lib paragraph
- index: rewrite introduction paragraph to avoid confusion
- use the name MicroPython consistently in documentation
- consistently link to micropython-lib in glossary
all:
- make more use of mp_raise_{msg,TypeError,ValueError} helpers
- unify header guard usage
- remove trailing spaces, per coding conventions
- don't include system errno.h when it's not needed
- use the name MicroPython consistently in comments
- make use of $(TOP) variable in Makefiles, instead of ".."
- raise exceptions via mp_raise_XXX
- make static dicts use mp_rom_map_elem_t type and MP_ROM_xxx macros
README:
- mention support for bytecode and frozen bytecode
- improve description of precompiled bytecode; mention mpy-cross
CODECONVENTIONS:
- clarify MicroPython changes sign-off process
- start to describe docs conventions
- describe docs use of markup for None/True/False
travis:
- build STM32F769DISC board instead of F7DISC to test dbl-prec FP
- pin cpp-coveralls at 0.3.12
Diffstat (limited to 'tests')
69 files changed, 508 insertions, 72 deletions
diff --git a/tests/README b/tests/README index b028cd062..3458f36a8 100644 --- a/tests/README +++ b/tests/README @@ -13,6 +13,6 @@ condition a test. The run-tests script uses small scripts in the feature_check directory to check whether each such feature is present, and skips the relevant tests if not. -When creating new tests, anything that relies on float support should go in the +When creating new tests, anything that relies on float support should go in the float/ subdirectory. Anything that relies on import x, where x is not a built-in module, should go in the import/ subdirectory. diff --git a/tests/basics/builtin_exec.py b/tests/basics/builtin_exec.py new file mode 100644 index 000000000..fd4e65c53 --- /dev/null +++ b/tests/basics/builtin_exec.py @@ -0,0 +1,32 @@ +print(exec("def foo(): return 42")) +print(foo()) + +d = {} +exec("def bar(): return 84", d) +print(d["bar"]()) + +# passing None/dict as args to globals/locals +foo = 11 +exec('print(foo)') +exec('print(foo)', None) +exec('print(foo)', {'foo':3}, None) +exec('print(foo)', None, {'foo':3}) +exec('print(foo)', None, {'bar':3}) +exec('print(foo)', {'bar':3}, locals()) + +try: + exec('print(foo)', {'bar':3}, None) +except NameError: + print('NameError') + +# invalid arg passed to globals +try: + exec('print(1)', 'foo') +except TypeError: + print('TypeError') + +# invalid arg passed to locals +try: + exec('print(1)', None, 123) +except TypeError: + print('TypeError') diff --git a/tests/basics/builtin_hash_gen.py b/tests/basics/builtin_hash_gen.py new file mode 100644 index 000000000..d42e5ebfb --- /dev/null +++ b/tests/basics/builtin_hash_gen.py @@ -0,0 +1,7 @@ +# test builtin hash function, on generators + +def gen(): + yield + +print(type(hash(gen))) +print(type(hash(gen()))) diff --git a/tests/basics/bytearray_slice_assign.py b/tests/basics/bytearray_slice_assign.py index 48f5938a5..7f7d1d119 100644 --- a/tests/basics/bytearray_slice_assign.py +++ b/tests/basics/bytearray_slice_assign.py @@ -4,7 +4,7 @@ except TypeError: print("SKIP") raise SystemExit -# test slices; only 2 argument version supported by Micro Python at the moment +# test slices; only 2 argument version supported by MicroPython at the moment x = bytearray(range(10)) # Assignment diff --git a/tests/basics/containment.py b/tests/basics/containment.py index bae366113..4c94a9bae 100644 --- a/tests/basics/containment.py +++ b/tests/basics/containment.py @@ -16,6 +16,17 @@ for needle in [haystack[:i+1] for i in range(len(haystack))]: print(haystack, "in", needle, "::", haystack in needle) print(haystack, "not in", needle, "::", haystack not in needle) +# containment of bytes/ints in bytes +print(b'' in b'123') +print(b'0' in b'123', b'1' in b'123') +print(48 in b'123', 49 in b'123') + +# containment of int in str is an error +try: + 1 in '123' +except TypeError: + print('TypeError') + # until here, the tests would work without the 'second attempt' iteration thing. for i in 1, 2: diff --git a/tests/basics/exec1.py b/tests/basics/exec1.py deleted file mode 100644 index 59de5d69a..000000000 --- a/tests/basics/exec1.py +++ /dev/null @@ -1,6 +0,0 @@ -print(exec("def foo(): return 42")) -print(foo()) - -d = {} -exec("def bar(): return 84", d) -print(d["bar"]()) diff --git a/tests/basics/for_else.py b/tests/basics/for_else.py new file mode 100644 index 000000000..0bb941506 --- /dev/null +++ b/tests/basics/for_else.py @@ -0,0 +1,43 @@ +# test for-else statement + +# test optimised range with simple else +for i in range(2): + print(i) +else: + print('else') + +# test optimised range with break over else +for i in range(2): + print(i) + break +else: + print('else') + +# test nested optimised range with continue in the else +for i in range(4): + print(i) + for j in range(4): + pass + else: + continue + break + +# test optimised range with non-constant end value +N = 2 +for i in range(N): + print(i) +else: + print('else') + +# test generic iterator with simple else +for i in [0, 1]: + print(i) +else: + print('else') + +# test generic iterator with break over else +for i in [0, 1]: + print(i) + break +else: + print('else') diff --git a/tests/basics/int_bytes.py b/tests/basics/int_bytes.py index 93c00bba1..d1837ea75 100644 --- a/tests/basics/int_bytes.py +++ b/tests/basics/int_bytes.py @@ -8,3 +8,15 @@ 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) print(int.from_bytes(b"\x01" + bytes(20), "little") == 1) + +# big-endian conversion +print((10).to_bytes(1, "big")) +print((100).to_bytes(10, "big")) +print(int.from_bytes(b"\0\0\0\0\0\0\0\0\0\x01", "big")) +print(int.from_bytes(b"\x01\0", "big")) + +# negative number of bytes should raise an error +try: + (1).to_bytes(-1, "little") +except ValueError: + print("ValueError") diff --git a/tests/basics/int_bytes_intbig.py b/tests/basics/int_bytes_intbig.py index 0e0ad1cbb..147362bef 100644 --- a/tests/basics/int_bytes_intbig.py +++ b/tests/basics/int_bytes_intbig.py @@ -1,4 +1,5 @@ print((2**64).to_bytes(9, "little")) +print((2**64).to_bytes(9, "big")) b = bytes(range(20)) @@ -7,6 +8,7 @@ ib = int.from_bytes(b, "big") print(il) print(ib) print(il.to_bytes(20, "little")) +print(ib.to_bytes(20, "big")) # check that extra zero bytes don't change the internal int value print(int.from_bytes(b + bytes(10), "little") == int.from_bytes(b, "little")) diff --git a/tests/basics/int_bytes_notimpl.py b/tests/basics/int_bytes_notimpl.py deleted file mode 100644 index b149f4496..000000000 --- a/tests/basics/int_bytes_notimpl.py +++ /dev/null @@ -1,4 +0,0 @@ -try: - print((10).to_bytes(1, "big")) -except Exception as e: - print(type(e)) diff --git a/tests/basics/int_bytes_notimpl.py.exp b/tests/basics/int_bytes_notimpl.py.exp deleted file mode 100644 index 606649a69..000000000 --- a/tests/basics/int_bytes_notimpl.py.exp +++ /dev/null @@ -1 +0,0 @@ -<class 'NotImplementedError'> diff --git a/tests/basics/list_slice_assign.py b/tests/basics/list_slice_assign.py index 1ad1ef27c..885615717 100644 --- a/tests/basics/list_slice_assign.py +++ b/tests/basics/list_slice_assign.py @@ -1,4 +1,4 @@ -# test slices; only 2 argument version supported by Micro Python at the moment +# test slices; only 2 argument version supported by MicroPython at the moment x = list(range(10)) # Assignment diff --git a/tests/basics/namedtuple1.py b/tests/basics/namedtuple1.py index b9a007240..15e3b785e 100644 --- a/tests/basics/namedtuple1.py +++ b/tests/basics/namedtuple1.py @@ -24,6 +24,9 @@ for t in T(1, 2), T(bar=1, foo=2): print(isinstance(t, tuple)) +# Create using positional and keyword args +print(T(3, bar=4)) + try: t[0] = 200 except TypeError: diff --git a/tests/basics/op_precedence.py b/tests/basics/op_precedence.py new file mode 100644 index 000000000..519a2a113 --- /dev/null +++ b/tests/basics/op_precedence.py @@ -0,0 +1,43 @@ +# see https://docs.python.org/3/reference/expressions.html#operator-precedence + +# '|' is the least binding numeric operator + +# '^' +# OK: 1 | (2 ^ 3) = 1 | 1 = 1 +# BAD: (1 | 2) ^ 3 = 3 ^ 3 = 0 +print(1 | 2 ^ 3) + +# '&' +# OK: 3 ^ (2 & 1) = 3 ^ 0 = 3 +# BAD: (3 ^ 2) & 1 = 1 & 1 = 1 +print(3 ^ 2 & 1) + +# '<<', '>>' +# OK: 2 & (3 << 1) = 2 & 6 = 2 +# BAD: (2 & 3) << 1 = 2 << 1 = 4 +print(2 & 3 << 1) +# OK: 6 & (4 >> 1) = 6 & 2 = 2 +# BAD: (6 & 4) >> 1 = 2 >> 1 = 1 +print(6 & 4 >> 1) + +# '+', '-' +# OK: 1 << (1 + 1) = 1 << 2 = 4 +# BAD: (1 << 1) + 1 = 2 + 1 = 3 +print(1 << 1 + 1) + +# '*', '/', '//', '%' +# OK: 2 + (2 * 2) = 2 + 4 = 6 +# BAD: (2 + 2) * 2 = 4 * 2 = 8 +print(2 + 2 * 2) + +# '+x', '-x', '~x' + +# '**' +# OK: -(2**2) = -4 +# BAD: (-2)**2 = 4 +print(-2**2) +# OK: 2**(-1) = 0.5 +print(2**-1) + +# (expr...) +print((2 + 2) * 2) diff --git a/tests/basics/python34.py b/tests/basics/python34.py index a23f347d6..d5cc59ad6 100644 --- a/tests/basics/python34.py +++ b/tests/basics/python34.py @@ -20,6 +20,8 @@ def test_syntax(code): print("SyntaxError") test_syntax("f(*a, *b)") # can't have multiple * (in 3.5 we can) test_syntax("f(**a, **b)") # can't have multiple ** (in 3.5 we can) +test_syntax("f(*a, b)") # can't have positional after * +test_syntax("f(**a, b)") # can't have positional after ** test_syntax("() = []") # can't assign to empty tuple (in 3.6 we can) test_syntax("del ()") # can't delete empty tuple (in 3.6 we can) diff --git a/tests/basics/python34.py.exp b/tests/basics/python34.py.exp index f497df3b8..590fc364f 100644 --- a/tests/basics/python34.py.exp +++ b/tests/basics/python34.py.exp @@ -7,5 +7,7 @@ SyntaxError SyntaxError SyntaxError SyntaxError +SyntaxError +SyntaxError 3.4 3 4 diff --git a/tests/basics/struct1_intbig.py b/tests/basics/struct1_intbig.py index b1fec527e..380293f36 100644 --- a/tests/basics/struct1_intbig.py +++ b/tests/basics/struct1_intbig.py @@ -12,6 +12,8 @@ print(struct.pack("<I", 2**32 - 1)) print(struct.pack("<I", 0xffffffff)) # long long ints +print(struct.pack("<Q", 1)) +print(struct.pack(">Q", 1)) print(struct.pack("<Q", 2**64 - 1)) print(struct.pack(">Q", 2**64 - 1)) print(struct.pack("<Q", 0xffffffffffffffff)) diff --git a/tests/basics/struct2.py b/tests/basics/struct2.py index d8234d0d3..3b9dd5c1f 100644 --- a/tests/basics/struct2.py +++ b/tests/basics/struct2.py @@ -40,3 +40,30 @@ try: struct.calcsize('0z') except: print('Exception') + +# check that a count without a type specifier raises an exception + +try: + struct.calcsize('1') +except: + print('Exception') + +try: + struct.pack('1') +except: + print('Exception') + +try: + struct.pack_into('1', bytearray(4), 0, 'xx') +except: + print('Exception') + +try: + struct.unpack('1', 'xx') +except: + print('Exception') + +try: + struct.unpack_from('1', 'xx') +except: + print('Exception') diff --git a/tests/basics/tuple_mult.py b/tests/basics/tuple_mult.py index b128b2968..cac95185a 100644 --- a/tests/basics/tuple_mult.py +++ b/tests/basics/tuple_mult.py @@ -11,6 +11,11 @@ a = (1, 2, 3) c = a * 3 print(a, c) +# inplace multiplication +a = (1, 2) +a *= 2 +print(a) + # unsupported type on RHS try: () * None diff --git a/tests/cpydiff/core_class_mro.py b/tests/cpydiff/core_class_mro.py new file mode 100644 index 000000000..99713e790 --- /dev/null +++ b/tests/cpydiff/core_class_mro.py @@ -0,0 +1,15 @@ +""" +categories: Core,Classes +description: Method Resolution Order (MRO) is not compliant with CPython +cause: Depth first non-exhaustive method resolution order +workaround: Avoid complex class hierarchies with multiple inheritance and complex method overrides. Keep in mind that many languages don't support multiple inheritance at all. +""" +class Foo: + def __str__(self): + return "Foo" + +class C(tuple, Foo): + pass + +t = C((1, 2, 3)) +print(t) diff --git a/tests/cpydiff/core_class_supermultiple.py b/tests/cpydiff/core_class_supermultiple.py index adf4a17a8..f0823ee11 100644 --- a/tests/cpydiff/core_class_supermultiple.py +++ b/tests/cpydiff/core_class_supermultiple.py @@ -1,8 +1,8 @@ """ categories: Core,Classes description: When inheriting from multiple classes super() only calls one class -cause: Depth first non-exhaustive method resolution order -workaround: Unknown +cause: See :ref:`cpydiff_core_class_mro` +workaround: See :ref:`cpydiff_core_class_mro` """ class A: def __init__(self): diff --git a/tests/cpydiff/core_arguments.py b/tests/cpydiff/core_function_argcount.py index 4734a8062..5f3dca4dc 100644 --- a/tests/cpydiff/core_arguments.py +++ b/tests/cpydiff/core_function_argcount.py @@ -1,5 +1,5 @@ """ -categories: Core +categories: Core,Functions description: Error messages for methods may display unexpected argument counts cause: MicroPython counts "self" as an argument. workaround: Interpret error messages with the information above in mind. diff --git a/tests/cpydiff/core_mro.py b/tests/cpydiff/core_mro.py deleted file mode 100644 index 35b898b30..000000000 --- a/tests/cpydiff/core_mro.py +++ /dev/null @@ -1,15 +0,0 @@ -""" -categories: Core -description: Method Resolution Order (MRO) is not compliant with CPython -cause: Unknown -workaround: Unknown -""" -class Foo: - def __str__(self): - return "Foo" - -class C(tuple, Foo): - pass - -t = C((1, 2, 3)) -print(t) diff --git a/tests/cpydiff/modules_deque.py b/tests/cpydiff/modules_deque.py index dc9369d02..a503ea4f5 100644 --- a/tests/cpydiff/modules_deque.py +++ b/tests/cpydiff/modules_deque.py @@ -2,7 +2,7 @@ categories: Modules,deque description: Deque not implemented cause: Unknown -workaround: Use regular queues or lists creatively +workaround: Use regular lists. micropython-lib has implementation of collections.deque. """ import collections D = collections.deque() diff --git a/tests/cpydiff/modules_sys_stdassign.py b/tests/cpydiff/modules_sys_stdassign.py index 096af430e..1bf2a598a 100644 --- a/tests/cpydiff/modules_sys_stdassign.py +++ b/tests/cpydiff/modules_sys_stdassign.py @@ -1,7 +1,7 @@ """ categories: Modules,sys -description: Override sys.stdin, sys.stdout and sys.stderr. Impossible as they are stored in read-only memory. -cause: Unknown +description: Overriding sys.stdin, sys.stdout and sys.stderr not possible +cause: They are stored in read-only memory. workaround: Unknown """ import sys diff --git a/tests/cpydiff/types_bytes_keywords.py b/tests/cpydiff/types_bytes_keywords.py index 35119e28f..4dc383f26 100644 --- a/tests/cpydiff/types_bytes_keywords.py +++ b/tests/cpydiff/types_bytes_keywords.py @@ -1,7 +1,7 @@ """ categories: Types,bytes -description: bytes(...) with keywords not implemented +description: bytes() with keywords not implemented cause: Unknown -workaround: Input the encoding format directly. eg. ``print(bytes('abc', 'utf-8'))`` +workaround: Pass the encoding as a positional paramter, e.g. ``print(bytes('abc', 'utf-8'))`` """ print(bytes('abc', encoding='utf8')) diff --git a/tests/cpydiff/types_bytes_subscrstep.py b/tests/cpydiff/types_bytes_subscrstep.py index fd1602d65..2871bda6c 100644 --- a/tests/cpydiff/types_bytes_subscrstep.py +++ b/tests/cpydiff/types_bytes_subscrstep.py @@ -1,7 +1,7 @@ """ categories: Types,bytes -description: Bytes subscr with step != 1 not implemented -cause: Unknown -workaround: Unknown +description: Bytes subscription with step != 1 not implemented +cause: MicroPython is highly optimized for memory usage. +workaround: Use explicit loop for this very rare operation. """ print(b'123'[0:3:2]) diff --git a/tests/cpydiff/types_exception_instancevar.py b/tests/cpydiff/types_exception_instancevar.py index d1015e96c..adc353361 100644 --- a/tests/cpydiff/types_exception_instancevar.py +++ b/tests/cpydiff/types_exception_instancevar.py @@ -1,8 +1,8 @@ """ categories: Types,Exception -description: Assign instance variable to exception -cause: Unknown -workaround: Unknown +description: User-defined attributes for builtin exceptions are not supported +cause: MicroPython is highly optimized for memory usage. +workaround: Use user-defined exception subclasses. """ e = Exception() e.x = 0 diff --git a/tests/cpydiff/types_exception_loops.py b/tests/cpydiff/types_exception_loops.py index a142e4757..8d326cbbb 100644 --- a/tests/cpydiff/types_exception_loops.py +++ b/tests/cpydiff/types_exception_loops.py @@ -1,7 +1,7 @@ """ categories: Types,Exception -description: While loop guards will obscure exception line number reporting due to being optimised onto the end of the code block -cause: Unknown +description: Exception in while loop condition may have unexpected line number +cause: Condition checks are optimized to happen at the end of loop body, and that line number is reported. workaround: Unknown """ l = ["-foo", "-bar"] diff --git a/tests/cpydiff/types_float_rounding.py b/tests/cpydiff/types_float_rounding.py index 647f61ba2..82a149d85 100644 --- a/tests/cpydiff/types_float_rounding.py +++ b/tests/cpydiff/types_float_rounding.py @@ -1,6 +1,6 @@ """ categories: Types,float -description: uPy and CPython outputs formats differ +description: uPy and CPython outputs formats may differ cause: Unknown workaround: Unknown """ diff --git a/tests/cpydiff/types_int_subclassconv.py b/tests/cpydiff/types_int_subclassconv.py index 565fbad4b..260b060ed 100644 --- a/tests/cpydiff/types_int_subclassconv.py +++ b/tests/cpydiff/types_int_subclassconv.py @@ -2,7 +2,7 @@ categories: Types,int description: No int conversion for int-derived types available cause: Unknown -workaround: Unknown +workaround: Avoid subclassing builtin types unless really needed. Prefer https://en.wikipedia.org/wiki/Composition_over_inheritance . """ class A(int): __add__ = lambda self, other: A(int(self) + other) diff --git a/tests/cpydiff/types_list_delete_subscrstep.py b/tests/cpydiff/types_list_delete_subscrstep.py index f524fa8dc..36e6f526b 100644 --- a/tests/cpydiff/types_list_delete_subscrstep.py +++ b/tests/cpydiff/types_list_delete_subscrstep.py @@ -2,7 +2,7 @@ categories: Types,list description: List delete with step != 1 not implemented cause: Unknown -workaround: Unknown +workaround: Use explicit loop for this rare operation. """ l = [1, 2, 3, 4] del l[0:4:2] diff --git a/tests/cpydiff/types_list_store_subscrstep.py b/tests/cpydiff/types_list_store_subscrstep.py index 2de2e1a3c..1460372bb 100644 --- a/tests/cpydiff/types_list_store_subscrstep.py +++ b/tests/cpydiff/types_list_store_subscrstep.py @@ -2,7 +2,7 @@ categories: Types,list description: List store with step != 1 not implemented cause: Unknown -workaround: Unknown +workaround: Use explicit loop for this rare operation. """ l = [1, 2, 3, 4] l[0:4:2] = [5, 6] diff --git a/tests/cpydiff/types_str_ljust_rjust.py b/tests/cpydiff/types_str_ljust_rjust.py new file mode 100644 index 000000000..498596205 --- /dev/null +++ b/tests/cpydiff/types_str_ljust_rjust.py @@ -0,0 +1,7 @@ +""" +categories: Types,str +description: str.ljust() and str.rjust() not implemented +cause: MicroPython is highly optimized for memory usage. Easy workarounds available. +workaround: Instead of `s.ljust(10)` use `"%-10s" % s`, instead of `s.rjust(10)` use `"% 10s" % s`. Alternatively, `"{:<10}".format(s)` or `"{:>10}".format(s)`. +""" +print('abc'.ljust(10)) diff --git a/tests/extmod/ubinascii_a2b_base64.py b/tests/extmod/ubinascii_a2b_base64.py index b35f26591..05a3169f3 100644 --- a/tests/extmod/ubinascii_a2b_base64.py +++ b/tests/extmod/ubinascii_a2b_base64.py @@ -21,6 +21,13 @@ print(binascii.a2b_base64(b'f4D/')) print(binascii.a2b_base64(b'f4D+')) # convert '+' print(binascii.a2b_base64(b'MTIzNEFCQ0RhYmNk')) +# Ignore invalid characters and pad sequences +print(binascii.a2b_base64(b'Zm9v\n')) +print(binascii.a2b_base64(b'Zm\x009v\n')) +print(binascii.a2b_base64(b'Zm9v==')) +print(binascii.a2b_base64(b'Zm9v===')) +print(binascii.a2b_base64(b'Zm9v===YmFy')) + try: print(binascii.a2b_base64(b'abc')) except ValueError: diff --git a/tests/extmod/ubinascii_micropython.py b/tests/extmod/ubinascii_micropython.py index a4c00a2cb..77084ec9e 100644 --- a/tests/extmod/ubinascii_micropython.py +++ b/tests/extmod/ubinascii_micropython.py @@ -10,3 +10,6 @@ except ImportError: # two arguments supported in uPy but not CPython a = binascii.hexlify(b'123', ':') print(a) + +# zero length buffer +print(binascii.hexlify(b'', b':')) diff --git a/tests/extmod/ubinascii_micropython.py.exp b/tests/extmod/ubinascii_micropython.py.exp index 0ae3d768e..a195d2602 100644 --- a/tests/extmod/ubinascii_micropython.py.exp +++ b/tests/extmod/ubinascii_micropython.py.exp @@ -1 +1,2 @@ b'31:32:33' +b'' diff --git a/tests/extmod/ure1.py b/tests/extmod/ure1.py index 1f38b8087..6075990fc 100644 --- a/tests/extmod/ure1.py +++ b/tests/extmod/ure1.py @@ -80,3 +80,6 @@ try: re.compile("*") except: print("Caught invalid regex") + +# bytes objects +m = re.match(rb'a+?', b'ab'); print(m.group(0)) diff --git a/tests/extmod/ure_split.py b/tests/extmod/ure_split.py index 317ca9892..a8b9c1686 100644 --- a/tests/extmod/ure_split.py +++ b/tests/extmod/ure_split.py @@ -26,3 +26,8 @@ print(s) r = re.compile("[a-f]+") s = r.split("0a3b9") print(s) + +# bytes objects +r = re.compile(b"x") +s = r.split(b"fooxbar") +print(s) diff --git a/tests/extmod/ussl_basic.py b/tests/extmod/ussl_basic.py index 9f8019a0b..e8710ed51 100644 --- a/tests/extmod/ussl_basic.py +++ b/tests/extmod/ussl_basic.py @@ -43,6 +43,14 @@ except OSError as er: # close ss.close() +# close 2nd time +ss.close() + +# read on closed socket +try: + ss.read(10) +except OSError as er: + print('read:', repr(er)) # write on closed socket try: diff --git a/tests/extmod/ussl_basic.py.exp b/tests/extmod/ussl_basic.py.exp index b4dd03860..cb9c51f7a 100644 --- a/tests/extmod/ussl_basic.py.exp +++ b/tests/extmod/ussl_basic.py.exp @@ -5,4 +5,5 @@ setblocking: NotImplementedError 4 b'' read: OSError(-261,) -write: OSError(-256,) +read: OSError(9,) +write: OSError(9,) diff --git a/tests/feature_check/float.py b/tests/feature_check/float.py new file mode 100644 index 000000000..af93f5976 --- /dev/null +++ b/tests/feature_check/float.py @@ -0,0 +1,13 @@ +# detect how many bits of precision the floating point implementation has + +try: + float +except NameError: + print(0) +else: + if float('1.0000001') == float('1.0'): + print(30) + elif float('1e300') == float('inf'): + print(32) + else: + print(64) diff --git a/tests/feature_check/float.py.exp b/tests/feature_check/float.py.exp new file mode 100644 index 000000000..900731ffd --- /dev/null +++ b/tests/feature_check/float.py.exp @@ -0,0 +1 @@ +64 diff --git a/tests/float/int_big_float.py b/tests/float/int_big_float.py index b1a26ca73..0bd166218 100644 --- a/tests/float/int_big_float.py +++ b/tests/float/int_big_float.py @@ -18,6 +18,10 @@ print("%.5g" % (i / 1.2)) # this should delegate to complex print("%.5g" % (i * 1.2j).imag) +# negative power should produce float +print("%.5g" % (i ** -1)) +print("%.5g" % ((2 + i - i) ** -3)) + try: i / 0 except ZeroDivisionError: diff --git a/tests/float/math_fun.py b/tests/float/math_fun.py index 80d20bd8a..2835b9bfb 100644 --- a/tests/float/math_fun.py +++ b/tests/float/math_fun.py @@ -51,7 +51,7 @@ binary_functions = [('copysign', copysign, [(23., 42.), (-23., 42.), (23., -42.) ('atan2', atan2, ((1., 0.), (0., 1.), (2., 0.5), (-3., 5.), (-3., -4.),)), ('fmod', fmod, ((1., 1.), (0., 1.), (2., 0.5), (-3., 5.), (-3., -4.),)), ('ldexp', ldexp, ((1., 0), (0., 1), (2., 2), (3., -2), (-3., -4),)), - ('log', log, ((2., 2.), (3., 2.), (4., 5.), (0., 1.), (1., 0.), (-1., 1.), (1., -1.))), + ('log', log, ((2., 2.), (3., 2.), (4., 5.), (0., 1.), (1., 0.), (-1., 1.), (1., -1.), (2., 1.))), ] for function_name, function, test_vals in binary_functions: @@ -59,5 +59,5 @@ for function_name, function, test_vals in binary_functions: for value1, value2 in test_vals: try: print("{:.5g}".format(function(value1, value2))) - except ValueError as e: - print(str(e)) + except (ValueError, ZeroDivisionError) as e: + print(type(e)) diff --git a/tests/float/string_format_modulo.py b/tests/float/string_format_modulo.py index 03c8dd00a..aea534247 100644 --- a/tests/float/string_format_modulo.py +++ b/tests/float/string_format_modulo.py @@ -44,3 +44,6 @@ print(('%.40g' % 1e-3)[:2]) print(('%.40g' % 1e-4)[:2]) print("%.0g" % 1) # 0 precision 'g' + +print('%.1e' % 9.99) # round up with positive exponent +print('%.1e' % 0.999) # round up with negative exponent diff --git a/tests/float/string_format_modulo3.py b/tests/float/string_format_modulo3.py index 563964786..5d26f2575 100644 --- a/tests/float/string_format_modulo3.py +++ b/tests/float/string_format_modulo3.py @@ -1,4 +1,3 @@ # uPy and CPython outputs differ for the following print("%.1g" % -9.9) # round up 'g' with '-' sign -print("%.1e" % 9.99) # round up with positive exponent -print("%.1e" % 0.999) # round up with negative exponent +print("%.2g" % 99.9) # round up diff --git a/tests/float/string_format_modulo3.py.exp b/tests/float/string_format_modulo3.py.exp index b158c7d7f..71432b340 100644 --- a/tests/float/string_format_modulo3.py.exp +++ b/tests/float/string_format_modulo3.py.exp @@ -1,3 +1,2 @@ -10 -1.00e+01 -1.00e-00 +100 diff --git a/tests/import/builtin_import.py b/tests/import/builtin_import.py new file mode 100644 index 000000000..088f631fc --- /dev/null +++ b/tests/import/builtin_import.py @@ -0,0 +1,16 @@ +# test calling builtin import function + +# basic test +__import__('builtins') + +# first arg should be a string +try: + __import__(1) +except TypeError: + print('TypeError') + +# level argument should be non-negative +try: + __import__('xyz', None, None, None, -1) +except ValueError: + print('ValueError') diff --git a/tests/import/pkg7/subpkg1/subpkg2/mod3.py b/tests/import/pkg7/subpkg1/subpkg2/mod3.py index 7ed69bdee..c73e2081f 100644 --- a/tests/import/pkg7/subpkg1/subpkg2/mod3.py +++ b/tests/import/pkg7/subpkg1/subpkg2/mod3.py @@ -3,8 +3,7 @@ from ...mod2 import bar print(mod1.foo) print(bar) -# when attempting relative import beyond top-level package uPy raises ImportError -# whereas CPython raises a ValueError +# attempted relative import beyond top-level package try: from .... import mod1 except ValueError: diff --git a/tests/io/bytesio_ext2.py b/tests/io/bytesio_ext2.py new file mode 100644 index 000000000..c07ad900c --- /dev/null +++ b/tests/io/bytesio_ext2.py @@ -0,0 +1,13 @@ +try: + import uio as io +except ImportError: + import io + +a = io.BytesIO(b"foobar") +try: + a.seek(-10) +except Exception as e: + # CPython throws ValueError, but MicroPython has consistent stream + # interface, so BytesIO raises the same error as a real file, which + # is OSError(EINVAL). + print(repr(e)) diff --git a/tests/io/bytesio_ext2.py.exp b/tests/io/bytesio_ext2.py.exp new file mode 100644 index 000000000..b52e4978a --- /dev/null +++ b/tests/io/bytesio_ext2.py.exp @@ -0,0 +1 @@ +OSError(22,) diff --git a/tests/io/stringio1.py b/tests/io/stringio1.py index fa50f282e..9f7c1e44e 100644 --- a/tests/io/stringio1.py +++ b/tests/io/stringio1.py @@ -36,7 +36,7 @@ print(a.read()) a = io.StringIO() a.close() for f in [a.read, a.getvalue, lambda:a.write("")]: - # CPython throws for operations on closed I/O, micropython makes + # CPython throws for operations on closed I/O, MicroPython makes # the underlying string empty unless MICROPY_CPYTHON_COMPAT defined try: f() diff --git a/tests/net_hosted/README b/tests/net_hosted/README new file mode 100644 index 000000000..724dd6158 --- /dev/null +++ b/tests/net_hosted/README @@ -0,0 +1,11 @@ +This directory contains network tests which require just "peer to peer" +network connection between test host and device under test, instead of +full Internet connection. + +Note that setup for these tests and tests themselves are WIP, and may +not yet fully correspond to the functional specification above. + +So far, these tests are not run as part of the main testsuite and need +to be run seperately (from the main test/ directory): + + ./run-tests net_hosted/*.py diff --git a/tests/net_hosted/accept_nonblock.py b/tests/net_hosted/accept_nonblock.py new file mode 100644 index 000000000..56f3288e2 --- /dev/null +++ b/tests/net_hosted/accept_nonblock.py @@ -0,0 +1,16 @@ +# test that socket.accept() on a non-blocking socket raises EAGAIN + +try: + import usocket as socket +except: + import socket + +s = socket.socket() +s.bind(socket.getaddrinfo('127.0.0.1', 8123)[0][-1]) +s.setblocking(False) +s.listen(1) +try: + s.accept() +except OSError as er: + print(er.args[0] == 11) # 11 is EAGAIN +s.close() diff --git a/tests/net_hosted/accept_nonblock.py.exp b/tests/net_hosted/accept_nonblock.py.exp new file mode 100644 index 000000000..0ca95142b --- /dev/null +++ b/tests/net_hosted/accept_nonblock.py.exp @@ -0,0 +1 @@ +True diff --git a/tests/net_hosted/accept_timeout.py b/tests/net_hosted/accept_timeout.py new file mode 100644 index 000000000..44b3b8c7c --- /dev/null +++ b/tests/net_hosted/accept_timeout.py @@ -0,0 +1,22 @@ +# test that socket.accept() on a socket with timeout raises ETIMEDOUT + +try: + import usocket as socket +except: + import socket + +try: + socket.socket.settimeout +except AttributeError: + print('SKIP') + raise SystemExit + +s = socket.socket() +s.bind(socket.getaddrinfo('127.0.0.1', 8123)[0][-1]) +s.settimeout(1) +s.listen(1) +try: + s.accept() +except OSError as er: + print(er.args[0] in (110, 'timed out')) # 110 is ETIMEDOUT; CPython uses a string +s.close() diff --git a/tests/net_hosted/accept_timeout.py.exp b/tests/net_hosted/accept_timeout.py.exp new file mode 100644 index 000000000..0ca95142b --- /dev/null +++ b/tests/net_hosted/accept_timeout.py.exp @@ -0,0 +1 @@ +True diff --git a/tests/net_hosted/connect_nonblock.py b/tests/net_hosted/connect_nonblock.py new file mode 100644 index 000000000..6479978be --- /dev/null +++ b/tests/net_hosted/connect_nonblock.py @@ -0,0 +1,20 @@ +# test that socket.connect() on a non-blocking socket raises EINPROGRESS + +try: + import usocket as socket +except: + import socket + + +def test(peer_addr): + s = socket.socket() + s.setblocking(False) + try: + s.connect(peer_addr) + except OSError as er: + print(er.args[0] == 115) # 115 is EINPROGRESS + s.close() + + +if __name__ == "__main__": + test(socket.getaddrinfo('micropython.org', 80)[0][-1]) diff --git a/tests/net_hosted/connect_nonblock.py.exp b/tests/net_hosted/connect_nonblock.py.exp new file mode 100644 index 000000000..0ca95142b --- /dev/null +++ b/tests/net_hosted/connect_nonblock.py.exp @@ -0,0 +1 @@ +True diff --git a/tests/net_hosted/ssl_getpeercert.py b/tests/net_hosted/ssl_getpeercert.py new file mode 100644 index 000000000..e265c830d --- /dev/null +++ b/tests/net_hosted/ssl_getpeercert.py @@ -0,0 +1,21 @@ +# test ssl.getpeercert() method + +try: + import usocket as socket + import ussl as ssl +except: + import socket + import ssl + + +def test(peer_addr): + s = socket.socket() + s.connect(peer_addr) + s = ssl.wrap_socket(s) + cert = s.getpeercert(True) + print(type(cert), len(cert) > 100) + s.close() + + +if __name__ == "__main__": + test(socket.getaddrinfo('micropython.org', 443)[0][-1]) diff --git a/tests/net_hosted/ssl_getpeercert.py.exp b/tests/net_hosted/ssl_getpeercert.py.exp new file mode 100644 index 000000000..ff7ef5adf --- /dev/null +++ b/tests/net_hosted/ssl_getpeercert.py.exp @@ -0,0 +1 @@ +<class 'bytes'> True diff --git a/tests/net_inet/README b/tests/net_inet/README new file mode 100644 index 000000000..9a5614efa --- /dev/null +++ b/tests/net_inet/README @@ -0,0 +1,5 @@ +This directory contains network tests which require Internet connection. +Note that these tests are not run as part of the main testsuite and need +to be run seperately (from the main test/ directory): + + ./run-tests net_inet/*.py diff --git a/tests/net_inet/test_tls_sites.py b/tests/net_inet/test_tls_sites.py new file mode 100644 index 000000000..67345fd0b --- /dev/null +++ b/tests/net_inet/test_tls_sites.py @@ -0,0 +1,56 @@ +try: + import usocket as _socket +except: + import _socket +try: + import ussl as ssl +except: + import ssl + + +def test_one(site, opts): + ai = _socket.getaddrinfo(site, 443) + addr = ai[0][-1] + + s = _socket.socket() + + try: + s.connect(addr) + + if "sni" in opts: + s = ssl.wrap_socket(s, server_hostname=opts["host"]) + else: + s = ssl.wrap_socket(s) + + s.write(b"GET / HTTP/1.0\r\n\r\n") + resp = s.read(4096) +# print(resp) + + finally: + s.close() + + +SITES = [ + "google.com", + "www.google.com", + "api.telegram.org", +# "w9rybpfril.execute-api.ap-southeast-2.amazonaws.com", + {"host": "w9rybpfril.execute-api.ap-southeast-2.amazonaws.com", "sni": True}, +] + + +def main(): + for site in SITES: + opts = {} + if isinstance(site, dict): + opts = site + site = opts["host"] + + try: + test_one(site, opts) + print(site, "ok") + except Exception as e: + print(site, repr(e)) + + +main() diff --git a/tests/net_inet/test_tls_sites.py.exp b/tests/net_inet/test_tls_sites.py.exp new file mode 100644 index 000000000..12732d1fa --- /dev/null +++ b/tests/net_inet/test_tls_sites.py.exp @@ -0,0 +1,4 @@ +google.com ok +www.google.com ok +api.telegram.org ok +w9rybpfril.execute-api.ap-southeast-2.amazonaws.com ok diff --git a/tests/run-bench-tests b/tests/run-bench-tests index 1e5e7804b..d48b4b7ec 100755 --- a/tests/run-bench-tests +++ b/tests/run-bench-tests @@ -26,7 +26,7 @@ def run_tests(pyb, test_dict): print(base_test + ":") for test_file in tests: - # run Micro Python + # run MicroPython if pyb is None: # run on PC try: diff --git a/tests/run-tests b/tests/run-tests index f24fc0961..f9c26283d 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -239,6 +239,7 @@ def run_tests(pyb, tests, args, base_path="."): skip_tests.add('cmdline/repl_emacs_keys.py') upy_byteorder = run_feature_check(pyb, args, base_path, 'byteorder.py') + upy_float_precision = int(run_feature_check(pyb, args, base_path, 'float.py')) has_complex = run_feature_check(pyb, args, base_path, 'complex.py') == b'complex\n' has_coverage = run_feature_check(pyb, args, base_path, 'coverage.py') == b'coverage\n' cpy_byteorder = subprocess.check_output([CPYTHON3, base_path + '/feature_check/byteorder.py']) @@ -252,6 +253,19 @@ def run_tests(pyb, tests, args, base_path="."): skip_tests.add('thread/stress_heap.py') # has reliability issues skip_tests.add('thread/stress_recurse.py') # has reliability issues + if upy_float_precision == 0: + skip_tests.add('extmod/ujson_dumps_float.py') + skip_tests.add('extmod/ujson_loads_float.py') + skip_tests.add('misc/rge_sm.py') + if upy_float_precision < 32: + skip_tests.add('float/float2int_intbig.py') # requires fp32, there's float2int_fp30_intbig.py instead + skip_tests.add('float/string_format.py') # requires fp32, there's string_format_fp30.py instead + skip_tests.add('float/bytes_construct.py') # requires fp32 + skip_tests.add('float/bytearray_construct.py') # requires fp32 + if upy_float_precision < 64: + skip_tests.add('float/float_divmod.py') # tested by float/float_divmod_relaxed.py instead + skip_tests.add('float/float2int_doubleprec_intbig.py') + if not has_complex: skip_tests.add('float/complex1.py') skip_tests.add('float/complex1_intbig.py') @@ -272,8 +286,6 @@ def run_tests(pyb, tests, args, base_path="."): # Some tests shouldn't be run on pyboard if pyb is not None: skip_tests.add('basics/exception_chain.py') # warning is not printed - skip_tests.add('float/float_divmod.py') # tested by float/float_divmod_relaxed.py instead - skip_tests.add('float/float2int_doubleprec_intbig.py') # requires double precision floating point to work skip_tests.add('micropython/meminfo.py') # output is very different to PC output skip_tests.add('extmod/machine_mem.py') # raw memory access not supported @@ -282,19 +294,12 @@ def run_tests(pyb, tests, args, base_path="."): skip_tests.add('misc/recursion.py') # requires stack checking enabled skip_tests.add('misc/recursive_data.py') # requires stack checking enabled skip_tests.add('misc/recursive_iternext.py') # requires stack checking enabled - skip_tests.add('misc/rge_sm.py') # requires floating point skip_tests.update({'extmod/uctypes_%s.py' % t for t in 'bytearray le native_le ptr_le ptr_native_le sizeof sizeof_native array_assign_le array_assign_native_le'.split()}) # requires uctypes skip_tests.add('extmod/zlibd_decompress.py') # requires zlib - skip_tests.add('extmod/ujson_dumps_float.py') # requires floating point - skip_tests.add('extmod/ujson_loads_float.py') # requires floating point skip_tests.add('extmod/uheapq1.py') # uheapq not supported by WiPy skip_tests.add('extmod/urandom_basic.py') # requires urandom skip_tests.add('extmod/urandom_extra.py') # requires urandom elif args.target == 'esp8266': - skip_tests.add('float/float2int_intbig.py') # requires at least fp32, there's float2int_fp30_intbig.py instead - skip_tests.add('float/string_format.py') # requires at least fp32, there's string_format_fp30.py instead - skip_tests.add('float/bytes_construct.py') # requires fp32 - skip_tests.add('float/bytearray_construct.py') # requires fp32 skip_tests.add('misc/rge_sm.py') # too large elif args.target == 'minimal': skip_tests.add('misc/rge_sm.py') # too large @@ -318,6 +323,7 @@ def run_tests(pyb, tests, args, base_path="."): skip_tests.update({'basics/%s.py' % t for t in 'with_break with_continue with_return'.split()}) # require complete with support skip_tests.add('basics/array_construct2.py') # requires generators skip_tests.add('basics/bool1.py') # seems to randomly fail + skip_tests.add('basics/builtin_hash_gen.py') # requires yield skip_tests.add('basics/class_bind_self.py') # requires yield skip_tests.add('basics/del_deref.py') # requires checking for unbound local skip_tests.add('basics/del_local.py') # requires checking for unbound local @@ -382,7 +388,7 @@ def run_tests(pyb, tests, args, base_path="."): if args.write_exp: continue - # run Micro Python + # run MicroPython output_mupy = run_micropython(pyb, args, test_file) if output_mupy == b'SKIP\n': diff --git a/tests/thread/thread_lock1.py b/tests/thread/thread_lock1.py index ca585ffbb..ba5c7dff0 100644 --- a/tests/thread/thread_lock1.py +++ b/tests/thread/thread_lock1.py @@ -38,3 +38,9 @@ try: except KeyError: print('KeyError') print(lock.locked()) + +# test that we can't release an unlocked lock +try: + lock.release() +except RuntimeError: + print('RuntimeError') diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp index 416993887..ab638a632 100644 --- a/tests/unix/extra_coverage.py.exp +++ b/tests/unix/extra_coverage.py.exp @@ -11,6 +11,7 @@ false true 2147483648 80000000 80000000 +abc # vstr tests sts @@ -24,7 +25,8 @@ ame__ __name__ path argv version version_info implementation platform byteorder maxsize exit stdin stdout -stderr modules exc_info print_exception +stderr modules exc_info getsizeof +print_exception ementation # attrtuple (start=1, stop=2, step=3) |
