]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
use patch context manager instead of decorator because the decorator 'leaks' metadata...
authorBenjamin Peterson <benjamin@python.org>
Sat, 20 Sep 2014 15:53:12 +0000 (11:53 -0400)
committerBenjamin Peterson <benjamin@python.org>
Sat, 20 Sep 2014 15:53:12 +0000 (11:53 -0400)
Lib/distutils/tests/test_dir_util.py
Lib/distutils/tests/test_file_util.py

index d2696b822c8e9e061fae125920308179e1d78c7f..d436cf8319171554ba17b9590e4db61d6bed53e5 100644 (file)
@@ -122,12 +122,12 @@ 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):
+    def test_copy_tree_exception_in_listdir(self):
         """
         An exception in listdir should raise a DistutilsFileError
         """
-        with self.assertRaises(errors.DistutilsFileError):
+        with patch("os.listdir", side_effect=OSError()), \
+             self.assertRaises(errors.DistutilsFileError):
             src = self.tempdirs[-1]
             dir_util.copy_tree(src, None)
 
index 270f81ebb6cc9f04ab06683b23649bec767de79b..d3db5cef0e0d6d3db9b60f075940592cfa94d4b0 100644 (file)
@@ -61,24 +61,23 @@ class FileUtilTestCase(support.TempdirManager, unittest.TestCase):
         wanted = ['moving %s -> %s' % (self.source, self.target_dir)]
         self.assertEqual(self._logs, wanted)
 
-    @patch('os.rename', side_effect=OSError('wrong', 1))
-    def test_move_file_exception_unpacking_rename(self, _):
+    def test_move_file_exception_unpacking_rename(self):
         # see issue 22182
-        with self.assertRaises(DistutilsFileError):
+        with patch("os.rename", side_effect=OSError("wrong", 1)), \
+             self.assertRaises(DistutilsFileError):
             with open(self.source, 'w') as fobj:
                 fobj.write('spam eggs')
             move_file(self.source, self.target, verbose=0)
 
-    @patch('os.rename', side_effect=OSError(errno.EXDEV, 'wrong'))
-    @patch('os.unlink', side_effect=OSError('wrong', 1))
-    def test_move_file_exception_unpacking_unlink(self, rename, unlink):
+    def test_move_file_exception_unpacking_unlink(self):
         # see issue 22182
-        with self.assertRaises(DistutilsFileError):
+        with patch("os.rename", side_effect=OSError(errno.EXDEV, "wrong")), \
+             patch("os.unlink", side_effect=OSError("wrong", 1)), \
+             self.assertRaises(DistutilsFileError):
             with open(self.source, 'w') as fobj:
                 fobj.write('spam eggs')
             move_file(self.source, self.target, verbose=0)
 
-
 def test_suite():
     return unittest.makeSuite(FileUtilTestCase)