diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2021-10-14 17:16:23 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2021-10-14 17:16:23 +0200 |
commit | 4e5626d05e876ef0630e93976449de309e18b499 (patch) | |
tree | 66b64e7d2e1cb6ce21931a9cbebd8456db4e6ce5 | |
parent | aa0412e4ead1f2ab53cb95d6121aea8ac2fd20eb (diff) | |
download | psutil-4e5626d05e876ef0630e93976449de309e18b499.tar.gz |
tests: move per-module imports at the top of the file(s)
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
-rw-r--r-- | psutil/tests/__init__.py | 6 | ||||
-rwxr-xr-x | psutil/tests/test_linux.py | 11 | ||||
-rwxr-xr-x | psutil/tests/test_osx.py | 6 | ||||
-rwxr-xr-x | psutil/tests/test_windows.py | 6 |
4 files changed, 17 insertions, 12 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index e0df67fa..245ff2f3 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -72,6 +72,9 @@ if sys.version_info >= (3, 4): else: enum = None +if POSIX: + from psutil._psposix import wait_pid + __all__ = [ # constants @@ -482,9 +485,6 @@ def terminate(proc_or_pid, sig=signal.SIGTERM, wait_timeout=GLOBAL_TIMEOUT): Does nothing if the process does not exist. Return process exit status. """ - if POSIX: - from psutil._psposix import wait_pid - def wait(proc, timeout): if isinstance(proc, subprocess.Popen) and not PY3: proc.wait() diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py index 6c01edbd..d2d8e7d4 100755 --- a/psutil/tests/test_linux.py +++ b/psutil/tests/test_linux.py @@ -47,6 +47,11 @@ from psutil.tests import TOLERANCE_SYS_MEM from psutil.tests import unittest from psutil.tests import which +if LINUX: + from psutil._pslinux import calculate_avail_vmem + from psutil._pslinux import CLOCK_TICKS + from psutil._pslinux import open_binary + HERE = os.path.abspath(os.path.dirname(__file__)) SIOCGIFADDR = 0x8915 @@ -58,6 +63,7 @@ if LINUX: SECTOR_SIZE = 512 EMPTY_TEMPERATURES = not glob.glob('/sys/class/hwmon/hwmon*') + # ===================================================================== # --- utils # ===================================================================== @@ -358,9 +364,6 @@ class TestSystemVirtualMemory(PsutilTestCase): def test_avail_old_percent(self): # Make sure that our calculation of avail mem for old kernels # is off by max 15%. - from psutil._pslinux import calculate_avail_vmem - from psutil._pslinux import open_binary - mems = {} with open_binary('/proc/meminfo') as f: for line in f: @@ -1994,8 +1997,6 @@ class TestProcess(PsutilTestCase): self.assertEqual(exc.exception.name, p.name()) def test_stat_file_parsing(self): - from psutil._pslinux import CLOCK_TICKS - args = [ "0", # pid "(cat)", # name diff --git a/psutil/tests/test_osx.py b/psutil/tests/test_osx.py index b7a0b088..f797de71 100755 --- a/psutil/tests/test_osx.py +++ b/psutil/tests/test_osx.py @@ -11,6 +11,7 @@ import time import psutil from psutil import MACOS +from psutil import POSIX from psutil.tests import HAS_BATTERY from psutil.tests import PsutilTestCase from psutil.tests import retry_on_failure @@ -21,6 +22,9 @@ from psutil.tests import TOLERANCE_DISK_USAGE from psutil.tests import TOLERANCE_SYS_MEM from psutil.tests import unittest +if POSIX: + from psutil._psutil_posix import getpagesize + def sysctl(cmdline): """Expects a sysctl command with an argument and parse the result @@ -36,8 +40,6 @@ def sysctl(cmdline): def vm_stat(field): """Wrapper around 'vm_stat' cmdline utility.""" - from psutil._psutil_posix import getpagesize - out = sh('vm_stat') for line in out.split('\n'): if field in line: diff --git a/psutil/tests/test_windows.py b/psutil/tests/test_windows.py index 01b710c2..9d5b0113 100755 --- a/psutil/tests/test_windows.py +++ b/psutil/tests/test_windows.py @@ -47,6 +47,10 @@ if WINDOWS and not PYPY: import win32process import wmi # requires "pip install wmi" / "make setup-dev-env" +if WINDOWS: + from psutil._pswindows import ACCESS_DENIED_SET + from psutil._pswindows import convert_oserror + cext = psutil._psplatform.cext @@ -56,7 +60,6 @@ def wrap_exceptions(fun): try: return fun(self, *args, **kwargs) except OSError as err: - from psutil._pswindows import ACCESS_DENIED_SET if err.errno in ACCESS_DENIED_SET: raise psutil.AccessDenied(None, None) if err.errno == errno.ESRCH: @@ -633,7 +636,6 @@ class TestDualProcessImplementation(PsutilTestCase): assert fun.called def test_cmdline(self): - from psutil._pswindows import convert_oserror for pid in psutil.pids(): try: a = cext.proc_cmdline(pid, use_peb=True) |