aboutsummaryrefslogtreecommitdiff
path: root/tests/basics
AgeCommit message (Collapse)Author
2020-03-28tests/basics/dict_pop.py: Remove extra comma in call and fix grammar.David Lechner
2020-03-11py/objstringio: Expose tell() on StringIO and BytesIO objects.Andrew Leech
To match file objects. Fixes issue #5581.
2020-02-28py/builtinevex: Support passing in a bytearray/buffer to eval/exec.Damien George
CPython allows this and it's a simple generalisation of the existing code which just supported str/bytes. Fixes issue #5704.
2020-02-21tests/basics/array1.py: Add equality testing for array.Jim Mussared
2020-02-21py/objarray: Turn on MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE for memoryview.Jim Mussared
And add corresponding tests. Fixes #5674 (comparison of memoryview against bytes).
2020-02-20tests/basics: Add test for tuple compare with class derived from tuple.Damien George
Only the "==" operator was tested by the test suite in for such arguments. Other comparison operators like "<" take a different path in the code so need to be tested separately.
2020-02-11tests/basics: Add test for equality between tuple and namedtuple.Damien George
2020-02-11tests/basics: Add tests for equality between bool and int/float/complex.Damien George
False/True should be implicitly converted to 0/1 when compared with numeric types.
2020-02-06tests/basics: Move test for "return" outside function to own file.Petr Viktorin
Because its behaviour is conditional on MICROPY_CPYTHON_COMPAT.
2020-02-04tests: Move CPy diff test to real test now that subclass equality works.Damien George
Testing for equality of subclassed strings now works, thanks to commit 3aab54bf434e7f025a91ea05052f1bac439fad8c
2020-01-30tests/basics: Expand test cases for equality of subclasses.Nicko van Someren
2020-01-30py: Support non-boolean results for equality and inequality tests.Nicko van Someren
This commit implements a more complete replication of CPython's behaviour for equality and inequality testing of objects. This addresses the issues discussed in #5382 and a few other inconsistencies. Improvements over the old code include: - Support for returning non-boolean results from comparisons (as used by numpy and others). - Support for non-reflexive equality tests. - Preferential use of __ne__ methods and MP_BINARY_OP_NOT_EQUAL binary operators for inequality tests, when available. - Fallback to op2 == op1 or op2 != op1 when op1 does not implement the (in)equality operators. The scheme here makes use of a new flag, MP_TYPE_FLAG_NEEDS_FULL_EQ_TEST, in the flags word of mp_obj_type_t to indicate if various shortcuts can or cannot be used when performing equality and inequality tests. Currently four built-in classes have the flag set: float and complex are non-reflexive (since nan != nan) while bytearray and frozenszet instances can equal other builtin class instances (bytes and set respectively). The flag is also set for any new class defined by the user. This commit also includes a more comprehensive set of tests for the behaviour of (in)equality operators implemented in special methods.
2020-01-27tests: Add tests for generator throw and yield-from with exc handlers.Jim Mussared
This commit adds a generator test for throwing into a nested exception, and one when using yield-from with a pending exception cleanup. Both these tests currently fail on the native emitter, and are simplified versions of native test failures from uasyncio in #5332.
2020-01-24tests: Add boolean-as-integer formatting tests for fixed regression.Yonatan Goldschmidt
As suggested by @dpgeorge in #5538.
2019-12-28py/objslice: Add support for indices() method on slice objects.Nicko van Someren
Instances of the slice class are passed to __getitem__() on objects when the user indexes them with a slice. In practice the majority of the time (other than passing it on untouched) is to work out what the slice means in the context of an array dimension of a particular length. Since Python 2.3 there has been a method on the slice class, indices(), that takes a dimension length and returns the real start, stop and step, accounting for missing or negative values in the slice spec. This commit implements such a indices() method on the slice class. It is configurable at compile-time via MICROPY_PY_BUILTINS_SLICE_INDICES, disabled by default, enabled on unix, stm32 and esp32 ports. This commit also adds new tests for slice indices and for slicing unicode strings.
2019-12-27py/objsingleton: Use mp_generic_unary_op for singleton objects.Damien George
So these types more closely match NoneType, eg they can be hashed, like in CPython.
2019-12-21py/objobject: Add object.__delattr__ function.Yonatan Goldschmidt
Similar to object.__setattr__.
2019-12-21py/objobject: Add object.__setattr__ function.Yonatan Goldschmidt
Allows assigning attributes on class instances that implement their own __setattr__. Both object.__setattr__ and super(A, b).__setattr__ will work with this commit.
2019-12-13tests/basics/memoryview_itemsize: Make portable to 32- and 64-bit archs.Damien George
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-11-04py/modsys: Report .mpy version in sys.implementation.Damien George
This commit adds a sys.implementation.mpy entry when the system supports importing .mpy files. This entry is a 16-bit integer which encodes two bytes of information from the header of .mpy files that are supported by the system being run: the second and third bytes, .mpy version, and flags and native architecture. This allows determining the supported .mpy file dynamically by code, and also for the user to find it out by inspecting this value. It's further possible to dynamically detect if the system supports importing .mpy files by `hasattr(sys.implementation, 'mpy')`.
2019-11-04py/objgenerator: Allow pend_throw to an unstarted generator.Jim Mussared
Replace the is_running field with a tri-state variable to indicate running/not-running/pending-exception. Update tests to cover the various cases. This allows cancellation in uasyncio even if the coroutine hasn't been executed yet. Fixes #5242
2019-10-29tests/basics: Split sys.exit test to separate file so it can be skipped.Damien George
2019-10-29tests/basics: Automatically skip tests that use str/bytes modulo-format.Damien George
2019-10-29tests/basics: Split out specific slice tests to separate files.Damien George
So they can be automatically skipped if slice is not enabled.
2019-10-29tests/basics: Use bytes not bytearray when checking user buffer proto.Damien George
Using bytes will test the same path for the buffer protocol in py/objtype.c.
2019-10-29tests/basics: Split out specific bytearray tests to separate files.Damien George
So they can be automatically skipped if bytearray is not enabled.
2019-10-29tests/basics/builtin_dir.py: Look for "version" in dir(sys).Damien George
Because "version" will always be there, but "exit" may not.
2019-10-29tests/basics: Use str.format instead of % for formatting messages.Damien George
Only use % formatting when testing % itself, because only str.format is guaranteed to be available on any port.
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