summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-01-03 12:21:52 -0800
committerGiampaolo Rodola <g.rodola@gmail.com>2020-01-03 12:21:52 -0800
commitef8b682027d8adda3c88c393aa42d3f1d3ad95b5 (patch)
tree0d24d33e9e42fdd90c6d9ffb63d1f2960d5bcb72
parent220a1948770eda6cd208c3fb0b6ed017d1772288 (diff)
downloadpsutil-ef8b682027d8adda3c88c393aa42d3f1d3ad95b5.tar.gz
fix open_files() tests broken on windows due to case sensitiveness
-rwxr-xr-xpsutil/tests/test_process.py21
-rwxr-xr-xpsutil/tests/test_unicode.py3
2 files changed, 13 insertions, 11 deletions
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py
index 24a29b5a..37eaecf2 100755
--- a/psutil/tests/test_process.py
+++ b/psutil/tests/test_process.py
@@ -966,13 +966,12 @@ class TestProcess(unittest.TestCase):
f.flush()
# give the kernel some time to see the new file
files = call_until(p.open_files, "len(ret) != %i" % len(files))
- for file in files:
- if file.path == TESTFN:
- if LINUX:
+ filenames = [os.path.normcase(x.path) for x in files]
+ self.assertIn(os.path.normcase(TESTFN), filenames)
+ if LINUX:
+ for file in files:
+ if file.path == TESTFN:
self.assertEqual(file.position, 1024)
- break
- else:
- self.fail("no file found; files=%s" % repr(files))
for file in files:
assert os.path.isfile(file.path), file
@@ -982,12 +981,12 @@ class TestProcess(unittest.TestCase):
p = psutil.Process(sproc.pid)
for x in range(100):
- filenames = [x.path for x in p.open_files()]
+ filenames = [os.path.normcase(x.path) for x in p.open_files()]
if TESTFN in filenames:
break
time.sleep(.01)
else:
- self.assertIn(TESTFN, filenames)
+ self.assertIn(os.path.normcase(TESTFN), filenames)
for file in filenames:
assert os.path.isfile(file), file
@@ -997,14 +996,16 @@ class TestProcess(unittest.TestCase):
@unittest.skipIf(APPVEYOR, "unreliable on APPVEYOR")
def test_open_files_2(self):
# test fd and path fields
+ normcase = os.path.normcase
with open(TESTFN, 'w') as fileobj:
p = psutil.Process()
for file in p.open_files():
- if file.path == fileobj.name or file.fd == fileobj.fileno():
+ if normcase(file.path) == normcase(fileobj.name) or \
+ file.fd == fileobj.fileno():
break
else:
self.fail("no file found; files=%s" % repr(p.open_files()))
- self.assertEqual(file.path, fileobj.name)
+ self.assertEqual(normcase(file.path), normcase(fileobj.name))
if WINDOWS:
self.assertEqual(file.fd, -1)
else:
diff --git a/psutil/tests/test_unicode.py b/psutil/tests/test_unicode.py
index f7115e3d..05c94613 100755
--- a/psutil/tests/test_unicode.py
+++ b/psutil/tests/test_unicode.py
@@ -165,7 +165,8 @@ class _BaseFSAPIsTests(object):
exe = p.exe()
self.assertIsInstance(exe, str)
if self.expect_exact_path_match():
- self.assertEqual(exe, self.funky_name)
+ self.assertEqual(os.path.normcase(exe),
+ os.path.normcase(self.funky_name))
def test_proc_name(self):
subp = get_test_subprocess(cmd=[self.funky_name])