99_bugs.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # multi loop bug
  2. out = []
  3. a = [1, 2]
  4. for i in a:
  5. for j in a:
  6. out.append((i, j))
  7. assert (out == [(1, 1), (1, 2), (2, 1), (2, 2)]), out
  8. # https://github.com/pocketpy/pocketpy/issues/37
  9. mp = map(lambda x: x**2, [1, 2, 3, 4, 5] )
  10. assert list(mp) == [1, 4, 9, 16, 25]
  11. assert not 3>4
  12. def f(x):
  13. if x>1:
  14. return 1
  15. assert f(2) == 1
  16. assert f(0) == None
  17. a = [1, 2]
  18. b = [3, 4]
  19. assert a.append == a.append
  20. assert a.append is not a.append
  21. assert a.append is not b.append
  22. assert a.append != b.append
  23. inq = 0
  24. if not inq:
  25. assert True
  26. else:
  27. assert False
  28. if inq is not 1:
  29. assert True
  30. if inq is not 0:
  31. assert False
  32. def g(x):
  33. return x
  34. def f(x):
  35. return x
  36. assert (g(1), 2) == (1, 2)
  37. assert (
  38. g(1),
  39. 2
  40. ) == (1, 2)
  41. assert f((
  42. g(1),
  43. 2
  44. )) == (1, 2)
  45. def f():
  46. for i in range(4):
  47. _ = 0
  48. while i: --i
  49. f()
  50. # class A: a=b=1
  51. # class A: a, b = 1, 2
  52. bmi = 0.0
  53. def test(a):
  54. if a:
  55. bmi = 1.4
  56. return f'{bmi:.2f}'
  57. assert test(1) == '1.40'
  58. try:
  59. assert test(0) == '0.00'
  60. exit(1)
  61. except UnboundLocalError:
  62. pass
  63. g = 1
  64. def f():
  65. global g
  66. ++g
  67. f(); f()
  68. assert g == 3
  69. def f(**kw):
  70. x = 1
  71. y = 2
  72. return kw, x, y
  73. assert f(x=4, z=1) == ({'x': 4, 'z': 1}, 1, 2)
  74. def g(**kw):
  75. x, y = 1, 2
  76. return kw
  77. ret = g(
  78. a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9,
  79. j=10, k=11, l=12, m=13, n=14, o=15, p=16, q=17,
  80. r=18, s=19, t=20, u=21, v=22, w=23, x=24, y=25,
  81. z=26
  82. )
  83. assert ret == {chr(i+97): i+1 for i in range(26)}
  84. assert g(**ret) == ret
  85. assert g(**g(**ret)) == ret
  86. # other known issues:
  87. # 1. d.extend(d) if d is deque
  88. g = 0
  89. def test():
  90. global g
  91. g += 1
  92. return g
  93. a = [1, 10, 3]
  94. a[test()] += 1
  95. assert (a == [1, 11, 3]), a
  96. assert (g == 1), g