99_bugs.py 1.4 KB

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