test.py 3.9KB

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