summaryrefslogtreecommitdiffstats
path: root/Lib/distutils
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-09-20 15:53:12 (GMT)
committerBenjamin Peterson <benjamin@python.org>2014-09-20 15:53:12 (GMT)
commit9833fcbca3317bb664252437a3c58d68bfee13a8 (patch)
tree5f533687c5d06324b17a42bb9e1780893570b0ba /Lib/distutils
parent96756b6a2712830cdbb29f5eb125b7aef0ee187c (diff)
downloadcpython-9833fcbca3317bb664252437a3c58d68bfee13a8.zip
cpython-9833fcbca3317bb664252437a3c58d68bfee13a8.tar.gz
cpython-9833fcbca3317bb664252437a3c58d68bfee13a8.tar.bz2
use patch context manager instead of decorator because the decorator 'leaks' metadata onto the function
Diffstat (limited to 'Lib/distutils')
-rw-r--r--Lib/distutils/tests/test_dir_util.py6
-rw-r--r--Lib/distutils/tests/test_file_util.py15
2 files changed, 10 insertions, 11 deletions
diff --git a/Lib/distutils/tests/test_dir_util.py b/Lib/distutils/tests/test_dir_util.py
index d2696b8..d436cf8 100644
--- a/Lib/distutils/tests/test_dir_util.py
+++ b/Lib/distutils/tests/test_dir_util.py
@@ -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)
diff --git a/Lib/distutils/tests/test_file_util.py b/Lib/distutils/tests/test_file_util.py
index 270f81e..d3db5ce 100644
--- a/Lib/distutils/tests/test_file_util.py
+++ b/Lib/distutils/tests/test_file_util.py
@@ -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)