[Python-checkins] cpython (merge 3.4 -> default): Issue #22182: Use e.args to unpack exceptions correctly in
berker.peksag
python-checkins at python.org
Fri Aug 29 06:08:56 CEST 2014
http://hg.python.org/cpython/rev/f01413758114
changeset: 92263:f01413758114
parent: 92258:4fc575d55e2b
parent: 92262:a3452677a386
user: Berker Peksag <berker.peksag at gmail.com>
date: Fri Aug 29 07:09:25 2014 +0300
summary:
Issue #22182: Use e.args to unpack exceptions correctly in distutils.file_util.move_file.
Patch by Claudiu Popa.
files:
Lib/distutils/file_util.py | 4 +-
Lib/distutils/tests/test_file_util.py | 20 +++++++++++++++
Misc/NEWS | 3 ++
3 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/Lib/distutils/file_util.py b/Lib/distutils/file_util.py
--- a/Lib/distutils/file_util.py
+++ b/Lib/distutils/file_util.py
@@ -194,7 +194,7 @@
try:
os.rename(src, dst)
except OSError as e:
- (num, msg) = e
+ (num, msg) = e.args
if num == errno.EXDEV:
copy_it = True
else:
@@ -206,7 +206,7 @@
try:
os.unlink(src)
except OSError as e:
- (num, msg) = e
+ (num, msg) = e.args
try:
os.unlink(dst)
except OSError:
diff --git a/Lib/distutils/tests/test_file_util.py b/Lib/distutils/tests/test_file_util.py
--- a/Lib/distutils/tests/test_file_util.py
+++ b/Lib/distutils/tests/test_file_util.py
@@ -2,10 +2,13 @@
import unittest
import os
import shutil
+import errno
+from unittest.mock import patch
from distutils.file_util import move_file
from distutils import log
from distutils.tests import support
+from distutils.errors import DistutilsFileError
from test.support import run_unittest
class FileUtilTestCase(support.TempdirManager, unittest.TestCase):
@@ -58,6 +61,23 @@
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, _):
+ # see issue 22182
+ with 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):
+ # see issue 22182
+ with 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)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -124,6 +124,9 @@
Library
-------
+- Issue #22182: Use e.args to unpack exceptions correctly in
+ distutils.file_util.move_file. Patch by Claudiu Popa.
+
- The webbrowser module now uses subprocess's start_new_session=True rather
than a potentially risky preexec_fn=os.setsid call.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list