1# tests for things that are not implemented, or have non-compliant behaviour 2 3try: 4 import uarray as array 5 import ustruct 6except ImportError: 7 print("SKIP") 8 raise SystemExit 9 10# when super can't find self 11try: 12 exec("def f(): super()") 13except SyntaxError: 14 print("SyntaxError") 15 16# store to exception attribute is not allowed 17try: 18 ValueError().x = 0 19except AttributeError: 20 print("AttributeError") 21 22# array deletion not implemented 23try: 24 a = array.array("b", (1, 2, 3)) 25 del a[1] 26except TypeError: 27 print("TypeError") 28 29# slice with step!=1 not implemented 30try: 31 a = array.array("b", (1, 2, 3)) 32 print(a[3:2:2]) 33except NotImplementedError: 34 print("NotImplementedError") 35 36# containment, looking for integer not implemented 37try: 38 print(1 in array.array("B", b"12")) 39except NotImplementedError: 40 print("NotImplementedError") 41 42# uPy raises TypeError, shold be ValueError 43try: 44 "%c" % b"\x01\x02" 45except (TypeError, ValueError): 46 print("TypeError, ValueError") 47 48# attributes/subscr not implemented 49try: 50 print("{a[0]}".format(a=[1, 2])) 51except NotImplementedError: 52 print("NotImplementedError") 53 54# str(...) with keywords not implemented 55try: 56 str(b"abc", encoding="utf8") 57except NotImplementedError: 58 print("NotImplementedError") 59 60# str.rsplit(None, n) not implemented 61try: 62 "a a a".rsplit(None, 1) 63except NotImplementedError: 64 print("NotImplementedError") 65 66# str.endswith(s, start) not implemented 67try: 68 "abc".endswith("c", 1) 69except NotImplementedError: 70 print("NotImplementedError") 71 72# str subscr with step!=1 not implemented 73try: 74 print("abc"[1:2:3]) 75except NotImplementedError: 76 print("NotImplementedError") 77 78# bytes(...) with keywords not implemented 79try: 80 bytes("abc", encoding="utf8") 81except NotImplementedError: 82 print("NotImplementedError") 83 84# bytes subscr with step!=1 not implemented 85try: 86 b"123"[0:3:2] 87except NotImplementedError: 88 print("NotImplementedError") 89 90# tuple load with step!=1 not implemented 91try: 92 ()[2:3:4] 93except NotImplementedError: 94 print("NotImplementedError") 95 96# list store with step!=1 not implemented 97try: 98 [][2:3:4] = [] 99except NotImplementedError: 100 print("NotImplementedError") 101 102# list delete with step!=1 not implemented 103try: 104 del [][2:3:4] 105except NotImplementedError: 106 print("NotImplementedError") 107 108# struct pack with too many args, not checked by uPy 109print(ustruct.pack("bb", 1, 2, 3)) 110 111# struct pack with too few args, not checked by uPy 112print(ustruct.pack("bb", 1)) 113 114# array slice assignment with unsupported RHS 115try: 116 bytearray(4)[0:1] = [1, 2] 117except NotImplementedError: 118 print("NotImplementedError") 119 120# can't assign attributes to a function 121def f(): 122 pass 123 124 125try: 126 f.x = 1 127except AttributeError: 128 print("AttributeError") 129 130# can't call a function type (ie make new instances of a function) 131try: 132 type(f)() 133except TypeError: 134 print("TypeError") 135 136# test when object explicitly listed at not-last position in parent tuple 137# this is not compliant with CPython because of illegal MRO 138class A: 139 def foo(self): 140 print("A.foo") 141 142 143class B(object, A): 144 pass 145 146 147B().foo() 148 149# can't assign property (or other special accessors) to already-subclassed class 150class A: 151 pass 152 153 154class B(A): 155 pass 156 157 158try: 159 A.bar = property() 160except AttributeError: 161 print("AttributeError") 162