aboutsummaryrefslogtreecommitdiff
path: root/tests/basics
AgeCommit message (Collapse)Author
2018-02-19py/objstr: Protect against creating bytes(n) with n negative.Damien George
Prior to this patch uPy (on a 32-bit arch) would have severe issues when calling bytes(-1): such a call would call vstr_init_len(vstr, -1) which would then +1 on the len and call vstr_init(vstr, 0), which would then round this up and allocate a small amount of memory for the vstr. The bytes constructor would then attempt to zero out all this memory, thinking it had allocated 2^32-1 bytes.
2018-02-19py/modbuiltins: Simplify and generalise dir() by probing qstrs.Damien George
This patch improves the builtin dir() function by probing the target object with all possible qstrs via mp_load_method_maybe. This is very simple (in terms of implementation), doesn't require recursion, and allows to list all methods of user-defined classes (without duplicates) even if they have multiple inheritance with a common parent. The downside is that it can be slow because it has to iterate through all the qstrs in the system, but the "dir()" function is anyway mostly used for testing frameworks and user introspection of types, so speed is not considered a priority. In addition to providing a more complete implementation of dir(), this patch is simpler than the previous implementation and saves some code space: bare-arm: -80 minimal x86: -80 unix x64: -56 unix nanbox: -48 stm32: -80 cc3200: -80 esp8266: -104 esp32: -64
2018-02-18py/objdict: Disallow possible modifications to fixed dicts.Mike Wadsten
2018-02-14py/objrange: Implement (in)equality comparison between range objects.Damien George
This feature is not often used so is guarded by the config option MICROPY_PY_BUILTINS_RANGE_BINOP which is disabled by default. With this option disabled MicroPython will always return false when comparing two range objects for equality (unless they are exactly the same object instance). This does not match CPython so if (in)equality between range objects is needed then this option should be enabled. Enabling this option costs between 100 and 200 bytes of code space depending on the machine architecture.
2018-02-14tests: Rewrite some tests so they can run without needing eval/exec.Damien George
For builds without the compiler enabled (and hence without eval/exec) it is useful to still be able to run as many tests as possible.
2018-02-14tests: Automatically skip tests that require eval, exec or frozenset.Damien George
2018-02-07tests/basics: Rename remaining tests that are for built-in functions.Damien George
For consistency with all of the other tests that are named builtin_XXX.py.
2018-02-07py/objtype: Check and prevent delete/store on a fixed locals map.Damien George
Note that the check for elem!=NULL is removed for the MP_MAP_LOOKUP_ADD_IF_NOT_FOUND case because mp_map_lookup will always return non-NULL for such a case.
2017-12-20tests/basics/memoryerror: Add test for out-of-memory using realloc.Damien George
2017-12-19tests: Add some more tests to improve coverage of py/parse.c.Damien George
2017-12-19tests/basics/builtin_pow3: Add tests for edge cases of pow3.Damien George
2017-12-19tests/basics/generator_pend_throw: Add test for just-started generator.Damien George
2017-12-19tests/basics: Add more set tests to improve coverage of py/objset.c.Damien George
2017-12-15py/objgenerator: Allow to pend an exception for next execution.Paul Sokolovsky
This implements .pend_throw(exc) method, which sets up an exception to be triggered on the next call to generator's .__next__() or .send() method. This is unlike .throw(), which immediately starts to execute the generator to process the exception. This effectively adds Future-like capabilities to generator protocol (exception will be raised in the future). The need for such a method arised to implement uasyncio wait_for() function efficiently (its behavior is clearly "Future" like, and normally would require to introduce an expensive Future wrapper around all native couroutines, like upstream asyncio does). py/objgenerator: pend_throw: Return previous pended value. This effectively allows to store an additional value (not necessary an exception) in a coroutine while it's not being executed. uasyncio has exactly this usecase: to mark a coro waiting in I/O queue (and thus not executed in the normal scheduling queue), for the purpose of implementing wait_for() function (cancellation of such waiting coro by a timeout).
2017-12-14tests: Add tests to improve coverage of py/objtype.c.Damien George
2017-12-12tests: Fix few test for proper "skipped" detection with qemu-arm's tinytest.Paul Sokolovsky
"Builtin" tinytest-based testsuite as employed by qemu-arm (and now generalized by me to be reusable for other targets) performs simplified detection of skipped tests, it treats as such tests which raised SystemExit (instead of checking got "SKIP" output). Consequently, each "SKIP" must be accompanied by SystemExit (and conversely, SystemExit should not be used if test is not skipped, which so far seems to be true).
2017-12-12tests/basics: Add test for overriding a native base-class's init method.Damien George
2017-11-27tests/basics/builtin_locals: Add test for using locals() in class body.Damien George
2017-11-24tests/basics/builtin_range: Add test for corner case of range slicing.Damien George
2017-11-24tests/basics: Add test for containment of a subclass of a native type.Damien George
2017-11-12py/objnamedtuple: Add _asdict function if OrderedDict is supportedstijn
2017-10-04py/objstr: Make empty bytes object have a null-terminating byte.Damien George
Because a lot of string processing functions assume there is a null terminating byte, so they can work in an efficient way. Fixes issue #3334.
2017-10-03py/objset: Include the failed key in a KeyError raised from set.remove.Damien George
2017-10-03py/objset: Check that RHS of a binary op is a set/frozenset.Damien George
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).
2017-09-19py/objstr: strip: Don't strip "\0" by default.Paul Sokolovsky
An issue was due to incorrectly taking size of default strip characters set.
2017-09-10tests/class_reverse_op: Test for reverse arith ops special methods.Paul Sokolovsky
This test should be run only if support for reverse ops is enabled, so the corresponding feature_check is added to run-tests.
2017-09-07py/objlist: Properly implement comparison with incompatible types.Paul Sokolovsky
Should raise TypeError, unless it's (in)equality comparison.
2017-09-06py/objtuple: Properly implement comparison with incompatible types.Paul Sokolovsky
Should raise TypeError, unless it's (in)equality comparison.
2017-09-04tests/class_inplace_op: Test for inplace op fallback to normal one.Paul Sokolovsky
2017-09-01py/modstruct: Check and prevent buffer-write overflow in struct packing.Damien George
Prior to this patch, the size of the buffer given to pack_into() was checked for being too small by using the count of the arguments, not their actual size. For example, a format spec of '4I' would only check that there was 4 bytes available, not 16; and 'I' would check for 1 byte, not 4. The pack() function is ok because its buffer is created to be exactly the correct size. The fix in this patch calculates the total size of the format spec at the start of pack_into() and verifies that the buffer is large enough. This adds some computational overhead, to iterate through the whole format spec. The alternative is to check during the packing, but that requires extra code to handle alignment, and the check is anyway not needed for pack(). So to maintain minimal code size the check is done using struct_calcsize.
2017-09-01py/modstruct: Check and prevent buffer-read overflow in struct unpackingDamien George
Prior to this patch, the size of the buffer given to unpack/unpack_from was checked for being too small by using the count of the arguments, not their actual size. For example, a format spec of '4I' would only check that there was 4 bytes available, not 16; and 'I' would check for 1 byte, not 4. This bug is fixed in this patch by calculating the total size of the format spec at the start of the unpacking function. This function anyway needs to calculate the number of items at the start, so calculating the total size can be done at the same time.
2017-09-01py/modstruct: In struct.pack, stop converting if there are no args left.Damien George
This patch makes a repeat counter behave the same as repeating the typecode, when there are not enough args. For example: struct.pack('2I', 1) now behave the same as struct.pack('II', 1).
2017-09-01tests/class_new: Add another testcase for __new__/__init__ interaction.Paul Sokolovsky
Similar to the existing testcase, but test that returning both value of native type and instance of another user class from __new__ lead to __init__ not being called, for better coverage.
2017-08-30tests/class_new: Add checks for __init__ being called and other improvements.Paul Sokolovsky
2017-08-30tests/object_new: Better messages, check user __new__() method.Paul Sokolovsky
Make messages more verbose and easier to follow and check that user class' __new__() is not called by object.__new__(user_class).
2017-08-30py/objtype: Handle NotImplemented return from binary special methods.Paul Sokolovsky
NotImplemented means "try other fallbacks (like calling __rop__ instead of __op__) and if nothing works, raise TypeError". As MicroPython doesn't implement any fallbacks, signal to raise TypeError right away.
2017-08-29py/objstr: startswith, endswith: Check arg to be a string.Paul Sokolovsky
Otherwise, it will silently get incorrect result on other values types, including CPython tuple form like "foo.png".endswith(("png", "jpg")) (which MicroPython doesn't support for unbloatedness).
2017-08-17py/binary: Change internal bytearray typecode from 0 to 1.Damien George
The value of 0 can't be used because otherwise mp_binary_get_size will let a null byte through as the type code (intepreted as byterray). This can lead to invalid type-specifier strings being let through without an error in the struct module, and even buffer overruns.
2017-08-15py/binary.c: Fix bug when packing big-endian 'Q' values.Bas van Sisseren
Without bugfix: struct.pack('>Q', 16) b'\x00\x00\x00\x10\x00\x00\x00\x00' With bugfix: struct.pack('>Q', 16) b'\x00\x00\x00\x00\x00\x00\x00\x10'
2017-08-09py/objstr: Raise an exception for wrong type on RHS of str binary op.Damien George
The main case to catch is invalid types for the containment operator, of the form str.__contains__(non-str).
2017-08-09py/objtuple: Allow to use inplace-multiplication operator on tuples.Damien George
2017-07-31all: Use the name MicroPython consistently in commentsAlexander Steffen
There were several different spellings of MicroPython present in comments, when there should be only one.
2017-07-21tests/basics/builtin_exec: Test various globals/locals args to exec().Tom Collins
2017-07-21tests: Rename exec1.py to builtin_exec.py.Damien George
2017-07-07py/objgenerator: Allow to hash generators and generator instances.Damien George
Adds nothing to the code size, since it uses existing empty slots in the type structures.
2017-07-05tests/basics: Add tests for arithmetic operators precedence.Krzysztof Blazewicz
2017-06-29tests/basics/namedtuple1: Add test for creating with pos and kw args.Damien George
2017-06-22tests/basics: Add tests for for-else statement.Damien George
2017-06-15py/objint: In to_bytes(), allow length arg to be any int and check sign.Damien George
2017-06-15py/objint: Support "big" byte-order in int.to_bytes().Damien George