950_bugs.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. # multi-loop generator
  2. out = []
  3. args = map(lambda x: x+1, [1, 2, 3])
  4. for x in args:
  5. for y in args:
  6. out.append((x, y))
  7. assert out == [(2, 3), (2, 4)]
  8. # multi loop bug
  9. out = []
  10. a = [1, 2]
  11. for i in a:
  12. for j in a:
  13. out.append((i, j))
  14. assert (out == [(1, 1), (1, 2), (2, 1), (2, 2)]), out
  15. # https://github.com/pocketpy/pocketpy/issues/37
  16. mp = map(lambda x: x**2, [1, 2, 3, 4, 5] )
  17. assert list(mp) == [1, 4, 9, 16, 25]
  18. assert not 3>4
  19. def f(x):
  20. if x>1:
  21. return 1
  22. assert f(2) == 1
  23. assert f(0) == None
  24. a = [1, 2]
  25. b = [3, 4]
  26. assert a.append == a.append
  27. assert a.append is not a.append
  28. assert a.append is not b.append
  29. assert a.append != b.append
  30. inq = 0
  31. if not inq:
  32. assert True
  33. else:
  34. assert False
  35. a = object()
  36. b = object()
  37. if a is not b:
  38. assert True
  39. if a == 0:
  40. assert False
  41. def g(x):
  42. return x
  43. def f(x):
  44. return x
  45. assert (g(1), 2) == (1, 2)
  46. assert (
  47. g(1),
  48. 2
  49. ) == (1, 2)
  50. assert f((
  51. g(1),
  52. 2
  53. )) == (1, 2)
  54. def f():
  55. for i in range(4):
  56. _ = 0
  57. while i: i-=1
  58. f()
  59. # class A: a=b=1
  60. # class A: a, b = 1, 2
  61. bmi = 0.0
  62. def test(a):
  63. if a:
  64. bmi = 1.4
  65. return f'{bmi:.2f}'
  66. assert test(1) == '1.40'
  67. try:
  68. x = test(0)
  69. print('x:', x)
  70. exit(1)
  71. except UnboundLocalError:
  72. pass
  73. g = 1
  74. def f():
  75. global g
  76. g += 1
  77. f(); f()
  78. assert g == 3
  79. def f(**kw):
  80. x = 1
  81. y = 2
  82. return kw, x, y
  83. assert f(x=4, z=1) == ({'x': 4, 'z': 1}, 1, 2)
  84. def g(**kw):
  85. x, y = 1, 2
  86. return kw
  87. ret = g(
  88. a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9,
  89. j=10, k=11, l=12, m=13, n=14, o=15, p=16, q=17,
  90. r=18, s=19, t=20, u=21, v=22, w=23, x=24, y=25,
  91. z=26
  92. )
  93. assert ret == {chr(i+97): i+1 for i in range(26)}
  94. assert g(**ret) == ret
  95. assert g(**g(**ret)) == ret
  96. # other known issues:
  97. # 1. d.extend(d) if d is deque
  98. g = 0
  99. def test():
  100. global g
  101. g += 1
  102. return g
  103. a = [1, 10, 3]
  104. a[test()] += 1
  105. assert (a == [1, 11, 3]), a
  106. assert (g == 1), g
  107. assert list.__new__(list) == []
  108. assert a.__new__ == list.__new__
  109. class A:
  110. x: list[int] = [i for i in range(1, 4)]
  111. assert A.x == [1, 2, 3]
  112. # stable sort
  113. a = [(0, 1), (1, 1), (1, 2)]
  114. b = sorted(a, key=lambda x: x[0])
  115. if b != [(0, 1), (1, 1), (1, 2)]:
  116. assert False, b
  117. # https://github.com/pocketpy/pocketpy/issues/367
  118. a = 10 if False else 5
  119. assert a == 5
  120. a, b, c = (1, 2, 3) if True else (4, 5, 6)
  121. assert a == 1
  122. assert b == 2
  123. assert c == 3
  124. # https://github.com/pocketpy/pocketpy/issues/376
  125. xs = [0]
  126. res = []
  127. for x in xs:
  128. res.append(x)
  129. if x == 100:
  130. break
  131. xs.append(x+1)
  132. assert res == list(range(101))
  133. assert xs == res
  134. # call property
  135. from vmath import vec2
  136. a = vec2(1, 2)
  137. try:
  138. x = a.x()
  139. exit(1)
  140. except TypeError:
  141. pass