Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
d07de5a5
Commit
d07de5a5
authored
Aug 29, 2014
by
Berker Peksag
Browse files
Options
Browse Files
Download
Plain Diff
Issue #22182: Use e.args to unpack exceptions correctly in distutils.file_util.move_file.
Patch by Claudiu Popa.
parents
0d72c5da
83b03cdd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
+22
-2
file_util.py
file_util.py
+2
-2
tests/test_file_util.py
tests/test_file_util.py
+20
-0
No files found.
file_util.py
View file @
d07de5a5
...
...
@@ -194,7 +194,7 @@ def move_file (src, dst,
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 @@ def move_file (src, dst,
try
:
os
.
unlink
(
src
)
except
OSError
as
e
:
(
num
,
msg
)
=
e
(
num
,
msg
)
=
e
.
args
try
:
os
.
unlink
(
dst
)
except
OSError
:
...
...
tests/test_file_util.py
View file @
d07de5a5
...
...
@@ -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 @@ 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
,
_
):
# 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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment