Skip to content
Snippets Groups Projects
Commit 86c75072 authored by Rami Ali's avatar Rami Ali Committed by Damien George
Browse files

tests/cpydiff: Add initial set of tests for uPy-CPython differences.

These tests are intended to fail, as they provide a programatic record of
differences between uPy and CPython.  They also contain a special comment
at the start of the file which has meta-data describing the difference,
including known causes and known workarounds.
parent 89267886
No related branches found
No related tags found
No related merge requests found
Showing
with 243 additions and 0 deletions
"""
categories: Core
description: Error messages may display incorrect argument counts
cause: Unknown
workaround: Unknown
"""
try:
[].append()
except Exception as e:
print(e)
"""
categories: Core,Classes
description: Special method __del__ not implemented for user-defined classes
cause: Unknown
workaround: Unknown
"""
import gc
class Foo():
def __del__(self):
print('__del__')
f = Foo()
del f
gc.collect()
"""
categories: Core,Classes
description: Bug when using "super" as a local
cause: Unknown
workaround: Unknown
"""
class A:
def foo(self):
super = [1]
super.pop()
print(super)
A().foo()
"""
categories: Core,Classes
description: When inheriting from multiple classes super() only calls one class
cause: Depth first non-exhaustive method resolution order
workaround: Unknown
"""
class A:
def __init__(self):
print("A.__init__")
class B(A):
def __init__(self):
print("B.__init__")
super().__init__()
class C(A):
def __init__(self):
print("C.__init__")
super().__init__()
class D(B,C):
def __init__(self):
print("D.__init__")
super().__init__()
D()
"""
categories: Core,Classes
description: Calling super() getter property in subclass will return a property object, not the value
cause: Unknown
workaround: Unknown
"""
class A:
@property
def p(self):
return {"a":10}
class AA(A):
@property
def p(self):
return super().p
a = AA()
print(a.p)
"""
categories: Core,Functions
description: Assign instance variable to function
cause: Unknown
workaround: Unknown
"""
def f():
pass
f.x = 0
print(f.x)
"""
categories: Core,Functions
description: Unpacking function arguments in non-last position gives incorrect result
cause: Unknown
workaround: Unknown
"""
print(*(1, 2), 3)
"""
categories: Core,Generator
description: Context manager __exit__() not called in a generator which does not run to completion
cause: Unknown
workaround: Unknown
"""
class foo(object):
def __enter__(self):
print('Enter')
def __exit__(self, *args):
print('Exit')
def bar(x):
with foo():
while True:
x += 1
yield x
def func():
g = bar(0)
for _ in range(3):
print(next(g))
func()
"""
categories: Core,import
description: Failed to load modules are still registered as loaded
cause: Unknown
workaround: Unknown
"""
import sys
try:
from modules import foo
except NameError as e:
print(e)
try:
from modules import foo
print('Should not get here')
except NameError as e:
print(e)
"""
categories: Core
description: Method Resolution Order (MRO) is not compliant with CPython
cause: Unknown
workaround: Unknown
"""
class Foo:
def __str__(self):
return "Foo"
class C(tuple, Foo):
pass
t = C((1, 2, 3))
print(t)
print('foo')
xxx
"""
categories: Modules,array
description: Looking for integer not implemented
cause: Unknown
workaround: Unknown
"""
import array
print(1 in array.array('B', b'12'))
"""
categories: Modules,array
description: Array deletion not implemented
cause: Unknown
workaround: Unknown
"""
import array
a = array.array('b', (1, 2, 3))
del a[1]
print(a)
"""
categories: Modules,array
description: Subscript with step != 1 is not yet implemented
cause: Unknown
workaround: Unknown
"""
import array
a = array.array('b', (1, 2, 3))
print(a[3:2:2])
"""
categories: Modules,deque
description: Deque not implemented
cause: Unknown
workaround: Use regular queues or lists creatively
"""
import collections
D = collections.deque()
print(D)
"""
categories: Modules,json
description: JSON module does not throw exception when object is not serialisable
cause: Unknown
workaround: Unknown
"""
import json
a = bytes(x for x in range(256))
try:
z = json.dumps(a)
x = json.loads(z)
print('Should not get here')
except TypeError:
print('TypeError')
"""
categories: Modules,struct
description: Struct pack with too few args, not checked by uPy
cause: Unknown
workaround: Unknown
"""
import struct
try:
print(struct.pack('bb', 1))
print('Should not get here')
except:
print('struct.error')
"""
categories: Modules,struct
description: Struct pack with too many args, not checked by uPy
cause: Unknown
workaround: Unknown
"""
import struct
try:
print(struct.pack('bb', 1, 2, 3))
print('Should not get here')
except:
print('struct.error')
"""
categories: Modules,sys
description: Override sys.stdin, sys.stdout and sys.stderr. Impossible as they are stored in read-only memory.
cause: Unknown
workaround: Unknown
"""
import sys
sys.stdin = None
print(sys.stdin)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment