summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-10-02 11:36:09 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2016-10-02 11:36:09 +0200
commitce5cb8c8917305ce7d63de408d28daadd0302ec4 (patch)
tree23054512f45914efb5d941e60320d70f6683246a
parent9f0f4056c839fdafb9afb3a108760d625ed8a15a (diff)
downloadpsutil-ce5cb8c8917305ce7d63de408d28daadd0302ec4.tar.gz
fix safe_rmpath on windows
-rw-r--r--psutil/tests/__init__.py18
-rw-r--r--psutil/tests/test_misc.py9
-rw-r--r--scripts/internal/winmake.py7
3 files changed, 15 insertions, 19 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py
index c592d04c..b75ab0b4 100644
--- a/psutil/tests/__init__.py
+++ b/psutil/tests/__init__.py
@@ -458,19 +458,15 @@ def call_until(fun, expr):
def safe_rmpath(path):
"Convenience function for removing temporary test files or dirs"
try:
- os.remove(path)
+ st = os.stat(path)
except OSError as err:
- if err.errno == errno.ENOENT:
- # no such file or dir
- pass
- elif err.errno == errno.EISDIR:
- try:
- os.rmdir(path)
- except OSError as err:
- if err.errno != errno.ENOENT:
- raise
- else:
+ if err.errno != errno.ENOENT:
raise
+ else:
+ if stat.S_ISDIR(st.st_mode):
+ os.rmdir(path)
+ else:
+ os.remove(path)
@contextlib.contextmanager
diff --git a/psutil/tests/test_misc.py b/psutil/tests/test_misc.py
index 6166f235..f624f7a7 100644
--- a/psutil/tests/test_misc.py
+++ b/psutil/tests/test_misc.py
@@ -571,14 +571,7 @@ class TestFSTestUtils(unittest.TestCase):
safe_rmpath(TESTFN)
assert not os.path.exists(TESTFN)
# test other exceptions are raised
- with mock.patch('psutil.tests.os.remove',
- side_effect=OSError(errno.EINVAL, "")) as m:
- with self.assertRaises(OSError):
- safe_rmpath(TESTFN)
- assert m.called
-
- os.mkdir(TESTFN)
- with mock.patch('psutil.tests.os.rmdir',
+ with mock.patch('psutil.tests.os.stat',
side_effect=OSError(errno.EINVAL, "")) as m:
with self.assertRaises(OSError):
safe_rmpath(TESTFN)
diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py
index 23ccbca2..8351a675 100644
--- a/scripts/internal/winmake.py
+++ b/scripts/internal/winmake.py
@@ -258,6 +258,13 @@ def test_platform():
@cmd
+def test_misc():
+ """Run misc tests"""
+ install()
+ sh("%s -m unittest -v psutil.tests.test_misc" % PYTHON)
+
+
+@cmd
def test_by_name():
"""Run test by name"""
try: