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 188 additions and 0 deletions
"""
categories: Syntax,Spaces
description: uPy requires spaces between literal numbers and keywords, CPy doesn't
cause: Unknown
workaround: Unknown
"""
try:
print(eval('1and 0'))
except SyntaxError:
print('Should have worked')
try:
print(eval('1or 0'))
except SyntaxError:
print('Should have worked')
try:
print(eval('1if 1else 0'))
except SyntaxError:
print('Should have worked')
"""
categories: Syntax,Unicode
description: Unicode name escapes are not implemented
cause: Unknown
workaround: Unknown
"""
print("\N{LATIN SMALL LETTER A}")
"""
categories: Types,bytearray
description: Array slice assignment with unsupported RHS
cause: Unknown
workaround: Unknown
"""
b = bytearray(4)
b[0:1] = [1, 2]
print(b)
"""
categories: Types,bytes
description: bytes(...) with keywords not implemented
cause: Unknown
workaround: Input the encoding format directly. eg. ``print(bytes('abc', 'utf-8'))``
"""
print(bytes('abc', encoding='utf8'))
"""
categories: Types,bytes
description: Bytes subscr with step != 1 not implemented
cause: Unknown
workaround: Unknown
"""
print(b'123'[0:3:2])
"""
categories: Types,Exception
description: Exception chaining not implemented
cause: Unknown
workaround: Unknown
"""
try:
raise TypeError
except TypeError:
raise ValueError
"""
categories: Types,Exception
description: Assign instance variable to exception
cause: Unknown
workaround: Unknown
"""
e = Exception()
e.x = 0
print(e.x)
"""
categories: Types,Exception
description: While loop guards will obscure exception line number reporting due to being optimised onto the end of the code block
cause: Unknown
workaround: Unknown
"""
l = ["-foo", "-bar"]
i = 0
while l[i][0] == "-":
print("iter")
i += 1
"""
categories: Types,Exception
description: Exception.__init__ raises TypeError if overridden and called by subclass
cause: Unknown
workaround: Unknown
"""
class A(Exception):
def __init__(self):
Exception.__init__(self)
a = A()
"""
categories: Types,float
description: uPy and CPython outputs formats differ
cause: Unknown
workaround: Unknown
"""
print('%.1g' % -9.9)
print('%.1e' % 9.99)
print('%.1e' % 0.999)
"""
categories: Types,int
description: No int conversion for int-derived types available
cause: Unknown
workaround: Unknown
"""
class A(int):
__add__ = lambda self, other: A(int(self) + other)
a = A(42)
print(a+a)
"""
categories: Types,int
description: Incorrect error message when passing float into to_bytes
cause: Unknown
workaround: Unknown
"""
try:
int('1').to_bytes(1.0)
except TypeError as e:
print(e)
"""
categories: Types,list
description: List delete with step != 1 not implemented
cause: Unknown
workaround: Unknown
"""
l = [1, 2, 3, 4]
del l[0:4:2]
print(l)
"""
categories: Types,list
description: List store with step != 1 not implemented
cause: Unknown
workaround: Unknown
"""
l = [1, 2, 3, 4]
l[0:4:2] = [5, 6]
print(l)
"""
categories: Types,str
description: UnicodeDecodeError not raised when expected
cause: Unknown
workaround: Unknown
"""
try:
print(repr(str(b"\xa1\x80", 'utf8')))
print('Should not get here')
except UnicodeDecodeError:
print('UnicodeDecodeError')
"""
categories: Types,str
description: Start/end indices such as str.endswith(s, start) not implemented
cause: Unknown
workaround: Unknown
"""
print('abc'.endswith('c', 1))
"""
categories: Types,str
description: Attributes/subscr not implemented
cause: Unknown
workaround: Unknown
"""
print('{a[0]}'.format(a=[1, 2]))
"""
categories: Types,str
description: str(...) with keywords not implemented
cause: Unknown
workaround: Input the encoding format directly. eg ``print(bytes('abc', 'utf-8'))``
"""
print(str(b'abc', encoding='utf8'))
"""
categories: Types,str
description: None as first argument for rsplit such as str.rsplit(None, n) not implemented
cause: Unknown
workaround: Unknown
"""
print('a a a'.rsplit(None, 1))
"""
categories: Types,str
description: Instance of a subclass of str cannot be compared for equality with an instance of a str
cause: Unknown
workaround: Unknown
"""
class S(str):
pass
s = S('hello')
print(s == 'hello')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment