test.py 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Above the run-comment and file encoding comment.
  4. # Comments.
  5. # TODO FIXME XXX
  6. # Keywords.
  7. with break continue del exec return pass print raise global assert yield
  8. for while if elif else import from as try except finally and in is not or
  9. lambda: a + 1
  10. lambda x, y: x + y
  11. yield from
  12. def functionname
  13. class Classname
  14. def функция
  15. class Класс
  16. await
  17. async def Test
  18. async with
  19. async for
  20. # Type annotations
  21. def myfunc(a: str, something_other,
  22. b: Callable[[str, str], int]) -> Any:
  23. myval: float
  24. mygood: Optional[int, Any] = b('wow', 'oops')
  25. myarr: Sequence[int] = origarr[aa:bb]
  26. mykey = a
  27. wow = {
  28. mykey: this_should_not_be_type_anno[Any],
  29. 'b': some_data,
  30. }
  31. call_with_dict(a={
  32. 'a': asdf,
  33. 'b': 'zxcb',
  34. mykey: this_should_not_be_type_anno[Any],
  35. }, b=mydata['a'])
  36. vanilla_lambda = lambda x, y: myval + 1.0
  37. call_with_lambda(lambda x, y: myval + 1.0)
  38. call_with_slice(mydata[range_start:range_end])
  39. # Builtin objects.
  40. True False Ellipsis None NotImplemented
  41. # Builtin function and types.
  42. __import__() abs() all() any() apply() basestring() bool() buffer() callable() chr() classmethod()
  43. cmp() coerce() compile() complex() delattr() dict() dir() divmod() enumerate() eval() execfile() file()
  44. filter() float() frozenset() getattr() globals() hasattr() hash() help() hex() id() input() int()
  45. intern() isinstance() issubclass() iter() len() list() locals() long() map() max() min() object() oct()
  46. open() ord() pow() property() range() raw_input() reduce() reload() repr() reversed() round() set()
  47. setattr() slice() sorted() staticmethod() str() sum() super() tuple() type() unichr() unicode() vars()
  48. xrange() zip()
  49. when_we_dont_call = a.float
  50. float = when_we_dont_call
  51. when_we_call = float(x)
  52. when_we_call = min(a, b)
  53. # Builtin exceptions and warnings.
  54. BaseException Exception StandardError ArithmeticError LookupError
  55. EnvironmentError
  56. AssertionError AttributeError EOFError FloatingPointError GeneratorExit IOError
  57. ImportError IndexError KeyError KeyboardInterrupt MemoryError NameError
  58. NotImplementedError OSError OverflowError ReferenceError RuntimeError
  59. StopIteration SyntaxError IndentationError TabError SystemError SystemExit
  60. TypeError UnboundLocalError UnicodeError UnicodeEncodeError UnicodeDecodeError
  61. UnicodeTranslateError ValueError WindowsError ZeroDivisionError
  62. Warning UserWarning DeprecationWarning PendingDepricationWarning SyntaxWarning
  63. RuntimeWarning FutureWarning ImportWarning UnicodeWarning
  64. # Decorators.
  65. @ decoratorname
  66. @ object.__init__(arg1, arg2)
  67. @ декоратор
  68. @ декоратор.décorateur
  69. # Numbers
  70. 0 1 2 9 10 0x1f .3 12.34 0j 124j 34.2E-3 0b10 0o77 1023434 0x0
  71. 1_1 1_1.2_2 1_2j 0x_1f 0x1_f 34_56e-3 34_56e+3_1 0o7_7
  72. # Erroneous numbers
  73. 077 100L 0xfffffffL 0L 08 0xk 0x 0b102 0o78 0o123LaB
  74. 0_ 0_1 0_x1f 0x1f_ 0_b77 0b77_ .2_ 1_j
  75. # Strings
  76. " test " ' test '
  77. """
  78. test
  79. """
  80. '''
  81. test
  82. '''
  83. " \a\b\c\"\'\n\r \x34\077 \08 \xag"
  84. r" \" \' "
  85. "testтест"
  86. b"test"
  87. b"test\r\n\xffff"
  88. b"тестtest"
  89. br"test"
  90. br"\a\b\n\r"
  91. # Formattings
  92. " %f "
  93. b" %f "
  94. "{0.name!r:b} {0[n]} {name!s: } {{test}} {{}} {} {.__len__:s}"
  95. b"{0.name!r:b} {0[n]} {name!s: } {{test}} {{}} {} {.__len__:s}"
  96. "${test} ${test ${test}aname $$$ $test+nope"
  97. b"${test} ${test ${test}aname $$$ $test+nope"
  98. f"{var}...{arr[123]} normal {var['{'] // 0xff} \"xzcb\" 'xzcb' {var['}'] + 1} text"
  99. f"{expr1 if True or False else expr2} wow {','.join(c.lower() for c in 'asdf')}"
  100. f"hello {expr:.2f} yes {(lambda: 0b1)():#03x} lol {var!r}"
  101. # Doctests.
  102. """
  103. Test:
  104. >>> a = 5
  105. >>> a
  106. 5
  107. Test
  108. """
  109. '''
  110. Test:
  111. >>> a = 5
  112. >>> a
  113. 5
  114. Test
  115. '''
  116. # Erroneous symbols or bad variable names.
  117. $ ? 6xav
  118. && || ===
  119. # Indentation errors.
  120. break
  121. # Trailing space errors.
  122. break
  123. """
  124. test
  125. """