summaryrefslogtreecommitdiff
path: root/psutil/tests
diff options
context:
space:
mode:
authorDaniel Widdis <widdis@gmail.com>2023-04-13 01:11:27 -0700
committerGitHub <noreply@github.com>2023-04-13 10:11:27 +0200
commit0dde184075f81a9b6e22caa7255396d21ae63769 (patch)
treed234e2a26bc6b77c576a0ddea6de42f61a96c4da /psutil/tests
parent67d988aeb5701bca3cc84795ae3f249b5c843451 (diff)
downloadpsutil-0dde184075f81a9b6e22caa7255396d21ae63769.tar.gz
Get Windows percent swap usage from performance counters (#2160)
Signed-off-by: Daniel Widdis <widdis@gmail.com>
Diffstat (limited to 'psutil/tests')
-rwxr-xr-xpsutil/tests/test_windows.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/psutil/tests/test_windows.py b/psutil/tests/test_windows.py
index 9b163a18..a9f68933 100755
--- a/psutil/tests/test_windows.py
+++ b/psutil/tests/test_windows.py
@@ -162,6 +162,27 @@ class TestSystemAPIs(WindowsTestCase):
int(w.AvailableBytes), psutil.virtual_memory().free,
delta=TOLERANCE_SYS_MEM)
+ def test_total_swapmem(self):
+ w = wmi.WMI().Win32_PerfRawData_PerfOS_Memory()[0]
+ self.assertEqual(int(w.CommitLimit) - psutil.virtual_memory().total,
+ psutil.swap_memory().total)
+ if (psutil.swap_memory().total == 0):
+ self.assertEqual(0, psutil.swap_memory().free)
+ self.assertEqual(0, psutil.swap_memory().used)
+
+ def test_percent_swapmem(self):
+ if (psutil.swap_memory().total > 0):
+ w = wmi.WMI().Win32_PerfRawData_PerfOS_PagingFile(
+ Name="_Total")[0]
+ # calculate swap usage to percent
+ percentSwap = int(w.PercentUsage) * 100 / int(w.PercentUsage_Base)
+ # exact percent may change but should be reasonable
+ # assert within +/- 5% and between 0 and 100%
+ self.assertGreaterEqual(psutil.swap_memory().percent, 0)
+ self.assertAlmostEqual(psutil.swap_memory().percent, percentSwap,
+ delta=5)
+ self.assertLessEqual(psutil.swap_memory().percent, 100)
+
# @unittest.skipIf(wmi is None, "wmi module is not installed")
# def test__UPTIME(self):
# # _UPTIME constant is not public but it is used internally