diff --git a/psutil/tests/test_windows.py b/psutil/tests/test_windows.py index 776579073f..3f0abae103 100755 --- a/psutil/tests/test_windows.py +++ b/psutil/tests/test_windows.py @@ -23,6 +23,7 @@ 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 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 @@ def test_total_phymem(self): 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) + def test_total_swapmem(self): if (psutil.swap_memory().total > 0): w = wmi.WMI().Win32_PerfRawData_PerfOS_Memory()[0] diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py index bb88005199..466887c2c0 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")