cpython (merge 3.4 -> default): Merge with 3.4; Closes #22315
http://hg.python.org/cpython/rev/640c575ab3e1 changeset: 92290:640c575ab3e1 parent: 92284:2b2da4ae86b4 parent: 92289:75a5cc4ef31c user: Jason R. Coombs <jaraco@jaraco.com> date: Sun Aug 31 18:02:18 2014 -0400 summary: Merge with 3.4; Closes #22315 files: Lib/distutils/dir_util.py | 3 +-- Lib/distutils/tests/test_dir_util.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Lib/distutils/dir_util.py b/Lib/distutils/dir_util.py --- a/Lib/distutils/dir_util.py +++ b/Lib/distutils/dir_util.py @@ -125,12 +125,11 @@ try: names = os.listdir(src) except OSError as e: - (errno, errstr) = e if dry_run: names = [] else: raise DistutilsFileError( - "error listing files in '%s': %s" % (src, errstr)) + "error listing files in '%s': %s" % (src, e.strerror)) if not dry_run: mkpath(dst, verbose=verbose) diff --git a/Lib/distutils/tests/test_dir_util.py b/Lib/distutils/tests/test_dir_util.py --- a/Lib/distutils/tests/test_dir_util.py +++ b/Lib/distutils/tests/test_dir_util.py @@ -3,7 +3,9 @@ import os import stat import sys +from unittest.mock import patch +from distutils import dir_util, errors from distutils.dir_util import (mkpath, remove_tree, create_tree, copy_tree, ensure_relative) @@ -11,6 +13,7 @@ from distutils.tests import support from test.support import run_unittest + class DirUtilTestCase(support.TempdirManager, unittest.TestCase): def _log(self, msg, *args): @@ -119,6 +122,16 @@ self.assertEqual(ensure_relative('c:\\home\\foo'), 'c:home\\foo') self.assertEqual(ensure_relative('home\\foo'), 'home\\foo') + @patch('os.listdir', side_effect=OSError()) + def test_copy_tree_exception_in_listdir(self, listdir): + """ + An exception in listdir should raise a DistutilsFileError + """ + with self.assertRaises(errors.DistutilsFileError): + src = self.tempdirs[-1] + dir_util.copy_tree(src, None) + + def test_suite(): return unittest.makeSuite(DirUtilTestCase) -- Repository URL: http://hg.python.org/cpython
participants (1)
-
jason.coombs