Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e572ce3f
Commit
e572ce3f
authored
Aug 31, 2014
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#22315: Use technique outlined in test_file_util
parent
4b02e704
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
22 deletions
+5
-22
Lib/distutils/tests/test_dir_util.py
Lib/distutils/tests/test_dir_util.py
+5
-22
No files found.
Lib/distutils/tests/test_dir_util.py
View file @
e572ce3f
...
...
@@ -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
():
...
...
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