diff options
Diffstat (limited to 'Lib/lib2to3/tests')
-rw-r--r-- | Lib/lib2to3/tests/data/py3_test_grammar.py | 2 | ||||
-rw-r--r-- | Lib/lib2to3/tests/support.py | 2 | ||||
-rw-r--r-- | Lib/lib2to3/tests/test_all_fixers.py | 1 | ||||
-rw-r--r-- | Lib/lib2to3/tests/test_fixers.py | 7 | ||||
-rw-r--r-- | Lib/lib2to3/tests/test_parser.py | 50 | ||||
-rw-r--r-- | Lib/lib2to3/tests/test_pytree.py | 5 | ||||
-rw-r--r-- | Lib/lib2to3/tests/test_refactor.py | 6 | ||||
-rw-r--r-- | Lib/lib2to3/tests/test_util.py | 3 |
8 files changed, 55 insertions, 21 deletions
diff --git a/Lib/lib2to3/tests/data/py3_test_grammar.py b/Lib/lib2to3/tests/data/py3_test_grammar.py index c0bf7f27aa5..cf31a5411a8 100644 --- a/Lib/lib2to3/tests/data/py3_test_grammar.py +++ b/Lib/lib2to3/tests/data/py3_test_grammar.py @@ -319,7 +319,7 @@ class GrammarTests(unittest.TestCase): def f(x) -> list: pass self.assertEquals(f.__annotations__, {'return': list}) - # test MAKE_CLOSURE with a variety of oparg's + # test closures with a variety of oparg's closure = 1 def f(): return closure def f(x=1): return closure diff --git a/Lib/lib2to3/tests/support.py b/Lib/lib2to3/tests/support.py index 0897177d05e..ae7cfe8ee27 100644 --- a/Lib/lib2to3/tests/support.py +++ b/Lib/lib2to3/tests/support.py @@ -3,10 +3,8 @@ # Python imports import unittest -import sys import os import os.path -import re from textwrap import dedent # Local imports diff --git a/Lib/lib2to3/tests/test_all_fixers.py b/Lib/lib2to3/tests/test_all_fixers.py index 15079fe0285..c0507cf3fbc 100644 --- a/Lib/lib2to3/tests/test_all_fixers.py +++ b/Lib/lib2to3/tests/test_all_fixers.py @@ -10,7 +10,6 @@ import unittest import test.support # Local imports -from lib2to3 import refactor from . import support diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py index 640dcefd94e..b3f26807259 100644 --- a/Lib/lib2to3/tests/test_fixers.py +++ b/Lib/lib2to3/tests/test_fixers.py @@ -2,12 +2,11 @@ # Python imports import os -import unittest from itertools import chain from operator import itemgetter # Local imports -from lib2to3 import pygram, pytree, refactor, fixer_util +from lib2to3 import pygram, fixer_util from lib2to3.tests import support @@ -3234,6 +3233,10 @@ class Test_types(FixerTestCase): a = """type(None)""" self.check(b, a) + b = "types.StringTypes" + a = "(str,)" + self.check(b, a) + class Test_idioms(FixerTestCase): fixer = "idioms" diff --git a/Lib/lib2to3/tests/test_parser.py b/Lib/lib2to3/tests/test_parser.py index e4a0194b822..9a969e8ec04 100644 --- a/Lib/lib2to3/tests/test_parser.py +++ b/Lib/lib2to3/tests/test_parser.py @@ -8,7 +8,7 @@ test_grammar.py files from both Python 2 and Python 3. # Testing imports from . import support -from .support import driver, test_dir +from .support import driver from test.support import verbose # Python imports @@ -134,6 +134,24 @@ class TestAsyncAwait(GrammarTest): """) self.validate("""async def foo(): + [i async for i in b] + """) + + self.validate("""async def foo(): + {i for i in b + async for i in a if await i + for b in i} + """) + + self.validate("""async def foo(): + [await i for i in b if await c] + """) + + self.validate("""async def foo(): + [ i for i in b if c] + """) + + self.validate("""async def foo(): def foo(): pass @@ -272,6 +290,36 @@ class TestFunctionAnnotations(GrammarTest): self.validate(s) +# Adapted from Python 3's Lib/test/test_grammar.py:GrammarTests.test_var_annot +class TestVarAnnotations(GrammarTest): + def test_1(self): + self.validate("var1: int = 5") + + def test_2(self): + self.validate("var2: [int, str]") + + def test_3(self): + self.validate("def f():\n" + " st: str = 'Hello'\n" + " a.b: int = (1, 2)\n" + " return st\n") + + def test_4(self): + self.validate("def fbad():\n" + " x: int\n" + " print(x)\n") + + def test_5(self): + self.validate("class C:\n" + " x: int\n" + " s: str = 'attr'\n" + " z = 2\n" + " def __init__(self, x):\n" + " self.x: int = x\n") + + def test_6(self): + self.validate("lst: List[int] = []") + class TestExcept(GrammarTest): def test_new(self): s = """ diff --git a/Lib/lib2to3/tests/test_pytree.py b/Lib/lib2to3/tests/test_pytree.py index 4d585a88412..177126d5452 100644 --- a/Lib/lib2to3/tests/test_pytree.py +++ b/Lib/lib2to3/tests/test_pytree.py @@ -9,11 +9,6 @@ more helpful than printing of (the first line of) the docstring, especially when debugging a test. """ -from __future__ import with_statement - -import sys -import warnings - # Testing imports from . import support diff --git a/Lib/lib2to3/tests/test_refactor.py b/Lib/lib2to3/tests/test_refactor.py index 856300153dd..e9bae5e45d0 100644 --- a/Lib/lib2to3/tests/test_refactor.py +++ b/Lib/lib2to3/tests/test_refactor.py @@ -2,24 +2,18 @@ Unit tests for refactor.py. """ -from __future__ import with_statement - import sys import os import codecs -import operator import io import re import tempfile import shutil import unittest -import warnings from lib2to3 import refactor, pygram, fixer_base from lib2to3.pgen2 import token -from . import support - TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data") FIXER_DIR = os.path.join(TEST_DATA_DIR, "fixers") diff --git a/Lib/lib2to3/tests/test_util.py b/Lib/lib2to3/tests/test_util.py index d2be82c4a26..c6c613972da 100644 --- a/Lib/lib2to3/tests/test_util.py +++ b/Lib/lib2to3/tests/test_util.py @@ -3,9 +3,6 @@ # Testing imports from . import support -# Python imports -import os.path - # Local imports from lib2to3.pytree import Node, Leaf from lib2to3 import fixer_util |