summaryrefslogtreecommitdiffstats
path: root/Tools/parser/test_unparse.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/parser/test_unparse.py')
-rw-r--r--Tools/parser/test_unparse.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/Tools/parser/test_unparse.py b/Tools/parser/test_unparse.py
index 2ac1ea6..be84400 100644
--- a/Tools/parser/test_unparse.py
+++ b/Tools/parser/test_unparse.py
@@ -2,9 +2,10 @@ import unittest
import test.support
import io
import os
+import random
import tokenize
-import ast
import unparse
+import ast
def read_pyfile(filename):
"""Read and return the contents of a Python source file (as a
@@ -93,6 +94,21 @@ finally:
suite5
"""
+with_simple = """\
+with f():
+ suite1
+"""
+
+with_as = """\
+with f() as x:
+ suite1
+"""
+
+with_two_items = """\
+with f() as x, g() as y:
+ suite1
+"""
+
class ASTTestCase(unittest.TestCase):
def assertASTEqual(self, ast1, ast2):
self.assertEqual(ast.dump(ast1), ast.dump(ast2))
@@ -215,6 +231,15 @@ class UnparseTestCase(ASTTestCase):
self.check_roundtrip("a, *b[0], c = seq")
self.check_roundtrip("a, *(b, c) = seq")
+ def test_with_simple(self):
+ self.check_roundtrip(with_simple)
+
+ def test_with_as(self):
+ self.check_roundtrip(with_as)
+
+ def test_with_two_items(self):
+ self.check_roundtrip(with_two_items)
+
class DirectoryTestCase(ASTTestCase):
"""Test roundtrip behaviour on all files in Lib and Lib/test."""
@@ -233,6 +258,10 @@ class DirectoryTestCase(ASTTestCase):
if n.endswith('.py') and not n.startswith('bad'):
names.append(os.path.join(test_dir, n))
+ # Test limited subset of files unless the 'cpu' resource is specified.
+ if not test.support.is_resource_enabled("cpu"):
+ names = random.sample(names, 10)
+
for filename in names:
if test.support.verbose:
print('Testing %s' % filename)