diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2018-04-12 10:58:41 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2018-04-12 10:58:41 +0200 |
commit | f96b6a801d423eeaff73a0f223e9fee27678963a (patch) | |
tree | 06db7ed1311c6ef62f6446e96cdb756d82768d0c | |
parent | efbab16fd4b3e1ee5f95339cd1a75433d641048b (diff) | |
parent | b2bbd272f6b183ddc7c119d39ed5c969b399239f (diff) | |
download | psutil-f96b6a801d423eeaff73a0f223e9fee27678963a.tar.gz |
Merge branch 'master' into 771-win-cpu-count
-rw-r--r-- | appveyor.yml | 5 | ||||
-rw-r--r-- | psutil/tests/__init__.py | 30 | ||||
-rwxr-xr-x | psutil/tests/test_process.py | 4 | ||||
-rwxr-xr-x | scripts/internal/winmake.py | 18 |
4 files changed, 40 insertions, 17 deletions
diff --git a/appveyor.yml b/appveyor.yml index 1bacc065..f39053ad 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -71,14 +71,11 @@ install: # - ps: (new-object net.webclient).DownloadFile('https://raw.github.com/pypa/pip/master/contrib/get-pip.py', 'C:/get-pip.py') - "%WITH_COMPILER% %PYTHON%/python.exe -m pip --version" - "%WITH_COMPILER% %PYTHON%/python.exe -m pip install --upgrade --user setuptools pip" - - "%WITH_COMPILER% %PYTHON%/python.exe -m pip install --upgrade --user unittest2 ipaddress pypiwin32==219 wmi wheel" - "%WITH_COMPILER% %PYTHON%/python.exe -m pip freeze" - - "%WITH_COMPILER% %PYTHON%/python.exe scripts/internal/winmake.py clean" - "%WITH_COMPILER% %PYTHON%/python.exe setup.py build" - "%WITH_COMPILER% %PYTHON%/python.exe setup.py build build_ext -i" - "%WITH_COMPILER% %PYTHON%/python.exe setup.py develop" - # 1.0.1 is the latest release supporting python 2.6 - - "%WITH_COMPILER% %PYTHON%/Scripts/pip.exe install mock==1.0.1" + - "%WITH_COMPILER% %PYTHON%/python.exe scripts/internal/winmake.py setup-dev-env" build: off diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index dcdbd4fa..80404a33 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -357,7 +357,7 @@ def create_proc_children_pair(): subp = pyrun(s) child1 = psutil.Process(subp.pid) data = wait_for_file(_TESTFN2, delete=False, empty=False) - os.remove(_TESTFN2) + safe_rmpath(_TESTFN2) child2_pid = int(data) _pids_started.add(child2_pid) child2 = psutil.Process(child2_pid) @@ -663,7 +663,7 @@ def wait_for_file(fname, delete=True, empty=False): if not empty: assert data if delete: - os.remove(fname) + safe_rmpath(fname) return data @@ -685,12 +685,34 @@ def call_until(fun, expr): def safe_rmpath(path): "Convenience function for removing temporary test files or dirs" + def retry_fun(fun): + # On Windows it could happen that the file or directory has + # open handles or references preventing the delete operation + # to succeed immediately, so we retry for a while. See: + # https://bugs.python.org/issue33240 + stop_at = time.time() + 1 + while time.time() < stop_at: + try: + return fun() + except WindowsError as _: + err = _ + if err.errno != errno.ENOENT: + raise + else: + warn("ignoring %s" % (str(err))) + time.sleep(0.01) + raise err + try: st = os.stat(path) if stat.S_ISDIR(st.st_mode): - os.rmdir(path) + fun = functools.partial(shutil.rmtree, path) + else: + fun = functools.partial(os.remove, path) + if POSIX: + fun() else: - os.remove(path) + retry_fun(fun) except OSError as err: if err.errno != errno.ENOENT: raise diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 3411114a..6f58be6d 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -238,10 +238,6 @@ class TestProcess(unittest.TestCase): percent = p.cpu_percent(interval=None) self.assertIsInstance(percent, float) self.assertGreaterEqual(percent, 0.0) - if not POSIX: - self.assertLessEqual(percent, 100.0) - else: - self.assertGreaterEqual(percent, 0.0) with self.assertRaises(ValueError): p.cpu_percent(interval=-1) diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py index 57543750..bd518f09 100755 --- a/scripts/internal/winmake.py +++ b/scripts/internal/winmake.py @@ -24,7 +24,11 @@ import sys import tempfile -PYTHON = os.getenv('PYTHON', sys.executable) +APPVEYOR = bool(os.environ.get('APPVEYOR')) +if APPVEYOR: + PYTHON = sys.executable +else: + PYTHON = os.getenv('PYTHON', sys.executable) TSCRIPT = os.getenv('TSCRIPT', 'psutil\\tests\\__main__.py') GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py" PY3 = sys.version_info[0] == 3 @@ -33,20 +37,24 @@ ROOT_DIR = os.path.realpath(os.path.join(HERE, "..", "..")) DEPS = [ "coverage", "flake8", - "ipaddress", - "mock", "nose", "pdbpp", "perf", "pip", - "pypiwin32", + "pypiwin32==219" if sys.version_info[:2] <= (3, 4) else "pypiwin32", "pyreadline", "setuptools", - "unittest2", "wheel", "wmi", "requests" ] +if sys.version_info[:2] <= (2, 6): + DEPS.append('unittest2') +if sys.version_info[:2] <= (2, 7): + DEPS.append('mock') +if sys.version_info[:2] <= (3, 2): + DEPS.append('ipaddress') + _cmds = {} if PY3: basestring = str |