summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2022-10-21 11:34:55 -0700
committerGiampaolo Rodola <g.rodola@gmail.com>2022-10-21 11:34:55 -0700
commit8e4099d9f063ceb4ee3da5845562c5b934f83544 (patch)
treeaf241529d3a1d7225400d8e2339c8f5bb048750a
parent55b588ac48d9b8e37f01c8428090066c01771627 (diff)
downloadpsutil-8e4099d9f063ceb4ee3da5845562c5b934f83544.tar.gz
add windows test for free physical mem #2074
-rwxr-xr-xpsutil/tests/test_windows.py39
-rwxr-xr-xscripts/internal/winmake.py4
2 files changed, 41 insertions, 2 deletions
diff --git a/psutil/tests/test_windows.py b/psutil/tests/test_windows.py
index 3bf45807..cb2642d1 100755
--- a/psutil/tests/test_windows.py
+++ b/psutil/tests/test_windows.py
@@ -23,6 +23,7 @@ import warnings
import psutil
from psutil import WINDOWS
from psutil._compat import FileNotFoundError
+from psutil._compat import which
from psutil._compat import super
from psutil.tests import APPVEYOR
from psutil.tests import GITHUB_ACTIONS
@@ -31,6 +32,7 @@ from psutil.tests import IS_64BIT
from psutil.tests import PY3
from psutil.tests import PYPY
from psutil.tests import TOLERANCE_DISK_USAGE
+from psutil.tests import TOLERANCE_SYS_MEM
from psutil.tests import PsutilTestCase
from psutil.tests import mock
from psutil.tests import retry_on_failure
@@ -62,6 +64,37 @@ class WindowsTestCase(PsutilTestCase):
pass
+def powershell(cmd):
+ """Currently not used, but avalable just in case. Usage:
+
+ >>> powershell(
+ "Get-CIMInstance Win32_PageFileUsage | Select AllocatedBaseSize")
+ """
+ if not which("powershell.exe"):
+ raise unittest.SkipTest("powershell.exe not available")
+ cmdline = \
+ 'powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive ' + \
+ '-NoProfile -WindowStyle Hidden -Command "%s"' % cmd
+ return sh(cmdline)
+
+
+def wmic(path, what, converter=int):
+ """Currently not used, but avalable just in case. Usage:
+
+ >>> wmic("Win32_OperatingSystem", "FreePhysicalMemory")
+ 2134124534
+ """
+ out = sh("wmic path %s get %s" % (path, what)).strip()
+ data = "".join(out.splitlines()[1:]).strip() # get rid of the header
+ if converter is not None:
+ if "," in what:
+ return tuple([converter(x) for x in data.split()])
+ else:
+ return converter(data)
+ else:
+ return data
+
+
# ===================================================================
# System APIs
# ===================================================================
@@ -123,6 +156,12 @@ class TestSystemAPIs(WindowsTestCase):
self.assertEqual(int(w.TotalPhysicalMemory),
psutil.virtual_memory().total)
+ def test_free_phymem(self):
+ w = wmi.WMI().Win32_PerfRawData_PerfOS_Memory()[0]
+ self.assertAlmostEqual(
+ int(w.AvailableBytes), psutil.virtual_memory().free,
+ delta=TOLERANCE_SYS_MEM)
+
# @unittest.skipIf(wmi is None, "wmi module is not installed")
# def test__UPTIME(self):
# # _UPTIME constant is not public but it is used internally
diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py
index bb880051..466887c2 100755
--- a/scripts/internal/winmake.py
+++ b/scripts/internal/winmake.py
@@ -383,7 +383,7 @@ def setup_dev_env():
sh("%s -m pip install -U %s" % (PYTHON, " ".join(DEPS)))
-def check_flake8():
+def flake8():
"""Run flake8 against all py files"""
py_files = subprocess.check_output("git ls-files")
if PY3:
@@ -565,7 +565,7 @@ def main():
sp.add_parser('install', help="build + install in develop/edit mode")
sp.add_parser('install-git-hooks', help="install GIT pre-commit hook")
sp.add_parser('install-pip', help="install pip")
- sp.add_parser('check_flake8', help="run flake8 against all py files")
+ sp.add_parser('flake8', help="run flake8 against all py files")
sp.add_parser('print-access-denied', help="print AD exceptions")
sp.add_parser('print-api-speed', help="benchmark all API calls")
sp.add_parser('setup-dev-env', help="install deps")