diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-04-23 01:55:27 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-04-23 01:55:27 +0200 |
commit | b78f2f20128fb541b7808d8e96be68aa0e33def5 (patch) | |
tree | d4ec2fa508feb649a72cb0a34d0bb6c463ca0cec | |
parent | 8e291c35a11a8bad883cfeb2473d056e2c9d6e16 (diff) | |
download | psutil-b78f2f20128fb541b7808d8e96be68aa0e33def5.tar.gz |
increase test coverage for sensors_temperatures() + refactor test constants + bump travis tollerance during tests
-rwxr-xr-x | .ci/travis/install.sh | 21 | ||||
-rwxr-xr-x | .ci/travis/run.sh | 4 | ||||
-rw-r--r-- | psutil/__init__.py | 14 | ||||
-rw-r--r-- | psutil/tests/__init__.py | 51 | ||||
-rwxr-xr-x | psutil/tests/test_system.py | 9 |
5 files changed, 51 insertions, 48 deletions
diff --git a/.ci/travis/install.sh b/.ci/travis/install.sh index 24996c3d..0d69e56d 100755 --- a/.ci/travis/install.sh +++ b/.ci/travis/install.sh @@ -3,8 +3,9 @@ set -e set -x +PYVER=`python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))'` + uname -a -python -c "import sys; print(sys.version)" if [[ "$(uname -s)" == 'Darwin' ]]; then brew update || brew update @@ -16,22 +17,10 @@ if [[ "$(uname -s)" == 'Darwin' ]]; then fi case "${PYVER}" in - # py26) - # pyenv install 2.6.9 - # pyenv virtualenv 2.6.9 psutil - # ;; py27) pyenv install 2.7.10 pyenv virtualenv 2.7.10 psutil ;; - # py32) - # pyenv install 3.2.6 - # pyenv virtualenv 3.2.6 psutil - # ;; - # py33) - # pyenv install 3.3.6 - # pyenv virtualenv 3.3.6 psutil - # ;; py34) pyenv install 3.4.3 pyenv virtualenv 3.4.3 psutil @@ -42,11 +31,11 @@ if [[ "$(uname -s)" == 'Darwin' ]]; then fi # old python versions -if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then +if [[ $PYVER == '2.6' ]]; then pip install -U ipaddress unittest2 argparse mock==1.0.1 -elif [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then +elif [[ $PYVER == '2.7' ]]; then pip install -U ipaddress mock -elif [[ $TRAVIS_PYTHON_VERSION == '3.3' ]]; then +elif [[ $PYVER == '3.3' ]]; then pip install -U ipaddress fi diff --git a/.ci/travis/run.sh b/.ci/travis/run.sh index ae5b09e2..eec282ce 100755 --- a/.ci/travis/run.sh +++ b/.ci/travis/run.sh @@ -18,7 +18,7 @@ python setup.py build python setup.py develop # run tests -if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]] && [[ "$(uname -s)" != 'Darwin' ]]; then +if [[ $PYVER == '2.7' ]] && [[ "$(uname -s)" != 'Darwin' ]]; then coverage run psutil/tests/runner.py --include="psutil/*" --omit="test/*,*setup*" else python psutil/tests/runner.py @@ -26,7 +26,7 @@ fi # Run memory leak tests and linter only on Linux and latest major Python # versions. -if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]] || [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then +if [[ $PYVER == '2.7' ]] || [[ $PYVER == '3.6' ]]; then python psutil/tests/test_memory_leaks.py if [[ "$(uname -s)" != 'Darwin' ]]; then diff --git a/psutil/__init__.py b/psutil/__init__.py index 5ce4f42b..46a81957 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -2205,8 +2205,9 @@ if hasattr(_psplatform, "sensors_temperatures"): All temperatures are expressed in celsius unless *fahrenheit* is set to True. """ - def to_fahrenheit(n): - return (float(n) * 9 / 5) + 32 + def convert(n): + if n is not None: + return (float(n) * 9 / 5) + 32 if fahrenheit else n ret = collections.defaultdict(list) rawdict = _psplatform.sensors_temperatures() @@ -2214,12 +2215,9 @@ if hasattr(_psplatform, "sensors_temperatures"): for name, values in rawdict.items(): while values: label, current, high, critical = values.pop(0) - if fahrenheit: - current = to_fahrenheit(current) - if high is not None: - high = to_fahrenheit(high) - if critical is not None: - critical = to_fahrenheit(critical) + current = convert(current) + high = convert(high) + critical = convert(critical) if high and not critical: critical = high diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index 13c4cfca..d18bc738 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -90,18 +90,35 @@ __all__ = [ # --- constants # =================================================================== +# --- platforms -# conf for retry_before_failing() decorator +TOX = os.getenv('TOX') or '' in ('1', 'true') +PYPY = '__pypy__' in sys.builtin_module_names +WIN_VISTA = (6, 0, 0) if WINDOWS else None +# whether we're running this test suite on Travis (https://travis-ci.org/) +TRAVIS = bool(os.environ.get('TRAVIS')) +# whether we're running this test suite on Appveyor for Windows +# (http://www.appveyor.com/) +APPVEYOR = bool(os.environ.get('APPVEYOR')) + +# --- configurable defaults + +# how many times retry_before_failing() decorator will retry NO_RETRIES = 10 -# bytes tolerance for OS memory related tests +# bytes tolerance for system-wide memory related tests MEMORY_TOLERANCE = 500 * 1024 # 500KB # the timeout used in functions which have to wait GLOBAL_TIMEOUT = 3 +# test output verbosity +VERBOSITY = 1 if os.getenv('SILENT') or TOX else 2 +# be more tolerant if we're on travis / appveyor in order to avoid +# false positives +if TRAVIS or APPVEYOR: + NO_RETRIES *= 3 + MEMORY_TOLERANCE *= 3 + GLOBAL_TIMEOUT *= 3 -AF_INET6 = getattr(socket, "AF_INET6") -AF_UNIX = getattr(socket, "AF_UNIX", None) -PYTHON = os.path.realpath(sys.executable) -DEVNULL = open(os.devnull, 'r+') +# --- files TESTFILE_PREFIX = '$testfn' TESTFN = os.path.join(os.path.realpath(os.getcwd()), TESTFILE_PREFIX) @@ -113,25 +130,19 @@ if not PY3: except UnicodeDecodeError: TESTFN_UNICODE = TESTFN + "-???" -TOX = os.getenv('TOX') or '' in ('1', 'true') -PYPY = '__pypy__' in sys.builtin_module_names +# --- paths -ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), - '..', '..')) +ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) SCRIPTS_DIR = os.path.join(ROOT_DIR, 'scripts') -WIN_VISTA = (6, 0, 0) if WINDOWS else None +# --- misc + +AF_INET6 = getattr(socket, "AF_INET6") +AF_UNIX = getattr(socket, "AF_UNIX", None) +PYTHON = os.path.realpath(sys.executable) +DEVNULL = open(os.devnull, 'r+') VALID_PROC_STATUSES = [getattr(psutil, x) for x in dir(psutil) if x.startswith('STATUS_')] -# whether we're running this test suite on Travis (https://travis-ci.org/) -TRAVIS = bool(os.environ.get('TRAVIS')) -# whether we're running this test suite on Appveyor for Windows -# (http://www.appveyor.com/) -APPVEYOR = bool(os.environ.get('APPVEYOR')) - -if TRAVIS or APPVEYOR: - GLOBAL_TIMEOUT = GLOBAL_TIMEOUT * 4 -VERBOSITY = 1 if os.getenv('SILENT') or TOX else 2 # assertRaisesRegexp renamed to assertRaisesRegex in 3.3; add support # for the new name diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py index 013ae8e3..fa9e8791 100755 --- a/psutil/tests/test_system.py +++ b/psutil/tests/test_system.py @@ -768,8 +768,8 @@ class TestSystemAPIs(unittest.TestCase): @unittest.skipUnless(hasattr(psutil, "sensors_temperatures"), "platform not supported") - def test_sensors_temperatures(self): - temps = psutil.sensors_temperatures() + def test_sensors_temperatures(self, fahrenheit=False): + temps = psutil.sensors_temperatures(fahrenheit=fahrenheit) for name, entries in temps.items(): self.assertIsInstance(name, (str, unicode)) for entry in entries: @@ -781,6 +781,11 @@ class TestSystemAPIs(unittest.TestCase): if entry.critical is not None: self.assertGreaterEqual(entry.critical, 0) + @unittest.skipUnless(hasattr(psutil, "sensors_temperatures"), + "platform not supported") + def test_sensors_temperatures_fahreneit(self): + self.test_sensors_temperatures(fahrenheit=True) + @unittest.skipUnless(hasattr(psutil, "sensors_battery"), "platform not supported") def test_sensors_battery(self): |