diff options
author | Giampaolo Rodola' <g.rodola@gmail.com> | 2013-04-10 08:48:04 -0700 |
---|---|---|
committer | Giampaolo Rodola' <g.rodola@gmail.com> | 2013-04-10 08:48:04 -0700 |
commit | b108b242835d379a79d0b5f7634ea4e036dbd753 (patch) | |
tree | 79e502f708d418a27724f137f667353155830730 | |
parent | 3bd1fb8adee0b959dfb13a8b87b541411c0d784b (diff) | |
download | psutil-b108b242835d379a79d0b5f7634ea4e036dbd753.tar.gz |
fix some test failures on Windows
-rw-r--r-- | psutil/__init__.py | 2 | ||||
-rw-r--r-- | psutil/_psmswindows.py | 2 | ||||
-rw-r--r-- | test/test_psutil.py | 15 |
3 files changed, 15 insertions, 4 deletions
diff --git a/psutil/__init__.py b/psutil/__init__.py index f4d241a5..b62f8d43 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -1283,6 +1283,8 @@ def test(): ctime = ctime.strftime("%H:%M") else: ctime = ctime.strftime("%b%d") + else: + ctime = '' cputime = time.strftime("%M:%S", time.localtime(sum(pinfo['cpu_times']))) user = pinfo['username'] if os.name == 'nt' and '\\' in user: diff --git a/psutil/_psmswindows.py b/psutil/_psmswindows.py index 9d582ef2..30a56254 100644 --- a/psutil/_psmswindows.py +++ b/psutil/_psmswindows.py @@ -36,7 +36,7 @@ except Exception: NUM_CPUS = None warnings.warn("couldn't determine platform's NUM_CPUS", RuntimeWarning) try: - BOOT_TIME = _psutil_mswindows.get_system_uptime() + BOOT_TIME = _psutil_mswindows.get_system_boot_time() except Exception, err: BOOT_TIME = None warnings.warn("couldn't determine platform's BOOT_TIME", RuntimeWarning) diff --git a/test/test_psutil.py b/test/test_psutil.py index c20e350d..f86f18c9 100644 --- a/test/test_psutil.py +++ b/test/test_psutil.py @@ -329,13 +329,18 @@ class TestCase(unittest.TestCase): def test_BOOT_TIME(self, arg=None): x = arg or psutil.BOOT_TIME - assert isinstance(x, float) - assert x > 0 + assert isinstance(x, float), x + assert x > 0, x assert x < time.time(), x def test_get_boot_time(self): self.test_BOOT_TIME(psutil.get_boot_time()) - self.assertEqual(psutil.get_boot_time(), psutil.BOOT_TIME) + if WINDOWS: + # work around float precision issues; give it 1 secs tolerance + diff = abs(psutil.get_boot_time() - psutil.BOOT_TIME) + assert diff < 1, diff + else: + self.assertEqual(psutil.get_boot_time(), psutil.BOOT_TIME) def test_NUM_CPUS(self): self.assertEqual(psutil.NUM_CPUS, len(psutil.cpu_times(percpu=True))) @@ -556,6 +561,8 @@ class TestCase(unittest.TestCase): def test_disk_partitions(self): for disk in psutil.disk_partitions(all=False): + if WINDOWS and 'cdrom' in disk.opts: + continue assert os.path.exists(disk.device), disk assert os.path.isdir(disk.mountpoint), disk assert disk.fstype, disk @@ -1642,6 +1649,8 @@ class TestCase(unittest.TestCase): except ImportError: if name not in psutil.__all__: fun = getattr(psutil, name) + if fun is None: + continue if 'deprecated' not in fun.__doc__.lower(): self.fail('%r not in psutil.__all__' % name) |