diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2018-03-31 00:47:40 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2018-03-31 00:47:40 +0200 |
commit | efbab16fd4b3e1ee5f95339cd1a75433d641048b (patch) | |
tree | a1c7e118011b4012c373a6c7c2903da2a0f637d4 | |
parent | c18dd45eaa0c34b1de0e5f0f1956d0ec326c36b7 (diff) | |
download | psutil-efbab16fd4b3e1ee5f95339cd1a75433d641048b.tar.gz |
refactor tests
-rw-r--r-- | docs/index.rst | 4 | ||||
-rwxr-xr-x | psutil/tests/test_windows.py | 42 |
2 files changed, 29 insertions, 17 deletions
diff --git a/docs/index.rst b/docs/index.rst index 0ffb3825..548f361f 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -179,8 +179,8 @@ CPU Note that this number is not equivalent to the number of CPUs the current process can actually use. That can vary in case process CPU affinity has been changed, Linux cgroups - are being used or on Windows systems using process groups or having more than - 64 CPUs. + are being used or on Windows systems using processor groups or having more + than 64 CPUs. The number of usable CPUs can be obtained with: >>> len(psutil.Process().cpu_affinity()) diff --git a/psutil/tests/test_windows.py b/psutil/tests/test_windows.py index 62d251f1..ffa763d0 100755 --- a/psutil/tests/test_windows.py +++ b/psutil/tests/test_windows.py @@ -69,45 +69,57 @@ def wrap_exceptions(fun): @unittest.skipIf(not WINDOWS, "WINDOWS only") -class TestSystemAPIs(unittest.TestCase): - - def test_nic_names(self): - out = sh('ipconfig /all') - nics = psutil.net_io_counters(pernic=True).keys() - for nic in nics: - if "pseudo-interface" in nic.replace(' ', '-').lower(): - continue - if nic not in out: - self.fail( - "%r nic wasn't found in 'ipconfig /all' output" % nic) +class TestCpuAPIs(unittest.TestCase): @unittest.skipIf('NUMBER_OF_PROCESSORS' not in os.environ, 'NUMBER_OF_PROCESSORS env var is not available') - def test_cpu_count(self): + def test_cpu_count_vs_NUMBER_OF_PROCESSORS(self): + # Will likely fail on many-cores systems: + # https://stackoverflow.com/questions/31209256 num_cpus = int(os.environ['NUMBER_OF_PROCESSORS']) self.assertEqual(num_cpus, psutil.cpu_count()) - def test_cpu_count_2(self): + def test_cpu_count_vs_GetSystemInfo(self): + # Will likely fail on many-cores systems: + # https://stackoverflow.com/questions/31209256 sys_value = win32api.GetSystemInfo()[5] psutil_value = psutil.cpu_count() self.assertEqual(sys_value, psutil_value) - def test_cpu_count_3(self): + def test_cpu_count_logical_vs_wmi(self): w = wmi.WMI() proc = w.Win32_Processor()[0] self.assertEqual(psutil.cpu_count(), proc.NumberOfLogicalProcessors) - def test_cpu_count_4(self): + def test_cpu_count_phys_vs_wmi(self): w = wmi.WMI() proc = w.Win32_Processor()[0] self.assertEqual(psutil.cpu_count(logical=False), proc.NumberOfCores) + def test_cpu_count_vs_cpu_times(self): + self.assertEqual(psutil.cpu_count(), + len(psutil.cpu_times(percpu=True))) + def test_cpu_freq(self): w = wmi.WMI() proc = w.Win32_Processor()[0] self.assertEqual(proc.CurrentClockSpeed, psutil.cpu_freq().current) self.assertEqual(proc.MaxClockSpeed, psutil.cpu_freq().max) + +@unittest.skipIf(not WINDOWS, "WINDOWS only") +class TestSystemAPIs(unittest.TestCase): + + def test_nic_names(self): + out = sh('ipconfig /all') + nics = psutil.net_io_counters(pernic=True).keys() + for nic in nics: + if "pseudo-interface" in nic.replace(' ', '-').lower(): + continue + if nic not in out: + self.fail( + "%r nic wasn't found in 'ipconfig /all' output" % nic) + def test_total_phymem(self): w = wmi.WMI().Win32_ComputerSystem()[0] self.assertEqual(int(w.TotalPhysicalMemory), |