summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/tests
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2014-08-31 21:31:32 (GMT)
committerJason R. Coombs <jaraco@jaraco.com>2014-08-31 21:31:32 (GMT)
commite572ce3fb54dc03cde1b1520077124418c14e9fa (patch)
tree23718f224286af89ba3a2da2fd78bdf503be074c /Lib/distutils/tests
parent4b02e7041cd331fff6262bbeba8cfc0154b72568 (diff)
downloadcpython-e572ce3fb54dc03cde1b1520077124418c14e9fa.zip
cpython-e572ce3fb54dc03cde1b1520077124418c14e9fa.tar.gz
cpython-e572ce3fb54dc03cde1b1520077124418c14e9fa.tar.bz2
#22315: Use technique outlined in test_file_util
Diffstat (limited to 'Lib/distutils/tests')
-rw-r--r--Lib/distutils/tests/test_dir_util.py27
1 files changed, 5 insertions, 22 deletions
diff --git a/Lib/distutils/tests/test_dir_util.py b/Lib/distutils/tests/test_dir_util.py
index eb83497..c9f789c 100644
--- a/Lib/distutils/tests/test_dir_util.py
+++ b/Lib/distutils/tests/test_dir_util.py
@@ -3,7 +3,7 @@ import unittest
import os
import stat
import sys
-import contextlib
+from unittest.mock import patch
from distutils import dir_util, errors
from distutils.dir_util import (mkpath, remove_tree, create_tree, copy_tree,
@@ -14,19 +14,6 @@ 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):
@@ -135,17 +122,13 @@ 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):
+ @patch('os.listdir', side_effect=OSError())
+ def test_copy_tree_exception_in_listdir(self, listdir):
"""
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)
+ with self.assertRaises(errors.DistutilsFileError):
+ dir_util.copy_tree('src', None)
def test_suite():