From fa5e7cf997df3cd011c4e2e9742811c0822a7f5c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 30 Aug 2015 13:13:11 -0400 Subject: Use modern mechanism for test discovery --- Lib/distutils/tests/test_filelist.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Lib/distutils/tests/test_filelist.py b/Lib/distutils/tests/test_filelist.py index e82bc3d..278809c 100644 --- a/Lib/distutils/tests/test_filelist.py +++ b/Lib/distutils/tests/test_filelist.py @@ -7,7 +7,7 @@ from distutils.log import WARN from distutils.errors import DistutilsTemplateError from distutils.filelist import glob_to_re, translate_pattern, FileList -from test.support import captured_stdout, run_unittest +from test.support import captured_stdout from distutils.tests import support MANIFEST_IN = """\ @@ -292,8 +292,5 @@ class FileListTestCase(support.LoggingSilencer, self.assertWarnings() -def test_suite(): - return unittest.makeSuite(FileListTestCase) - if __name__ == "__main__": - run_unittest(test_suite()) + unittest.main() -- cgit v0.12 From a0c6c1c6598173a524633c9b8fb23780f794b998 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 30 Aug 2015 13:22:56 -0400 Subject: Issue #12285: Add test capturing failure. --- Lib/distutils/tests/test_filelist.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lib/distutils/tests/test_filelist.py b/Lib/distutils/tests/test_filelist.py index 278809c..6b3bde0 100644 --- a/Lib/distutils/tests/test_filelist.py +++ b/Lib/distutils/tests/test_filelist.py @@ -6,7 +6,9 @@ from distutils import debug from distutils.log import WARN from distutils.errors import DistutilsTemplateError from distutils.filelist import glob_to_re, translate_pattern, FileList +from distutils import filelist +import test.support from test.support import captured_stdout from distutils.tests import support @@ -292,5 +294,13 @@ class FileListTestCase(support.LoggingSilencer, self.assertWarnings() +class FindAllTestCase(unittest.TestCase): + @test.support.skip_unless_symlink + def test_missing_symlink(self): + with test.support.temp_cwd(): + os.symlink('foo', 'bar') + self.assertEqual(filelist.findall(), []) + + if __name__ == "__main__": unittest.main() -- cgit v0.12 From 2c5278ad30c2883a9d64e834d38119bb96487396 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 30 Aug 2015 13:26:48 -0400 Subject: Add another test capturing the basic discovery expectation. --- Lib/distutils/tests/test_filelist.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Lib/distutils/tests/test_filelist.py b/Lib/distutils/tests/test_filelist.py index 6b3bde0..45ff565 100644 --- a/Lib/distutils/tests/test_filelist.py +++ b/Lib/distutils/tests/test_filelist.py @@ -301,6 +301,17 @@ class FindAllTestCase(unittest.TestCase): os.symlink('foo', 'bar') self.assertEqual(filelist.findall(), []) + def test_basic_discovery(self): + with test.support.temp_cwd(): + os.mkdir('foo') + file1 = os.path.join('foo', 'file1.txt') + test.support.create_empty_file(file1) + os.mkdir('bar') + file2 = os.path.join('bar', 'file2.txt') + test.support.create_empty_file(file2) + expected = [file1, file2] + self.assertEqual(filelist.findall(), expected) + if __name__ == "__main__": unittest.main() -- cgit v0.12 From a2cf2292a221f874bfec7587299ef26baee08906 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 19 Sep 2015 17:32:51 +0200 Subject: Add docstring and additional test revealing nuances of the implementation as found in setuptools. --- Lib/distutils/tests/test_filelist.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Lib/distutils/tests/test_filelist.py b/Lib/distutils/tests/test_filelist.py index 45ff565..571acdb 100644 --- a/Lib/distutils/tests/test_filelist.py +++ b/Lib/distutils/tests/test_filelist.py @@ -302,6 +302,11 @@ class FindAllTestCase(unittest.TestCase): self.assertEqual(filelist.findall(), []) def test_basic_discovery(self): + """ + When findall is called with no parameters or with + '.' as the parameter, the dot should be omitted from + the results. + """ with test.support.temp_cwd(): os.mkdir('foo') file1 = os.path.join('foo', 'file1.txt') @@ -312,6 +317,17 @@ class FindAllTestCase(unittest.TestCase): expected = [file1, file2] self.assertEqual(filelist.findall(), expected) + def test_non_local_discovery(self): + """ + When findall is called with another path, the full + path name should be returned. + """ + with test.support.temp_dir() as temp_dir: + file1 = os.path.join(temp_dir, 'file1.txt') + test.support.create_empty_file(file1) + expected = [file1] + self.assertEqual(filelist.findall(temp_dir), expected) + if __name__ == "__main__": unittest.main() -- cgit v0.12 From 1a04c447c951b33aa8c8c0f1b6803b06101b7f92 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 30 Aug 2015 14:05:58 -0400 Subject: Sort result to avoid spurious errors due to order. --- Lib/distutils/tests/test_filelist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/distutils/tests/test_filelist.py b/Lib/distutils/tests/test_filelist.py index 571acdb..e719198 100644 --- a/Lib/distutils/tests/test_filelist.py +++ b/Lib/distutils/tests/test_filelist.py @@ -314,8 +314,8 @@ class FindAllTestCase(unittest.TestCase): os.mkdir('bar') file2 = os.path.join('bar', 'file2.txt') test.support.create_empty_file(file2) - expected = [file1, file2] - self.assertEqual(filelist.findall(), expected) + expected = [file2, file1] + self.assertEqual(sorted(filelist.findall()), expected) def test_non_local_discovery(self): """ -- cgit v0.12 From edc4b2fa675788486cea661b4c6b9f7e33c44a3f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 19 Sep 2015 18:12:15 +0200 Subject: Issue #12285: Replace implementation of findall with implementation from Setuptools 7ce820d524db. --- Lib/distutils/filelist.py | 48 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/Lib/distutils/filelist.py b/Lib/distutils/filelist.py index db3f7a9..6522e69 100644 --- a/Lib/distutils/filelist.py +++ b/Lib/distutils/filelist.py @@ -6,6 +6,7 @@ and building lists of files. import os, re import fnmatch +import functools from distutils.util import convert_path from distutils.errors import DistutilsTemplateError, DistutilsInternalError from distutils import log @@ -242,35 +243,28 @@ class FileList: # ---------------------------------------------------------------------- # Utility functions +def _find_all_simple(path): + """ + Find all files under 'path' + """ + results = ( + os.path.join(base, file) + for base, dirs, files in os.walk(path, followlinks=True) + for file in files + ) + return filter(os.path.isfile, results) + + def findall(dir=os.curdir): - """Find all files under 'dir' and return the list of full filenames - (relative to 'dir'). """ - from stat import ST_MODE, S_ISREG, S_ISDIR, S_ISLNK - - list = [] - stack = [dir] - pop = stack.pop - push = stack.append - - while stack: - dir = pop() - names = os.listdir(dir) - - for name in names: - if dir != os.curdir: # avoid the dreaded "./" syndrome - fullname = os.path.join(dir, name) - else: - fullname = name - - # Avoid excess stat calls -- just one will do, thank you! - stat = os.stat(fullname) - mode = stat[ST_MODE] - if S_ISREG(mode): - list.append(fullname) - elif S_ISDIR(mode) and not S_ISLNK(mode): - push(fullname) - return list + Find all files under 'dir' and return the list of full filenames. + Unless dir is '.', return full filenames with dir prepended. + """ + files = _find_all_simple(dir) + if dir == os.curdir: + make_rel = functools.partial(os.path.relpath, start=dir) + files = map(make_rel, files) + return list(files) def glob_to_re(pattern): -- cgit v0.12 From 97eda155f82e6285315af86a02fa99fbe21a9a45 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 1 Sep 2016 21:12:17 -0400 Subject: Issue #12285: Update NEWS --- Misc/NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index aad29d9..d272762 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,8 @@ Core and Builtins Library ------- +- Issue #12285: Fix error when distutils encounters symlink. + - In the curses module, raise an error if window.getstr() or window.instr() is passed a negative value. -- cgit v0.12