summaryrefslogtreecommitdiffstatshomepage
path: root/tests
Commit message (Collapse)AuthorAge
* py/builtinimport: Remove partially-loaded modules from sys.modules.David Grayson2023-06-05
| | | | | | | | | | | | | | | | | | | Prior to this commit, importing a module that exists but has a syntax error or some other problem that happens at import time would result in a potentially-incomplete module object getting added to sys.modules. Subsequent imports would use that object, resulting in confusing error messages that hide the root cause of the problem. This commit fixes that issue by removing the failed module from sys.modules using the new NLR callback mechanism. Note that it is still important to add the module to sys.modules while the import is happening so that we can support circular imports just like CPython does. Fixes issue #967. Signed-off-by: David Grayson <davidegrayson@gmail.com>
* tests/import/import_pkg9.py: Add test for subpackage attribute.Jim Mussared2023-06-01
| | | | | | | | | | | When foo.bar is imported, bar is added as an attribute to foo. Previously this happened on every import, but should only happen on first import. This verifies the behavior for relative imports and overriding. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests/import/builtin_ext.py: Add test for built-in module override.Jim Mussared2023-06-01
| | | | | | | | | | | This verifies the behavior: - Exact matches of built-ins bypass filesystem. - u-prefix modules can be overridden from the filesystem. - Builtin import can be forced using either u-prefix or sys.path=[]. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* examples/usercmodule: Add a sub-package example.Jim Mussared2023-06-01
| | | | | | | | | | | This demonstrates how to add a sub-package in a user c module, as well as how to define the necessary qstrs and enable the feature in the build. This is used by the unix coverage build to test this feature. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/objint: Allow int() to parse anything with the buffer protocol.Damien George2023-06-01
| | | | | | | | This generalises and simplifies the code and follows CPython behaviour. See similar change for floats in a07fc5b6403b9a8bf7e7cb64f857272e5346d7e2. Signed-off-by: Damien George <damien@micropython.org>
* py/obj: Accept user types in mp_obj_get_int_maybe.Damien George2023-06-01
| | | | | | | | | This is possible now that MP_UNARY_OP_INT_MAYBE exists. As a consequence mp_obj_get_int now also supports user types, which was previously possible with MP_UNARY_OP_INT but no tests existed for it. Signed-off-by: Damien George <damien@micropython.org>
* py: Change MP_UNARY_OP_INT to MP_UNARY_OP_INT_MAYBE.Damien George2023-06-01
| | | | | | | | To be consistent with MP_UNARY_OP_INT_FLOAT and MP_UNARY_OP_INT_COMPLEX, and allow int() to first check if a type supports __int__ before trying other things (as per CPython). Signed-off-by: Damien George <damien@micropython.org>
* tests/basics: Remove __index__ and __inv__ from special methods tests.Damien George2023-06-01
| | | | | | | MicroPython does not support these special methods, and they may get in the way of other tests (eg indexing with __int__). Signed-off-by: Damien George <damien@micropython.org>
* py/runtime: If inplace binop fails then try corresponding normal binop.Damien George2023-05-19
| | | | | | | | The code that handles inplace-operator to normal-binary-operator fallback is moved in this commit from py/objtype.c to py/runtime.c, making it apply to all types, not just user classes. Signed-off-by: Damien George <damien@micropython.org>
* py/objstr: Return unsupported binop instead of raising TypeError.Damien George2023-05-19
| | | | | | | So that user types can implement reverse operators and have them work with str on the left-hand-side, eg `"a" + UserType()`. Signed-off-by: Damien George <damien@micropython.org>
* py/objarray: Disallow memoryview addition.Damien George2023-05-19
| | | | | | | Following CPython. This is important for subsequent commits to work correctly. Signed-off-by: Damien George <damien@micropython.org>
* tests/basics: Add more tests for hashing of various types.Damien George2023-05-19
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/objdict: Fix __hash__ for dict_view types.David Lechner2023-05-19
| | | | | | | This adds a unary_op implementation for the dict_view type that makes the implementation of `hash()` for these types compatible with CPython. Signed-off-by: David Lechner <david@pybricks.com>
* py/objslice: Ensure slice is not hashable.David Lechner2023-05-19
| | | | | | | | As per https://bugs.python.org/issue408326, the slice object should not be hashable. Since MicroPython has an implicit fallback when the unary_op slot is empty, we need to fill this slot. Signed-off-by: David Lechner <david@pybricks.com>
* tests/run-tests.py: Ensure correct cwd for mpy tests.Jim Mussared2023-05-18
| | | | | | | | | | | | | | | | | | | | | | | | | | Previously when using --via-mpy, the file was compiled to tests/<tmp>.mpy and then run using `micropython -m <tmp>` in the current cwd (usually tests/). This meant that an import in the test would be resolved relative to tests/. This is different to regular (non-via-mpy) tests, where we run (for example) `micropython basics/test.py` which means that an import would be resolved relative to basics/. Now --via-mpy matches the .py behavior. This is important because: a) It makes it so import tests do the right thing. b) There are directory names in tests/ that match built-in module names. Furthermore, it always ensures the cwd (for both micropython and cpython) is the test directory (e.g. basics/) rather than being left unset. This also makes it clearer inside the test that e.g. file access is relative to the Python file. Updated tests with file paths to match. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/compile: Remove over-eager optimisation of tuples as if condition.Damien George2023-05-03
| | | | | | | | | | | | | | | | | | | | | | | | When a tuple is the condition of an if statement, it's only possible to optimise that tuple away when it is a constant tuple (ie all its elements are constants), because if it's not constant then the elements must be evaluated in case they have side effects (even though the resulting tuple will always be "true"). The code before this change handled the empty tuple OK (because it doesn't need to be evaluated), but it discarded non-empty tuples without evaluating them, which is incorrect behaviour (as show by the updated test). This optimisation is anyway rarely applied because it's not common Python coding practice to write things like `if (): ...` and `if (1, 2): ...`, so removing this optimisation completely won't affect much code, if any. Furthermore, when MICROPY_COMP_CONST_TUPLE is enabled, constant tuples are already optimised by the parser, so expression with constant tuples like `if (): ...` and `if (1, 2): ...` will continue to be optimised properly (and so when this option is enabled the code that's deleted in this commit is actually unreachable when the if condition is a constant tuple). Signed-off-by: Damien George <damien@micropython.org>
* esp32,esp8266: Add support for the Espressif ESP-NOW protocol.Glenn Moloney2023-05-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ESP-NOW is a proprietary wireless communication protocol which supports connectionless communication between ESP32 and ESP8266 devices, using vendor specific WiFi frames. This commit adds support for this protocol through a new `espnow` module. This commit builds on original work done by @nickzoic, @shawwwn and with contributions from @zoland. Features include: - Use of (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring. - Core support in `_espnow` C module, extended by `espnow.py` module. - Asyncio support via `aioespnow.py` module (separate to this commit). - Docs provided at `docs/library/espnow.rst`. Methods available in espnow.ESPNow class are: - active(True/False) - config(): set rx buffer size, read timeout and tx rate - recv()/irecv()/recvinto() to read incoming messages from peers - send() to send messages to peer devices - any() to test if a message is ready to read - irq() to set callback for received messages - stats() returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts) - add_peer(mac, ...) registers a peer before sending messages - get_peer(mac) returns peer info: (mac, lmk, channel, ifidx, encrypt) - mod_peer(mac, ...) changes peer info parameters - get_peers() returns all peer info tuples - peers_table supports RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} ESP8266 is a pared down version of the ESP32 ESPNow support due to code size restrictions and differences in the low-level API. See docs for details. Also included is a test suite in tests/multi_espnow. This tests basic espnow data transfer, multiple transfers, various message sizes, encrypted messages (pmk and lmk), and asyncio support. Initial work is from https://github.com/micropython/micropython/pull/4115. Initial import of code is from: https://github.com/nickzoic/micropython/tree/espnow-4115.
* all: Fix spelling mistakes based on codespell check.Damien George2023-04-27
| | | | Signed-off-by: Damien George <damien@micropython.org>
* renesas-ra: Change MICROPY_HW_BOARD_NAME definition to product name.Takeo Takahashi2023-04-27
| | | | | | | | | | Changes in this commit: - Change MICROPY_HW_BOARD_NAME definition to match the product name. - Rename board folder's name to match the product name style. - Change related files like Makefile, document descriptions, test cases, CI and tools. Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
* tests/multi_bluetooth: Use multitest.broadcast instead of sleep.Jim Mussared2023-04-26
| | | | Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests/multi_bluetooth/ble_characteristic.py: Add write-no-response.Jim Mussared2023-04-26
| | | | Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests/multi_bluetooth: Add test for descriptors.Jim Mussared2023-04-26
| | | | Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests/multi_bluetooth/ble_subscribe: Use end_handle in desc discovery.Jim Mussared2023-04-26
| | | | | | Obtaining the end_handle was added in cacc96d9. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests/multi_bluetooth/ble_mtu: Split peripheral/central-initiated.Jim Mussared2023-04-26
| | | | | | | | btstack only supports central-initiated, so this allows us to have a test that works on both (ble_mtu.py), and then another one for just the NimBLE supported behavior (ble_mtu_peripheral.py). Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests/multi_bluetooth: Use time.sleep_ms instead of time.sleep.Jim Mussared2023-04-26
| | | | | | | On unix, time.sleep is implemented as select(timeout=<time>) which means that it does not run the poll hook during sleeping. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests/extmod/vfs_fat_ilistdir_del.py: Use 512-byte erase block size.Damien George2023-03-29
| | | | | | | Following other vfs_fat tests, so the test works on ports like stm32 that only support 512-byte block size. Signed-off-by: Damien George <damien@micropython.org>
* tests/multi_bluetooth: Use multitest.output_metric in BLE perf tests.Damien George2023-03-23
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/run-multitests.py: Support outputting test metrics.Damien George2023-03-23
| | | | | | | | | | If a multitest calls `multitest.output_metric(...)` then that output will be collected separately, not considered as part of the test verification output, and instead be printed at the end. This is useful for tests that want to output performance/timing metrics that may change from one run to the next. Signed-off-by: Damien George <damien@micropython.org>
* extmod/vfs_posix: Do not filter '..*' in ilistdir when filtering '..'.Jeremy Rand2023-03-21
| | | | | | | | | | | When iterating over os.ilistdir(), the special directories '.' and '..' are filtered from the results. But the code inadvertently also filtered any file/directory which happened to match '..*'. This change fixes the filter. Fixes issue #11032. Signed-off-by: Jeremy Rand <jeremy@rand-family.com>
* py/compile: Fix scope of assignment expression target in comprehensions.Damien George2023-03-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When := is used in a comprehension the target variable is bound to the parent scope, so it's either a global or a nonlocal. Prior to this commit that was handled by simply using the parent scope's id_info for the target variable. That's completely wrong because it uses the slot number for the parent's Python stack to store the variable, rather than the slot number for the comprehension. This will in most cases lead to incorrect behaviour or memory faults. This commit fixes the scoping of the target variable by explicitly declaring it a global or nonlocal, depending on whether the parent is the global scope or not. Then the id_info of the comprehension can be used to access the target variable. This fixes a lot of cases of using := in a comprehension. Code size change for this commit: bare-arm: +0 +0.000% minimal x86: +0 +0.000% unix x64: +152 +0.019% standard stm32: +96 +0.024% PYBV10 cc3200: +96 +0.052% esp8266: +196 +0.028% GENERIC esp32: +156 +0.010% GENERIC[incl +8(data)] mimxrt: +96 +0.027% TEENSY40 renesas-ra: +88 +0.014% RA6M2_EK nrf: +88 +0.048% pca10040 rp2: +104 +0.020% PICO samd: +88 +0.033% ADAFRUIT_ITSYBITSY_M4_EXPRESS Fixes issue #10895. Signed-off-by: Damien George <damien@micropython.org>
* tests/multi_bluetooth: Add bluetooth multi-test for deepsleep.Andrew Leech2023-03-08
| | | | Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
* tests/run-multitests.py: Add ability to test instance over reboot.Andrew Leech2023-03-08
| | | | | | | The device-under-test should use `multitest.expect_reboot()` to indicate that it will reboot. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
* py/modmath: Fix two-argument math function domain check.Damien George2023-02-24
| | | | | | | | | | | | | | | | Prior to this fix, pow(1.5, inf) and pow(0.5, -inf) (among other things) would incorrectly raise a ValueError, because the result is inf with the first argument being finite. This commit fixes this by allowing the result to be infinite if the first or second (or both) argument is infinite. This fix doesn't affect the other three math functions that have two arguments: - atan2 never returns inf, so always fails isinf(ans) - copysign returns inf only if the first argument x is inf, so will never reach the isinf(y) check - fmod never returns inf, so always fails isinf(ans) Signed-off-by: Damien George <damien@micropython.org>
* tests/float: Make output of math function tests more readable.Damien George2023-02-16
| | | | | | By explicitly naming the function, its arguments, and result. Signed-off-by: Damien George <damien@micropython.org>
* tests/float: Add domain checks for log and also -inf.Damien George2023-02-16
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/micropython: Split viper_misc test into two files.Damien George2023-02-09
| | | | | | | | So it can run on targets with low memory, eg esp8266. Also enable the viper_4args() sub-test, which is now supported. Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Skip vfs tests if target doesn't have enough memory.Damien George2023-02-09
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Get DecompIO test running on low-memory targets.Damien George2023-02-09
| | | | | | By changing the zlib header so that it uses a small (256 byte) window. Signed-off-by: Damien George <damien@micropython.org>
* tests/float: Skip new complex tests if complex unavailable.Damien George2023-02-09
| | | | | | These complex tests were recently added. Signed-off-by: Damien George <damien@micropython.org>
* top: Update Python formatting to black "2023 stable style".Jim Mussared2023-02-02
| | | | | | See https://black.readthedocs.io/en/stable/the_black_code_style/index.html Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/objint_mpz: Catch and reject @ and @= operating on big integers.Damien George2023-01-23
| | | | | | | | This will also catch / and /= when float support is disabled. Fixes issue #10544. Signed-off-by: Damien George <damien@micropython.org>
* py/lexer: Wrap in parenthesis all f-string arguments passed to format.Jim Mussared2023-01-20
| | | | | | | | | | | | | | This is important for literal tuples, e.g. f"{a,b,}, {c}" --> "{}".format((a,b), (c),) which would otherwise result in either a syntax error or the wrong result. Fixes issue #9635. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/objarray: Raise error on out-of-bound memoryview slice start.Andrew Leech2023-01-20
| | | | | | | | | | | 32-bit platforms only support a slice offset start of 24 bit max due to the limited size of the mp_obj_array_t.free member. Similarly on 64-bit platforms the limit is 56 bits. This commit adds an OverflowError if the user attempts to slice a memoryview beyond this limit. Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod/ure_namedclass: Add tests for named classes in class sets.Damien George2023-01-18
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/emitnative: Initialise locals as Python object type for native code.Damien George2022-12-16
| | | | | | | | | In @micropython.native code the types of variables and expressions are always Python objects, so they can be initialised as such. This prevents problems with compiling optimised code like while-loops where a local may be referenced before it is assigned to. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modussl_mbedtls: Fix support for ioctl(MP_STREAM_POLL).Damien Tournoud2022-12-15
| | | | | | | | | | | | | | | | | During the initial handshake or subsequent renegotiation, the protocol might need to read in order to write (or conversely to write in order to read). It might be blocked from doing so by the state of the underlying socket (i.e. there is no data to read, or there is no space to write). The library indicates this condition by returning one of the errors `MBEDTLS_ERR_SSL_WANT_READ` or `MBEDTLS_ERR_SSL_WANT_WRITE`. When that happens, we need to enforce that the next poll operation only considers the direction that the library indicated. In addition, mbedtls does its own read buffering that we need to take into account while polling, and we need to save the last error between read()/write() and ioctl().
* tests/unix/mod_os: Add test for os module.David Lechner2022-12-14
| | | | | | | This adds a test to get coverage of the unix port-specific implementation of the `os` module. Signed-off-by: David Lechner <david@pybricks.com>
* unix/moduos: Implement 2-arg version of os.getenv().David Lechner2022-12-14
| | | | | | This adds the `default` argument of `os.getenv(key, default=None)`. Signed-off-by: David Lechner <david@pybricks.com>
* all: Keep msvc build output in build/ directories.stijn2022-12-13
| | | | This follow the change made for Makefile-based projects in b2e82402.
* tests/extmod/framebuf_scroll: Add tests for FrameBuffer scrolling.TPReal2022-12-09
| | | | | Includes a currently-failing test of scrolling by at least the size of the buffer.