non_compliant.py 3.3 KB

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