diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2014-08-31 22:02:18 (GMT) |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2014-08-31 22:02:18 (GMT) |
commit | 71a8eed6150a83ba0ed652401277e6d17773955c (patch) | |
tree | 85db06513f53e48b21e2253287175165fc57e359 /Lib/distutils | |
parent | c49a6aa1f004ec8399dfc2a326ccc39b658ec5b4 (diff) | |
parent | 311321edc15d4062babf757e3827341633353d55 (diff) | |
download | cpython-71a8eed6150a83ba0ed652401277e6d17773955c.zip cpython-71a8eed6150a83ba0ed652401277e6d17773955c.tar.gz cpython-71a8eed6150a83ba0ed652401277e6d17773955c.tar.bz2 |
Merge with 3.4; Closes #22315
Diffstat (limited to 'Lib/distutils')
-rw-r--r-- | Lib/distutils/dir_util.py | 3 | ||||
-rw-r--r-- | 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 index 9879b0d..0924c9b 100644 --- a/Lib/distutils/dir_util.py +++ b/Lib/distutils/dir_util.py @@ -125,12 +125,11 @@ def copy_tree(src, dst, preserve_mode=1, preserve_times=1, 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 index 6181ec6..d2696b8 100644 --- a/Lib/distutils/tests/test_dir_util.py +++ b/Lib/distutils/tests/test_dir_util.py @@ -3,7 +3,9 @@ import unittest 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 import log 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 @@ class DirUtilTestCase(support.TempdirManager, unittest.TestCase): 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) |