aboutsummaryrefslogtreecommitdiff
path: root/tests/basics
AgeCommit message (Collapse)Author
2019-10-22tests: Rename "array" module to "uarray".Damien George
2019-10-18py/objtype: Add type.__bases__ attribute.Josh Lloyd
Enabled as part of MICROPY_CPYTHON_COMPAT.
2019-10-04tests/basics: Add test for throw into yield-from with normal return.Damien George
This test was found by missing coverage of a branch in py/nativeglue.c.
2019-10-04py/runtime: Fix PEP479 behaviour throwing StopIteration into yield from.Damien George
Commit 3f6ffe059f64b3ebc44dc0bbc63452cb8850702b implemented PEP479 but did not catch the case fixed in this commit. Found by coverage analysis, that the VM had uncovered code.
2019-10-04py/vm: Fix handling of unwind jump out of active finally.Damien George
Prior to this commit, when unwinding through an active finally the stack was not being correctly popped/folded, which resulting in the VM crashing for complicated unwinding of nested finallys. This should be fixed with this commit, and more tests for return/break/ continue within a finally have been added to exercise this.
2019-10-01tests/basics: Add test for getting name of func with closed over locals.Damien George
Tests correct decoding of the prelude to get the function name.
2019-09-26tests/basics: Add test for matmul operator.Damien George
This is a Python 3.5 feature so the .exp file is needed.
2019-09-02py/bc: Fix size calculation of UNWIND_JUMP opcode in mp_opcode_format.Damien George
Prior to this patch mp_opcode_format would calculate the incorrect size of the MP_BC_UNWIND_JUMP opcode, missing the additional byte. But, because opcodes below 0x10 are unused and treated as bytes in the .mpy load/save and freezing code, this bug did not show any symptoms, since nested unwind jumps would rarely (if ever) reach a depth of 16 (so the extra byte of this opcode would be between 0x01 and 0x0f and be correctly loaded/saved/frozen simply as an undefined opcode). This patch fixes this bug by correctly accounting for the additional byte. .
2019-09-02py/modstruct: Fix struct.pack_into with unaligned offset of native type.Damien George
Following the same fix for unpack.
2019-09-02py/modstruct: Fix struct.unpack with unaligned offset of native type.Tom McDermott
With this patch alignment is done relative to the start of the buffer that is being unpacked, not the raw pointer value, as per CPython. Fixes issue #3314.
2019-08-15py/objarray: Fix amount of free space in array when doing slice assign.Damien George
Prior to this patch the amount of free space in an array (including bytearray) was not being maintained correctly for the case of slice assignment which changed the size of the array. Under certain cases (as encoded in the new test) it was possible that the array could grow beyond its allocated memory block and corrupt the heap. Fixes issue #4127.
2019-07-31tests: Add tests for overriding builtins.__import__.Damien George
2019-05-21py/objarray: Add decode method to bytearray.stijn
Reuse the implementation for bytes since it works the same way regardless of the underlying type. This method gets added for CPython compatibility of bytearray, but to keep the code simple and small array.array now also has a working decode method, which is non-standard but doesn't hurt.
2019-05-14tests/basics: Add coverage tests for memoryview attributes.Damien George
2019-05-14py/objarray: Add support for memoryview.itemsize attribute.stijn
This allows figuring out the number of bytes in the memoryview object as len(memview) * memview.itemsize. The feature is enabled via MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE and is disabled by default.
2019-05-09py/objgenerator: Fix handling of None passed as 2nd arg to throw().Damien George
Fixes issue #4527.
2019-05-03tests/basics/sys1.py: Add test for calling sys.exit() without any args.Damien George
2019-04-28tests: Skip tests needing machine module if (u)machine doesn't exist.Damien George
2019-03-05py: Fix VM crash with unwinding jump out of a finally block.Damien George
This patch fixes a bug in the VM when breaking within a try-finally. The bug has to do with executing a break within the finally block of a try-finally statement. For example: def f(): for x in (1,): print('a', x) try: raise Exception finally: print(1) break print('b', x) f() Currently in uPy the above code will print: a 1 1 1 segmentation fault (core dumped) micropython Not only is there a seg fault, but the "1" in the finally block is printed twice. This is because when the VM executes a finally block it doesn't really know if that block was executed due to a fall-through of the try (no exception raised), or because an exception is active. In particular, for nested finallys the VM has no idea which of the nested ones have active exceptions and which are just fall-throughs. So when a break (or continue) is executed it tries to unwind all of the finallys, when in fact only some may be active. It's questionable whether break (or return or continue) should be allowed within a finally block, because they implicitly swallow any active exception, but nevertheless it's allowed by CPython (although almost never used in the standard library). And uPy should at least not crash in such a case. The solution here relies on the fact that exception and finally handlers always appear in the bytecode after the try body. Note: there was a similar bug with a return in a finally block, but that was previously fixed in b735208403a54774f9fd3d966f7c1a194c41870f
2019-02-26py/compile: Fix handling of unwinding BaseException in async with.Damien George
All exceptions that unwind through the async-with must be caught and BaseException is the top-level class, which includes Exception and others. Fixes issue #4552.
2019-02-21tests/basics: Add tests for try-except-else and try-except-else-finally.Damien George
2019-01-27py: Add optional support for 2-argument version of built-in next().stijn
Configurable via MICROPY_PY_BUILTINS_NEXT2, disabled by default.
2018-12-13tests/basics/special_methods2: Typo fix in comment.Paul Sokolovsky
2018-12-07tests/basics/special_methods: Add testcases for __int__.Paul Sokolovsky
2018-12-06py/objboundmeth: Support loading generic attrs from the method.Damien George
Instead of assuming that the method is a bytecode object, and only supporting load of __name__, make the operation generic by delegating the load to the method object itself. Saves a bit of code size and fixes the case of attempting to load __name__ on a native method, see issue #4028.
2018-10-28py/compile: Fix case of eager implicit conversion of local to nonlocal.Damien George
This ensures that implicit variables are only converted to implicit closed-over variables (nonlocals) at the very end of the function scope. If variables are closed-over when first used (read from, as was done prior to this commit) then this can be incorrect because the variable may be assigned to later on in the function which means they are just a plain local, not closed over. Fixes issue #4272.
2018-10-22tests: Make bytes/str.count() tests skippable.Paul Sokolovsky
2018-10-18tests/basics/class_getattr: Remove invalid test for __getattribute__.Damien George
Part of this test was trying to test some functionality of __getattribute__ but this method name was misspelt so it wasn't doing anything useful. Fixing the typo in this name makes the test fail because MicroPython doesn't support user defined __getattribute__ methods. So this part of the test is removed. The remaining tests are modified slightly to make it clearer what they are testing.
2018-10-18py/objtype: Remove comment about catching exc from user __getattr__.Damien George
Any exception raised in a user __getattr__ should be propagated out. A test is added to verify these semantics.
2018-09-28py/objtype: Support full object model for get/set/delitem special meths.Damien George
This makes these special methods have the same calling behaviour as other methods in a class instance (mp_convert_member_lookup() is already called by mp_obj_class_lookup()).
2018-09-28py/vm: Fix case of throwing GeneratorExit type into yield-from.Damien George
mp_make_raise_obj must be used to convert a possible exception type to an instance object, otherwise the VM may raise a non-exception object. An existing test is adjusted to test this case, with the original test already moved to generator_throw.py.
2018-09-28tests/basics: Split out gen throw tests from yield-from-throw tests.Damien George
2018-09-27py/objgenerator: Remove TODO about returning gen being called again.Damien George
The code implements correct behaviour, as tested by the new test case added in this commit.
2018-09-20py/objgenerator: Implement PEP479, StopIteration convs to RuntimeError.Damien George
This commit implements PEP479 which disallows raising StopIteration inside a generator to signal that it should be finished. Instead, the generator should simply return when it is complete. See https://www.python.org/dev/peps/pep-0479/ for details.
2018-09-11py/emitnative: Fix try-finally in outer scope, so finally is cancelled.Damien George
2018-09-11py/objarray: bytearray: Allow 2nd/3rd arg to constructor.Paul Sokolovsky
If bytearray is constructed from str, a second argument of encoding is required (in CPython), and third arg of Unicode error handling is allowed, e.g.: bytearray("str", "utf-8", "strict") This is similar to bytes: bytes("str", "utf-8", "strict") This patch just allows to pass 2nd/3rd arguments to bytearray, but doesn't try to validate them to not impact code size. (This is also similar to how bytes constructor is handled, though it does a bit more validation, e.g. check that in case of str arg, encoding argument is passed.)
2018-09-04tests/basics: Add test cases for context manager raising in enter/exit.Damien George
2018-09-04tests/basics: Add more tests for return within try-finally.Damien George
2018-09-03py/emitnative: Cancel caught exception once handled to prevent reraise.Damien George
The native emitter keeps the current exception in a slot in its C stack (instead of on its Python value stack), so when it catches an exception it must explicitly clear that slot so the same exception is not reraised later on.
2018-09-03py/vm: Fix handling of finally-return with complex nested finallys.Damien George
Back in 8047340d7532ec32bc9f2d603bffc0bc9544297f basic support was added in the VM to handle return statements within a finally block. But it didn't cover all cases, in particular when some finally's were active and others inactive when the "return" was executed. This patch adds further support for return-within-finally by correctly managing the currently_in_except_block flag, and should fix all cases. The main point is that finally handlers remain on the exception stack even if they are active (currently being executed), and the unwind return code should only execute those finally's which are inactive. New tests are added for the cases which now pass.
2018-08-17tests/basics: Provide .exp files for generator tests that fail PEP479.Damien George
PEP479 (see https://www.python.org/dev/peps/pep-0479/) prohibited raising StopIteration from within a generator (it is turned into a RuntimeError). This behaviour was introduced in Python 3.5 and in 3.7 was made compulsory. Until uPy implements PEP479, this patch adds .py.exp files for the relevant tests so they can be run under Python 3.7.
2018-08-17tests: Modify tests that print repr of an exception with 1 arg.Damien George
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.
2018-08-17tests/basics/int_big_error.py: Use bytearray to test for int overflow.Damien George
In Python 3.7 "1 >> (big int)" is now allowed, it no longer raises an OverflowError. So use bytearray to test big-int conversion overflow.
2018-08-17tests/basics/set_pop.py: Sort set before printing for consistent output.Damien George
2018-08-04tests: Make tests work on targets without float support.Ayke van Laethem
2018-07-10py/objgenerator: Implement __name__ with normal fun attr accessor code.Damien George
With the recent change b488a4a8480533a6a3c9468c2f8bd359c94d4d02, a generating function now has the same layout in memory as a normal bytecode function, and so can reuse the latter's attribute accessor code to implement __name__.
2018-06-27py/compile: Handle return/break/continue correctly in async with.Damien George
Before this patch the context manager's __aexit__() method would not be executed if a return/break/continue statement was used to exit an async with block. async with now has the same semantics as normal with. The fix here applies purely to the compiler, and does not modify the runtime at all. It might (eventually) be better to define new bytecode(s) to handle async with (and maybe other async constructs) in a cleaner, more efficient way. One minor drawback with addressing this issue purely in the compiler is that it wasn't possible to get 100% CPython semantics. The thing that is different here to CPython is that the __aexit__ method is not looked up in the context manager until it is needed, which is after the body of the async with statement has executed. So if a context manager doesn't have __aexit__ then CPython raises an exception before the async with is executed, whereas uPy will raise it after it is executed. Note that __aenter__ is looked up at the beginning in uPy because it needs to be called straightaway, so if the context manager isn't a context manager then it'll still raise an exception at the same location as CPython. The only difference is if the context manager has the __aenter__ method but not the __aexit__ method, then in that case uPy has different behaviour. But this is a very minor, and acceptable, difference.
2018-06-27tests: Move non-filesystem io tests to basics dir with io_ prefix.Damien George
2018-06-27tests/basics/namedtuple*: Import ucollections first.Paul Sokolovsky
Otherwise, test may have artefacts in the presence of the micropython-lib module.
2018-06-12py/lexer: Add support for underscores in numeric literals.Damien George
This is a very convenient feature introduced in Python 3.6 by PEP 515.