summaryrefslogtreecommitdiffstats
path: root/Lib/distutils
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2014-08-31 19:02:42 (GMT)
committerJason R. Coombs <jaraco@jaraco.com>2014-08-31 19:02:42 (GMT)
commit4b02e7041cd331fff6262bbeba8cfc0154b72568 (patch)
treeac2de4f163665162f8532fee795d588abec01fcf /Lib/distutils
parent1be2e82c57fad3bf8e04cb3e06212752de71ea70 (diff)
downloadcpython-4b02e7041cd331fff6262bbeba8cfc0154b72568.zip
cpython-4b02e7041cd331fff6262bbeba8cfc0154b72568.tar.gz
cpython-4b02e7041cd331fff6262bbeba8cfc0154b72568.tar.bz2
#22315: Add test to capture the failure.
Diffstat (limited to 'Lib/distutils')
-rw-r--r--Lib/distutils/tests/test_dir_util.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/distutils/tests/test_dir_util.py b/Lib/distutils/tests/test_dir_util.py
index 6181ec6..eb83497 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
+import contextlib
+from distutils import dir_util, errors
from distutils.dir_util import (mkpath, remove_tree, create_tree, copy_tree,
ensure_relative)
@@ -11,6 +13,20 @@ from distutils import log
from distutils.tests import support
from test.support import run_unittest
+
+@contextlib.context_manager
+def patch_obj(obj, attr, replacement):
+ """
+ A poor man's mock.patch.object
+ """
+ orig = getattr(obj, attr)
+ try:
+ setattr(obj, attr, replacement)
+ yield
+ finally:
+ setattr(obj, attr, orig)
+
+
class DirUtilTestCase(support.TempdirManager, unittest.TestCase):
def _log(self, msg, *args):
@@ -119,6 +135,19 @@ class DirUtilTestCase(support.TempdirManager, unittest.TestCase):
self.assertEqual(ensure_relative('c:\\home\\foo'), 'c:home\\foo')
self.assertEqual(ensure_relative('home\\foo'), 'home\\foo')
+ def test_copy_tree_exception_in_listdir(self):
+ """
+ An exception in listdir should raise a DistutilsFileError
+ """
+ def new_listdir(path):
+ raise OSError()
+ # simulate a transient network error or other failure invoking listdir
+ with patch_obj(os, 'listdir', new_listdir):
+ args = 'src', None
+ exc = errors.DistutilsFileError
+ self.assertRaises(exc, dir_util.copy_tree, *args)
+
+
def test_suite():
return unittest.makeSuite(DirUtilTestCase)