aboutsummaryrefslogtreecommitdiff
path: root/tests/import
AgeCommit message (Collapse)Author
2020-07-26tests: Move .mpy import tests from import/ to micropython/ dir.Damien George
These tests are specific to MicroPython so have a better home in the micropython/ test subdir, and putting them here allows them to be run by all targets, not just those that have access to the local filesystem (eg the unix port). Signed-off-by: Damien George <damien@micropython.org>
2020-03-30tests: Format all Python code with black, except tests in basics subdir.David Lechner
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.
2019-12-13tests: Add .exp files for basics/parser and import/import_override.Damien George
Because CPython 3.8.0 now produces different output: - basics/parser.py: CPython does not allow '\\\n' as input. - import/import_override: CPython imports _io.
2019-12-12tests/import: Add test for importing viper code with additional flags.Damien George
2019-11-26py/builtinimport: Raise exception on empty module name.Léa Saviot
To prevent a crash returning MP_OBJ_NULL. A test is added for this case.
2019-10-15py/persistentcode: Make .mpy more compact with qstr directly in prelude.Damien George
Instead of encoding 4 zero bytes as placeholders for the simple_name and source_file qstrs, and storing the qstrs after the bytecode, store the qstrs at the location of these 4 bytes. This saves 4 bytes per bytecode function stored in a .mpy file (for example lcd160cr.mpy drops by 232 bytes, 4x 58 functions). And resulting code size is slightly reduced on ports that use this feature.
2019-10-04py/compile: Disallow 'import *' outside module level.Petr Viktorin
This check follows CPython's behaviour, because 'import *' always populates the globals with the imported names, not locals. Since it's safe to do this (doesn't lead to a crash or undefined behaviour) the check is only enabled for MICROPY_CPYTHON_COMPAT. Fixes issue #5121.
2019-10-01py: Rework and compress second part of bytecode prelude.Damien George
This patch compresses the second part of the bytecode prelude which contains the source file name, function name, source-line-number mapping and cell closure information. This part of the prelude now begins with a single varible length unsigned integer which encodes 2 numbers, being the byte-size of the following 2 sections in the header: the "source info section" and the "closure section". After decoding this variable unsigned integer it's possible to skip over one or both of these sections very easily. This scheme saves about 2 bytes for most functions compared to the original format: one in the case that there are no closure cells, and one because padding was eliminated.
2019-10-01py: Compress first part of bytecode prelude.Damien George
The start of the bytecode prelude contains 6 numbers telling the amount of stack needed for the Python values and exceptions, and the signature of the function. Prior to this patch these numbers were all encoded one after the other (2x variable unsigned integers, then 4x bytes), but using so many bytes is unnecessary. An entropy analysis of around 150,000 bytecode functions from the CPython standard library showed that the optimal Shannon coding would need about 7.1 bits on average to encode these 6 numbers, compared to the existing 48 bits. This patch attempts to get close to this optimal value by packing the 6 numbers into a single, varible-length unsigned integer via bit-wise interleaving. The interleaving scheme is chosen to minimise the average number of bytes needed, and at the same time keep the scheme simple enough so it can be implemented without too much overhead in code size or speed. The scheme requires about 10.5 bits on average to store the 6 numbers. As a result most functions which originally took 6 bytes to encode these 6 numbers now need only 1 byte (in 80% of cases).
2019-09-26py/persistentcode: Bump .mpy version to 5.Damien George
The bytecode opcodes have changed (there are more, and they have been reordered).
2019-09-26tests: Update tests for changes to opcode ordering.Damien George
2019-07-31tests: Add tests for overriding builtins.__import__.Damien George
2019-03-08tests/import: Add test for importing x64 native code.Damien George
2019-03-05py/persistentcode: Add a qstr window to save mpy files more efficiently.Damien George
This is an implementation of a sliding qstr window used to reduce the number of qstrs stored in a .mpy file. The window size is configured to 32 entries which takes a fixed 64 bytes (16-bits each) on the C stack when loading/saving a .mpy file. It allows to remember the most recent 32 qstrs so they don't need to be stored again in the .mpy file. The qstr window uses a simple least-recently-used mechanism to discard the least recently used qstr when the window overflows (similar to dictionary compression). This scheme only needs a single pass to save/load the .mpy file. Reduces mpy file size by about 25% with a window size of 32.
2018-11-01tests/import_long_dyn: Test for "import *" of a long dynamic name.Paul Sokolovsky
Such names aren't stored as qstr in module dict, and there was a bug in "import *" handling which assumed any name in a module dict is a qstr.
2018-10-23tests/import: Add .exp file for module_getattr.py to not require Py 3.7.Damien George
2018-10-23py/objmodule: Implement PEP 562's __getattr__ for modules.Paul m. p. P
Configurable via MICROPY_MODULE_GETATTR, disabled by default. Among other things __getattr__ for modules can help to build lazy loading / code unloading at runtime.
2018-06-18tests/import: Add test for importing invalid .mpy file.Damien George
2017-06-28tests/import: Update comment now that uPy raises correct exception.Damien George
2017-06-28tests/import: Add a test for the builtin __import__ function.Damien George
2017-01-16py/builtinimport: Raise ValueError for bad relative import, per CPython.Damien George
2017-01-16tests/import: Improve builtinimport.c test coverage.Rami Ali
2016-12-21tests/import: Add a test which uses ... in from-import statement.Damien George
2016-10-11tests: Improve test coverage of py/compile.c.Damien George
2016-09-30tests/import: Add test for compiling "import a.b as c".Damien George
2015-06-27tests: Add test for relative import without package context.Paul Sokolovsky
2015-02-16tests: Add another testcase for relative imports.Paul Sokolovsky
2014-07-28py: Implement __file__ attribute for modules.Paul Sokolovsky
2014-07-05tests: Rename test scripts, changing - to _ for consistency.Damien George
From now on, all new tests must use underscore. Addresses issue #727.
2014-04-17tests: Move gen_context to import tests, because it relies on import.Damien George
2014-04-17tests: Split out those tests requiring float and import.Damien George
Tests in basics (which should probably be renamed to core) should not rely on float, or import any non-built-in files. This way these tests can be run when those features are not available. All test in basics now pass on the pyboard using stmhal port, except for string-repr which has some issues with character hex printing.