summaryrefslogtreecommitdiffstatshomepage
path: root/tests/misc
Commit message (Collapse)AuthorAge
* py/objstr: Support tuples and start/end args in startswith and endswith.Glenn Moloney2025-03-02
| | | | | | | | | | | | | | This change allows tuples to be passed as the prefix/suffix argument to the `str.startswith()` and `str.endswith()` methods. The methods will return `True` if the string starts/ends with any of the prefixes/suffixes in the tuple. Also adds full support for the `start` and `end` arguments to both methods for compatibility with CPython. Tests have been updated for the new behaviour. Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
* tests/misc/sys_settrace_features.py: Add note about CPython 3.12 issue.Angus Gratton2024-11-28
| | | | | | | | | | | | | CPython 3.12 has a documented issue with settrace for opcodes, apparently due to PEP 669. "This behavior will be changed back in 3.13 to be consistent with previous versions." No easy way to make the test pass on CPython 3.12, but at least this helps signal what the problem is to anyone who runs into a failure. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/objtype: Avoid crash on calling members of uninitialized native type.Laurens Valk2024-07-25
| | | | | | | | | | | | | When subclassing a native type, calling native members in `__init__` before `super().__init__()` has been called could cause a crash. In this situation, `self` in `mp_convert_member_lookup` is the `native_base_init_wrapper_obj`. The check added in this commit ensures that an `AttributeError` is raised before this happens, which is consistent with other failed lookups. Also fix a typo in a related comment. Signed-off-by: Laurens Valk <laurens@pybricks.com>
* examples/usercmodule/cexample: Add more advanced native class.Laurens Valk2024-07-25
| | | | | | | This adds a separate `AdvancedTimer` class that demonstrates a few more advanced concepts usch as custom handlers for printing and attributes. Signed-off-by: Laurens Valk <laurens@pybricks.com>
* all: Update Python formatting to ruff-format.Jim Mussared2023-11-03
| | | | | | | | | This updates a small number of files that change with ruff-format's (vs black's) rules. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/profile: Remove the requirement to disable MICROPY_COMP_CONST.Jim Mussared2023-08-30
| | | | | | | | | | | | | | | | The only reason that const had to be disabled was to make the test output match CPython when const was involved. Instead, this commit fixes the test to handle the lines where const is used. Also: - remove the special handling for MICROPY_PERSISTENT_CODE_SAVE in unix/mpconfigport.h, and make this automatic. - move the check for MICROPY_PERSISTENT_CODE_SAVE to where it's used (like we do for other similar checks) and add a comment explaining it. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests/misc/sys_settrace_features.py: Fix to run on newer CPython.Jim Mussared2023-08-30
| | | | | | | | | | | | | This test was failing on CPython 3.11 as it now emits `0` as the line number for the "call" event corresponding to import, where as in 3.6 it had `1` as the line number. We maintain the old behavior, but in order to make this test pass on both CPython versions, the trace handler now converts the `0` to a `1`. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests: Replace umodule with module everywhere.Jim Mussared2023-06-08
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Fix spelling mistakes based on codespell check.Damien George2023-04-27
| | | | 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>
* tests/misc/cexample_class: Fix timing sensitivity.Laurens Valk2022-11-25
| | | | | | | | This test could occasionally fail because some operations take longer than expected. This relaxes the timing constraints and defers printing until the very end. Signed-off-by: Laurens Valk <laurens@pybricks.com>
* tests/misc/cexample_module: Test class presence.Laurens Valk2022-11-25
| | | | | | | Now that the Timer class has been merged in a separate pull request, this can be added to the module test too. Signed-off-by: Laurens Valk <laurens@pybricks.com>
* examples/usercmodule: Add example of a native C class.Laurens Valk2022-11-23
| | | | | | | | This shows how ports can add their own custom types/classes. It is part of the unix coverage build, so we can use it for tests too. Signed-off-by: Laurens Valk <laurens@pybricks.com>
* tests/misc: Add test for cexample module.Laurens Valk2022-11-23
| | | | | | | This also moves the existing test for cexample.add_ints originally done in extra_coverage. Signed-off-by: Laurens Valk <laurens@pybricks.com>
* all: Update Python formatting to latest Black version 22.1.0.Damien George2022-02-02
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/misc/sys_settrace_features.py: Fix running with non-dflt encoding.stijn2020-12-18
| | | | | Notably git-cmd which comes with git installations on Windows alters the encoding resulting in CPython tracing encodings/cp1252.py calls.
* tests/misc/sys_settrace: Make test output independent of invoked path.stijn2020-12-18
| | | | | | | | | | | | The original logic of reducing a full path to a relative one assumes "tests/misc" is in the filename which is limited in usage: it never works for CPython on Windows since that will use a backslash as path separator, and also won't work when the filename is a path not relative to the tests directory which happens for example in the common case of running "./run-tests -d misc". Fix all cases by printing only the bare filename, which requires them all to start with sys_settrace_ hence the renaming.
* tests/misc/sys_settrace_features.py: Ignore CPython zipimport traces.Damien George2020-12-14
| | | | Signed-off-by: Damien George <damien@micropython.org>
* all: Rename "sys" module to "usys".stijn2020-09-04
| | | | | | | | | This is consistent with the other 'micro' modules and allows implementing additional features in Python via e.g. micropython-lib's sys. Note this is a breaking change (not backwards compatible) for ports which do not enable weak links, as "import sys" must now be replaced with "import usys".
* tests: Format all Python code with black, except tests in basics subdir.David Lechner2020-03-30
| | | | | | | | | | This adds the Python files in the tests/ directory to be formatted with ./tools/codeformat.py. The basics/ subdirectory is excluded for now so we aren't changing too much at once. In a few places `# fmt: off`/`# fmt: on` was used where the code had special formatting for readability or where the test was actually testing the specific formatting.
* tests: Rename "array" module to "uarray".Damien George2019-10-22
|
* tests: Add tests for sys.settrace feature.Milan Rossa2019-08-30
|
* py/vm: Don't add traceback info for exceptions that are re-raised.Damien George2019-08-28
| | | | | | | | | With this patch exceptions that are re-raised have improved tracebacks (less confusing, match CPython), and it makes re-raise slightly more efficient (in time and RAM) because they no longer need to add a traceback. Also general VM performance is not measurably affected. Partially fixes issue #2928.
* py/vm: Don't add traceback info for exc's propagated through a finally.Damien George2019-08-28
| | | | | | | | With this patch exception tracebacks that go through a finally are improved (less confusing, match CPython), and it makes finally's slightly more efficient (in time and RAM) because they no longer need to add a traceback. Partially fixes issue #2928.
* tests/misc/sys_atexit: Add test for new sys.atexit feature.Milan Rossa2019-08-15
|
* tests: Make bytes/str.count() tests skippable.Paul Sokolovsky2018-10-22
|
* py: Shorten error messages by using contractions and some rewording.Damien George2018-09-20
|
* tests: Modify tests that print repr of an exception with 1 arg.Damien George2018-08-17
| | | | | | | | | | In Python 3.7 the behaviour of repr() of an exception with one argument changed: it no longer prints a trailing comma in the argument list. See https://bugs.python.org/issue30399 This patch modifies tests that rely on this behaviour to not rely on it. And the python34.py test is updated to include a test for this behaviour with a .exp file.
* tests: Make tests work on targets without float support.Ayke van Laethem2018-08-04
|
* tests: Add tests using "file" argument in print and sys.print_exception.Damien George2018-06-20
|
* py/objtype: Optimise instance get/set/del by skipping special accessors.Damien George2018-06-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch is a code optimisation, trading text bytes for speed. On pyboard it's an increase of 0.06% in code size for a gain (in pystone performance) of roughly 6.5%. The patch optimises load/store/delete of attributes in user defined classes by not looking up special accessors (@property, __get__, __delete__, __set__, __setattr__ and __getattr_) if they are guaranteed not to exist in the class. Currently, if you do my_obj.foo() then the runtime has to do a few checks to see if foo is a property or has __get__, and if so delegate the call. And for stores things like my_obj.foo = 1 has to first check if foo is a property or has __set__ defined on it. Doing all those checks each and every time the attribute is accessed has a performance penalty. This patch eliminates all those checks for cases when it's guaranteed that the checks will always fail, ie no attributes are properties nor have any special accessor methods defined on them. To make this guarantee it checks all attributes of a user-defined class when it is first created. If any of the attributes of the user class are properties or have special accessors, or any of the base classes of the user class have them, then it sets a flag in the class to indicate that special accessors must be checked for. Then in the load/store/delete code it checks this flag to see if it can take the shortcut and optimise the lookup. It's an optimisation that's pretty widely applicable because it improves lookup performance for all methods of user defined classes, and stores of attributes, at least for those that don't have special accessors. And, it allows to enable descriptors with minimal additional runtime overhead if they are not used for a particular user class. There is one restriction on dynamic class creation that has been introduced by this patch: a user-defined class cannot go from zero special accessors to one special accessor (or more) after that class has been subclassed. If the script attempts this an AttributeError is raised (see addition to tests/misc/non_compliant.py for an example of this case). The cost in code space bytes for the optimisation in this patch is: unix x64: +528 unix nanbox: +508 stm32: +192 cc3200: +200 esp8266: +332 esp32: +244 Performance tests that were done: - on unix x86-64, pystone improved by about 5% - on pyboard, pystone improved by about 6.5%, from 1683 up to 1794 - on pyboard, bm_chaos (from CPython benchmark suite) improved by about 5% - on esp32, pystone improved by about 30% (but there are caching effects) - on esp32, bm_chaos improved by about 11%
* tests: Move recursive tests to the tests/stress/ subdir.Damien George2018-04-10
| | | | | | Keeping all the stress related tests in one place makes it easier to stress-test a given port, and to also not run such tests on ports that can't handle them.
* tests: Add tests to improve coverage of py/objtype.c.Damien George2017-12-14
|
* py/objset: Check that RHS of a binary op is a set/frozenset.Damien George2017-10-03
| | | | | | | | | | CPython docs explicitly state that the RHS of a set/frozenset binary op must be a set to prevent user errors. It also preserves commutativity of the ops, eg: "abc" & set() is a TypeError, and so should be set() & "abc". This change actually decreases unix (x64) code by 160 bytes; it increases stm32 by 4 bytes and esp8266 by 28 bytes (but previous patch already introduced a much large saving).
* tests: Convert remaining "sys.exit()" to "raise SystemExit".Paul Sokolovsky2017-06-10
|
* tests/misc/: Make few tests skippable.Paul Sokolovsky2017-03-11
|
* tests/misc: Add test for line number printing with large bytecode chunk.Damien George2017-02-10
|
* tests/misc/non_compliant: Add test for inability to assign func attrs.Damien George2017-01-19
|
* tests: Add tests to improve coverage of objarray.c.Rami Ali2016-12-21
|
* tests: Improve coverage of array, range, dict, slice, exc, unicode.Damien George2016-10-17
|
* tests: Improve test coverage of py/compile.c.Damien George2016-10-11
|
* tests: Improve coverage of struct with test for non-compliant behaviour.Damien George2016-10-07
|
* tests/misc/non_compliant: Add tests to improve coverage testing.Damien George2016-08-15
|
* tests/recursive_iternext: Clang/Linux is even more stack-frugal than MacOS.Paul Sokolovsky2016-06-04
|
* tests/misc/recursive_iternext: Provide more fine-grained selection of N.Damien George2016-06-03
| | | | To work on a variety of ports the selection of N is very specific.
* tests/misc/recursive_iternext.py: Increase depth N from 1000 to 2000.Damien George2016-06-03
| | | | | This makes the test reliably overflow the recursion limit (which is the correct behaviour) on Mac OS X.
* tests: Make "io" modules fixes for CPython compatibility.Paul Sokolovsky2016-05-02
| | | | | | | Previously, "import _io" worked on both CPython and MicroPython (essentially by a chance on CPython, as there's not guarantee that its contents will stay the same across versions), but as the module was renamed to uio, need to use more robust import sequence for compatibility.
* tests: Update for _io/_collections module having been renamed.Paul Sokolovsky2016-05-02
|
* tests/recursive_iternext.py: Make low-heap friendly.Paul Sokolovsky2016-03-07
|
* tests/print_exception: Use exception which prints the same regardless of config.Paul Sokolovsky2016-03-07
| | | | | | NameError may either include offending name or not. Unfortunately, this change makes test float-dependent. And using integer division leads to different error message than CPython.