Commit 7351f9e5 authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

bpo-31174: Improve the code of test_tools.test_unparse. (#4146)

parent 03eb11f0
...@@ -268,12 +268,13 @@ class DirectoryTestCase(ASTTestCase): ...@@ -268,12 +268,13 @@ class DirectoryTestCase(ASTTestCase):
# test directories, relative to the root of the distribution # test directories, relative to the root of the distribution
test_directories = 'Lib', os.path.join('Lib', 'test') test_directories = 'Lib', os.path.join('Lib', 'test')
def get_names(self): @classmethod
if DirectoryTestCase.NAMES is not None: def get_names(cls):
return DirectoryTestCase.NAMES if cls.NAMES is not None:
return cls.NAMES
names = [] names = []
for d in self.test_directories: for d in cls.test_directories:
test_dir = os.path.join(basepath, d) test_dir = os.path.join(basepath, d)
for n in os.listdir(test_dir): for n in os.listdir(test_dir):
if n.endswith('.py') and not n.startswith('bad'): if n.endswith('.py') and not n.startswith('bad'):
...@@ -284,8 +285,7 @@ class DirectoryTestCase(ASTTestCase): ...@@ -284,8 +285,7 @@ class DirectoryTestCase(ASTTestCase):
names = random.sample(names, 10) names = random.sample(names, 10)
# bpo-31174: Store the names sample to always test the same files. # bpo-31174: Store the names sample to always test the same files.
# It prevents false alarms when hunting reference leaks. # It prevents false alarms when hunting reference leaks.
DirectoryTestCase.NAMES = names cls.NAMES = names
return names return names
def test_files(self): def test_files(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment