diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-09-05 01:17:18 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-09-05 01:17:18 +0200 |
commit | bd5a2c316833ce690b8f7a375502796e0fd5f305 (patch) | |
tree | a4850b89eef762802718da5ca1232c3de5043972 | |
parent | ab8d678112df54c7483ccb5f95f25e640752426a (diff) | |
download | psutil-bd5a2c316833ce690b8f7a375502796e0fd5f305.tar.gz |
win test: make win32 external modules mandatory
-rwxr-xr-x | .git-pre-commit | 12 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | psutil/tests/__init__.py | 22 | ||||
-rw-r--r-- | psutil/tests/test_process.py | 4 | ||||
-rw-r--r-- | psutil/tests/test_windows.py | 23 |
5 files changed, 22 insertions, 41 deletions
diff --git a/.git-pre-commit b/.git-pre-commit index 804c0a86..f6bca80e 100755 --- a/.git-pre-commit +++ b/.git-pre-commit @@ -1,8 +1,14 @@ #!/usr/bin/env python -# This gets executed on 'git commit' and rejects the commit in case the -# submitted code does not pass validation. -# Install it with "make install-git-hooks" +# Copyright (c) 2009 Giampaolo Rodola'. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +""" +This gets executed on 'git commit' and rejects the commit in case the +submitted code does not pass validation. +Install it with "make install-git-hooks". +""" import os import subprocess @@ -66,7 +66,7 @@ build: clean # Install this package + GIT hooks. Install is done: # - as the current user, in order to avoid permission issues # - in development / edit mode, so that source can be modified on the fly -install: install_git_hooks build +install: build $(PYTHON) setup.py develop $(INSTALL_OPTS) rm -rf tmp diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index da71826c..874cbfeb 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -13,6 +13,7 @@ import atexit import contextlib import errno import functools +import ipaddress # python >= 3.3 / requires "pip install ipaddress" import os import re import shutil @@ -28,10 +29,7 @@ import warnings from socket import AF_INET from socket import SOCK_DGRAM from socket import SOCK_STREAM -try: - import ipaddress # python >= 3.3 -except ImportError: - ipaddress = None + try: from unittest import mock # py3 except ImportError: @@ -128,8 +126,6 @@ TRAVIS = bool(os.environ.get('TRAVIS')) # (http://www.appveyor.com/) APPVEYOR = bool(os.environ.get('APPVEYOR')) -if TRAVIS or 'tox' in sys.argv[0]: - import ipaddress if TRAVIS or APPVEYOR: GLOBAL_TIMEOUT = GLOBAL_TIMEOUT * 4 VERBOSITY = 1 if os.getenv('SILENT') or TOX else 2 @@ -535,16 +531,14 @@ def check_net_address(addr, family): assert len(octs) == 4, addr for num in octs: assert 0 <= num <= 255, addr - if ipaddress: - if not PY3: - addr = unicode(addr) - ipaddress.IPv4Address(addr) + if not PY3: + addr = unicode(addr) + ipaddress.IPv4Address(addr) elif family == AF_INET6: assert isinstance(addr, str), addr - if ipaddress: - if not PY3: - addr = unicode(addr) - ipaddress.IPv6Address(addr) + if not PY3: + addr = unicode(addr) + ipaddress.IPv6Address(addr) elif family == psutil.AF_LINK: assert re.match('([a-fA-F0-9]{2}[:|\-]?){6}', addr) is not None, addr else: diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 1d223ada..0d7d06be 100644 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -26,10 +26,6 @@ import types from socket import AF_INET from socket import SOCK_DGRAM from socket import SOCK_STREAM -try: - import ipaddress # python >= 3.3 -except ImportError: - ipaddress = None import psutil diff --git a/psutil/tests/test_windows.py b/psutil/tests/test_windows.py index 962af74c..2998e5d0 100644 --- a/psutil/tests/test_windows.py +++ b/psutil/tests/test_windows.py @@ -18,14 +18,12 @@ import time import traceback try: - import wmi # requires "pip install wmi" -except ImportError: - wmi = None -try: - import win32api # requires "pip install pypiwin32" + import win32api # requires "pip install pypiwin32" / "make setup-dev-env" import win32con + import wmi # requires "pip install wmi" / "make setup-dev-env" except ImportError: - win32api = win32con = None + if os.name == 'nt': + raise import psutil from psutil import WINDOWS @@ -120,13 +118,11 @@ class WindowsSpecificTestCase(unittest.TestCase): # --- Process class tests - @unittest.skipIf(wmi is None, "wmi module is not installed") def test_process_name(self): w = wmi.WMI().Win32_Process(ProcessId=self.pid)[0] p = psutil.Process(self.pid) self.assertEqual(p.name(), w.Caption) - @unittest.skipIf(wmi is None, "wmi module is not installed") def test_process_exe(self): w = wmi.WMI().Win32_Process(ProcessId=self.pid)[0] p = psutil.Process(self.pid) @@ -134,14 +130,12 @@ class WindowsSpecificTestCase(unittest.TestCase): # Being Windows paths case-insensitive we ignore that. self.assertEqual(p.exe().lower(), w.ExecutablePath.lower()) - @unittest.skipIf(wmi is None, "wmi module is not installed") def test_process_cmdline(self): w = wmi.WMI().Win32_Process(ProcessId=self.pid)[0] p = psutil.Process(self.pid) self.assertEqual(' '.join(p.cmdline()), w.CommandLine.replace('"', '')) - @unittest.skipIf(wmi is None, "wmi module is not installed") def test_process_username(self): w = wmi.WMI().Win32_Process(ProcessId=self.pid)[0] p = psutil.Process(self.pid) @@ -149,7 +143,6 @@ class WindowsSpecificTestCase(unittest.TestCase): username = "%s\\%s" % (domain, username) self.assertEqual(p.username(), username) - @unittest.skipIf(wmi is None, "wmi module is not installed") def test_process_rss_memory(self): time.sleep(0.1) w = wmi.WMI().Win32_Process(ProcessId=self.pid)[0] @@ -157,7 +150,6 @@ class WindowsSpecificTestCase(unittest.TestCase): rss = p.memory_info().rss self.assertEqual(rss, int(w.WorkingSetSize)) - @unittest.skipIf(wmi is None, "wmi module is not installed") def test_process_vms_memory(self): time.sleep(0.1) w = wmi.WMI().Win32_Process(ProcessId=self.pid)[0] @@ -171,7 +163,6 @@ class WindowsSpecificTestCase(unittest.TestCase): if (vms != wmi_usage) and (vms != wmi_usage * 1024): self.fail("wmi=%s, psutil=%s" % (wmi_usage, vms)) - @unittest.skipIf(wmi is None, "wmi module is not installed") def test_process_create_time(self): w = wmi.WMI().Win32_Process(ProcessId=self.pid)[0] p = psutil.Process(self.pid) @@ -188,7 +179,6 @@ class WindowsSpecificTestCase(unittest.TestCase): num_cpus = int(os.environ['NUMBER_OF_PROCESSORS']) self.assertEqual(num_cpus, psutil.cpu_count()) - @unittest.skipIf(wmi is None, "wmi module is not installed") def test_total_phymem(self): w = wmi.WMI().Win32_ComputerSystem()[0] self.assertEqual(int(w.TotalPhysicalMemory), @@ -207,7 +197,6 @@ class WindowsSpecificTestCase(unittest.TestCase): # # Note: this test is not very reliable - @unittest.skipIf(wmi is None, "wmi module is not installed") @unittest.skipIf(APPVEYOR, "test not relieable on appveyor") def test_pids(self): # Note: this test might fail if the OS is starting/killing @@ -217,7 +206,6 @@ class WindowsSpecificTestCase(unittest.TestCase): psutil_pids = set(psutil.pids()) self.assertEqual(wmi_pids, psutil_pids) - @unittest.skipIf(wmi is None, "wmi module is not installed") @retry_before_failing() def test_disks(self): ps_parts = psutil.disk_partitions(all=True) @@ -247,7 +235,6 @@ class WindowsSpecificTestCase(unittest.TestCase): else: self.fail("can't find partition %s" % repr(ps_part)) - @unittest.skipIf(win32api is None, "pywin32 module is not installed") def test_num_handles(self): p = psutil.Process(os.getpid()) before = p.num_handles() @@ -258,7 +245,6 @@ class WindowsSpecificTestCase(unittest.TestCase): win32api.CloseHandle(handle) self.assertEqual(p.num_handles(), before) - @unittest.skipIf(win32api is None, "pywin32 module is not installed") def test_num_handles_2(self): # Note: this fails from time to time; I'm keen on thinking # it doesn't mean something is broken @@ -316,7 +302,6 @@ class WindowsSpecificTestCase(unittest.TestCase): self.assertRaises(psutil.NoSuchProcess, p.send_signal, signal.CTRL_BREAK_EVENT) - @unittest.skipIf(wmi is None, "wmi module is not installed") def test_net_if_stats(self): ps_names = set(cext.net_if_stats()) wmi_adapters = wmi.WMI().Win32_NetworkAdapter() |