diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2023-04-01 12:24:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-01 12:24:59 +0200 |
commit | 7eadee31db2f038763a3a6f978db1ea76bbc4674 (patch) | |
tree | 55d75da147cc3a40b989e18df1126de5167b66cf /psutil | |
parent | 7d55ce4e3d81705264398a15ffaa1896f4e1aefc (diff) | |
download | psutil-7eadee31db2f038763a3a6f978db1ea76bbc4674.tar.gz |
Fix pylint warnings / cleanup (#2218)
Diffstat (limited to 'psutil')
-rw-r--r-- | psutil/__init__.py | 2 | ||||
-rw-r--r-- | psutil/_common.py | 4 | ||||
-rw-r--r-- | psutil/_compat.py | 4 | ||||
-rw-r--r-- | psutil/_psaix.py | 4 | ||||
-rw-r--r-- | psutil/_pslinux.py | 6 | ||||
-rw-r--r-- | psutil/_pssunos.py | 2 | ||||
-rw-r--r-- | psutil/_pswindows.py | 2 | ||||
-rw-r--r-- | psutil/tests/__init__.py | 23 | ||||
-rwxr-xr-x | psutil/tests/test_bsd.py | 2 | ||||
-rwxr-xr-x | psutil/tests/test_connections.py | 2 | ||||
-rwxr-xr-x | psutil/tests/test_contracts.py | 2 | ||||
-rwxr-xr-x | psutil/tests/test_linux.py | 18 | ||||
-rwxr-xr-x | psutil/tests/test_misc.py | 20 | ||||
-rwxr-xr-x | psutil/tests/test_osx.py | 37 | ||||
-rwxr-xr-x | psutil/tests/test_posix.py | 5 | ||||
-rwxr-xr-x | psutil/tests/test_process.py | 9 | ||||
-rwxr-xr-x | psutil/tests/test_system.py | 18 | ||||
-rwxr-xr-x | psutil/tests/test_testutils.py | 10 | ||||
-rwxr-xr-x | psutil/tests/test_unicode.py | 3 |
19 files changed, 65 insertions, 108 deletions
diff --git a/psutil/__init__.py b/psutil/__init__.py index deaf02ea..6036cbe9 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -516,7 +516,7 @@ class Process(object): "s" if len(invalid_names) > 1 else "", ", ".join(map(repr, invalid_names)))) - retdict = dict() + retdict = {} ls = attrs or valid_names with self.oneshot(): for name in ls: diff --git a/psutil/_common.py b/psutil/_common.py index 74ae2557..92286746 100644 --- a/psutil/_common.py +++ b/psutil/_common.py @@ -43,7 +43,7 @@ else: # can't take it from _common.py as this script is imported by setup.py PY3 = sys.version_info[0] == 3 -PSUTIL_DEBUG = bool(os.getenv('PSUTIL_DEBUG', 0)) +PSUTIL_DEBUG = bool(os.getenv('PSUTIL_DEBUG')) _DEFAULT = object() __all__ = [ @@ -924,7 +924,7 @@ def debug(msg): """If PSUTIL_DEBUG env var is set, print a debug message to stderr.""" if PSUTIL_DEBUG: import inspect - fname, lineno, func_name, lines, index = inspect.getframeinfo( + fname, lineno, _, lines, index = inspect.getframeinfo( inspect.currentframe().f_back) if isinstance(msg, Exception): if isinstance(msg, (OSError, IOError, EnvironmentError)): diff --git a/psutil/_compat.py b/psutil/_compat.py index 52e762b1..2531cf4b 100644 --- a/psutil/_compat.py +++ b/psutil/_compat.py @@ -254,7 +254,7 @@ except ImportError: http://docs.python.org/3/library/functools.html#functools.lru_cache """ def decorating_function(user_function): - cache = dict() + cache = {} stats = [0, 0] HITS, MISSES = 0, 1 make_key = _make_key @@ -432,7 +432,7 @@ except ImportError: try: from subprocess import TimeoutExpired as SubprocessTimeoutExpired except ImportError: - class SubprocessTimeoutExpired: + class SubprocessTimeoutExpired(Exception): pass diff --git a/psutil/_psaix.py b/psutil/_psaix.py index 2391478c..5c41069c 100644 --- a/psutil/_psaix.py +++ b/psutil/_psaix.py @@ -465,8 +465,8 @@ class Process(object): @wrap_exceptions def cpu_times(self): - cpu_times = cext.proc_cpu_times(self.pid, self._procfs_path) - return _common.pcputimes(*cpu_times) + t = cext.proc_cpu_times(self.pid, self._procfs_path) + return _common.pcputimes(*t) @wrap_exceptions def terminal(self): diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 1bdeabfe..d178fe16 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -327,8 +327,8 @@ except ImportError: pid, resource_, ctypes.byref(new), ctypes.byref(current)) if ret != 0: - errno = ctypes.get_errno() - raise OSError(errno, os.strerror(errno)) + errno_ = ctypes.get_errno() + raise OSError(errno_, os.strerror(errno_)) return (current.rlim_cur, current.rlim_max) @@ -1837,7 +1837,7 @@ class Process(object): ) except KeyError as err: raise ValueError("%r field was not found in %s; found fields " - "are %r" % (err[0], fname, fields)) + "are %r" % (err.args[0], fname, fields)) @wrap_exceptions def cpu_times(self): diff --git a/psutil/_pssunos.py b/psutil/_pssunos.py index 541c1aa4..8663de3c 100644 --- a/psutil/_pssunos.py +++ b/psutil/_pssunos.py @@ -143,7 +143,7 @@ def swap_memory(): p = subprocess.Popen(['/usr/bin/env', 'PATH=/usr/sbin:/sbin:%s' % os.environ['PATH'], 'swap', '-l'], stdout=subprocess.PIPE) - stdout, stderr = p.communicate() + stdout, _ = p.communicate() if PY3: stdout = stdout.decode(sys.stdout.encoding) if p.returncode != 0: diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index b546f15d..3802f3ed 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -699,7 +699,7 @@ def retry_error_partial_copy(fun): def wrapper(self, *args, **kwargs): delay = 0.0001 times = 33 - for x in range(times): # retries for roughly 1 second + for _ in range(times): # retries for roughly 1 second try: return fun(self, *args, **kwargs) except WindowsError as _: diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index cdc8b671..e82bb38d 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -85,22 +85,19 @@ __all__ = [ "HAS_CPU_AFFINITY", "HAS_CPU_FREQ", "HAS_ENVIRON", "HAS_PROC_IO_COUNTERS", "HAS_IONICE", "HAS_MEMORY_MAPS", "HAS_PROC_CPU_NUM", "HAS_RLIMIT", "HAS_SENSORS_BATTERY", "HAS_BATTERY", "HAS_SENSORS_FANS", - "HAS_SENSORS_TEMPERATURES", "HAS_MEMORY_FULL_INFO", "MACOS_11PLUS", + "HAS_SENSORS_TEMPERATURES", "MACOS_11PLUS", "MACOS_12PLUS", "COVERAGE", # subprocesses 'pyrun', 'terminate', 'reap_children', 'spawn_testproc', 'spawn_zombie', 'spawn_children_pair', # threads - 'ThreadTask' + 'ThreadTask', # test utils 'unittest', 'skip_on_access_denied', 'skip_on_not_implemented', 'retry_on_failure', 'TestMemoryLeak', 'PsutilTestCase', 'process_namespace', 'system_namespace', 'print_sysinfo', - # install utils - 'install_pip', 'install_test_deps', # fs utils - 'chdir', 'safe_rmpath', 'create_exe', 'decode_path', 'encode_path', - 'get_testfn', + 'chdir', 'safe_rmpath', 'create_exe', 'get_testfn', # os 'get_winver', 'kernel_version', # sync primitives @@ -458,7 +455,7 @@ def spawn_zombie(): zpid = int(conn.recv(1024)) _pids_started.add(zpid) zombie = psutil.Process(zpid) - call_until(lambda: zombie.status(), "ret == psutil.STATUS_ZOMBIE") + call_until(zombie.status, "ret == psutil.STATUS_ZOMBIE") return (parent, zombie) finally: conn.close() @@ -628,7 +625,7 @@ def reap_children(recursive=False): if children: for p in children: terminate(p, wait_timeout=None) - gone, alive = psutil.wait_procs(children, timeout=GLOBAL_TIMEOUT) + _, alive = psutil.wait_procs(children, timeout=GLOBAL_TIMEOUT) for p in alive: warn("couldn't terminate process %r; attempting kill()" % p) terminate(p, sig=signal.SIGKILL) @@ -999,7 +996,7 @@ class TestMemoryLeak(PsutilTestCase): retries = 10 if CI_TESTING else 5 verbose = True _thisproc = psutil.Process() - _psutil_debug_orig = bool(os.getenv('PSUTIL_DEBUG', 0)) + _psutil_debug_orig = bool(os.getenv('PSUTIL_DEBUG')) @classmethod def setUpClass(cls): @@ -1059,7 +1056,7 @@ class TestMemoryLeak(PsutilTestCase): diff = mem2 - mem1 # can also be negative return diff - def _check_mem(self, fun, times, warmup_times, retries, tolerance): + def _check_mem(self, fun, times, retries, tolerance): messages = [] prev_mem = 0 increase = times @@ -1104,8 +1101,7 @@ class TestMemoryLeak(PsutilTestCase): self._call_ntimes(fun, warmup_times) # warm up self._check_fds(fun) - self._check_mem(fun, times=times, warmup_times=warmup_times, - retries=retries, tolerance=tolerance) + self._check_mem(fun, times=times, retries=retries, tolerance=tolerance) def execute_w_exc(self, exc, fun, **kwargs): """Convenience method to test a callable while making sure it @@ -1122,7 +1118,6 @@ def print_sysinfo(): import datetime import getpass import locale - import platform import pprint try: import pip @@ -1616,7 +1611,7 @@ def check_net_address(addr, family): elif family == psutil.AF_LINK: assert re.match(r'([a-fA-F0-9]{2}[:|\-]?){6}', addr) is not None, addr else: - raise ValueError("unknown family %r", family) + raise ValueError("unknown family %r" % family) def check_connection_ntuple(conn): diff --git a/psutil/tests/test_bsd.py b/psutil/tests/test_bsd.py index e541547d..29ea384d 100755 --- a/psutil/tests/test_bsd.py +++ b/psutil/tests/test_bsd.py @@ -36,7 +36,7 @@ if BSD: PAGESIZE = getpagesize() # muse requires root privileges - MUSE_AVAILABLE = True if os.getuid() == 0 and which('muse') else False + MUSE_AVAILABLE = os.getuid() == 0 and which('muse') else: PAGESIZE = None MUSE_AVAILABLE = False diff --git a/psutil/tests/test_connections.py b/psutil/tests/test_connections.py index f3b1f837..d47233bc 100755 --- a/psutil/tests/test_connections.py +++ b/psutil/tests/test_connections.py @@ -501,7 +501,7 @@ class TestSystemWideConnections(ConnectionTestCase): pids = [] times = 10 fnames = [] - for i in range(times): + for _ in range(times): fname = self.get_testfn() fnames.append(fname) src = textwrap.dedent("""\ diff --git a/psutil/tests/test_contracts.py b/psutil/tests/test_contracts.py index 3b806ee3..b767e3eb 100755 --- a/psutil/tests/test_contracts.py +++ b/psutil/tests/test_contracts.py @@ -176,7 +176,7 @@ class TestAvailProcessAPIs(PsutilTestCase): def test_io_counters(self): hasit = hasattr(psutil.Process, "io_counters") - self.assertEqual(hasit, False if MACOS or SUNOS else True) + self.assertEqual(hasit, not (MACOS or SUNOS)) def test_num_fds(self): self.assertEqual(hasattr(psutil.Process, "num_fds"), POSIX) diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py index 964416b3..e1de6706 100755 --- a/psutil/tests/test_linux.py +++ b/psutil/tests/test_linux.py @@ -749,7 +749,7 @@ class TestSystemCPUCountLogical(PsutilTestCase): # this way we'll fall back on relying on /proc/stat with mock_open_content('/proc/cpuinfo', b"") as m: self.assertEqual(psutil._pslinux.cpu_count_logical(), original) - m.called + assert m.called @unittest.skipIf(not LINUX, "LINUX only") @@ -817,8 +817,8 @@ class TestSystemCPUFrequency(PsutilTestCase): self.assertEqual(ret.max, 0.0) self.assertEqual(ret.min, 0.0) for freq in psutil.cpu_freq(percpu=True): - self.assertEqual(ret.max, 0.0) - self.assertEqual(ret.min, 0.0) + self.assertEqual(freq.max, 0.0) + self.assertEqual(freq.min, 0.0) finally: reload_module(psutil._pslinux) reload_module(psutil) @@ -1057,7 +1057,7 @@ class TestSystemNetIOCounters(PsutilTestCase): def test_against_ifconfig(self): def ifconfig(nic): ret = {} - out = sh("ifconfig %s" % name) + out = sh("ifconfig %s" % nic) ret['packets_recv'] = int( re.findall(r'RX packets[: ](\d+)', out)[0]) ret['packets_sent'] = int( @@ -1150,7 +1150,7 @@ class TestSystemDiskPartitions(PsutilTestCase): for part in psutil.disk_partitions(all=False): usage = psutil.disk_usage(part.mountpoint) - dev, total, used, free = df(part.mountpoint) + _, total, used, free = df(part.mountpoint) self.assertEqual(usage.total, total) self.assertAlmostEqual(usage.free, free, delta=TOLERANCE_DISK_USAGE) @@ -2034,7 +2034,7 @@ class TestProcess(PsutilTestCase): # which no longer exists by the time we open() it (race # condition). threads() is supposed to ignore that instead # of raising NSP. - def open_mock(name, *args, **kwargs): + def open_mock_1(name, *args, **kwargs): if name.startswith('/proc/%s/task' % os.getpid()): raise IOError(errno.ENOENT, "") else: @@ -2042,20 +2042,20 @@ class TestProcess(PsutilTestCase): orig_open = open patch_point = 'builtins.open' if PY3 else '__builtin__.open' - with mock.patch(patch_point, side_effect=open_mock) as m: + with mock.patch(patch_point, side_effect=open_mock_1) as m: ret = psutil.Process().threads() assert m.called self.assertEqual(ret, []) # ...but if it bumps into something != ENOENT we want an # exception. - def open_mock(name, *args, **kwargs): + def open_mock_2(name, *args, **kwargs): if name.startswith('/proc/%s/task' % os.getpid()): raise IOError(errno.EPERM, "") else: return orig_open(name, *args, **kwargs) - with mock.patch(patch_point, side_effect=open_mock): + with mock.patch(patch_point, side_effect=open_mock_2): self.assertRaises(psutil.AccessDenied, psutil.Process().threads) def test_exe_mocked(self): diff --git a/psutil/tests/test_misc.py b/psutil/tests/test_misc.py index afa60b1c..a7b5d02d 100755 --- a/psutil/tests/test_misc.py +++ b/psutil/tests/test_misc.py @@ -299,19 +299,19 @@ class TestMemoizeDecorator(PsutilTestCase): def run_against(self, obj, expected_retval=None): # no args - for x in range(2): + for _ in range(2): ret = obj() self.assertEqual(self.calls, [((), {})]) if expected_retval is not None: self.assertEqual(ret, expected_retval) # with args - for x in range(2): + for _ in range(2): ret = obj(1) self.assertEqual(self.calls, [((), {}), ((1, ), {})]) if expected_retval is not None: self.assertEqual(ret, expected_retval) # with args + kwargs - for x in range(2): + for _ in range(2): ret = obj(1, bar=2) self.assertEqual( self.calls, [((), {}), ((1, ), {}), ((1, ), {'bar': 2})]) @@ -400,19 +400,19 @@ class TestMemoizeDecorator(PsutilTestCase): calls = [] # no args - for x in range(2): + for _ in range(2): ret = foo() expected = ((), {}) self.assertEqual(ret, expected) self.assertEqual(len(calls), 1) # with args - for x in range(2): + for _ in range(2): ret = foo(1) expected = ((1, ), {}) self.assertEqual(ret, expected) self.assertEqual(len(calls), 2) # with args + kwargs - for x in range(2): + for _ in range(2): ret = foo(1, bar=2) expected = ((1, ), {'bar': 2}) self.assertEqual(ret, expected) @@ -732,7 +732,7 @@ class TestWrapNumbers(PsutilTestCase): {'disk_io': {('disk1', 0): 0, ('disk1', 1): 0, ('disk1', 2): 100}}) self.assertEqual(cache[2], {'disk_io': {'disk1': set([('disk1', 2)])}}) - def assert_(): + def check_cache_info(): cache = wrap_numbers.cache_info() self.assertEqual( cache[1], @@ -746,14 +746,14 @@ class TestWrapNumbers(PsutilTestCase): wrap_numbers(input, 'disk_io') cache = wrap_numbers.cache_info() self.assertEqual(cache[0], {'disk_io': input}) - assert_() + check_cache_info() # then it goes up input = {'disk1': nt(100, 100, 90)} wrap_numbers(input, 'disk_io') cache = wrap_numbers.cache_info() self.assertEqual(cache[0], {'disk_io': input}) - assert_() + check_cache_info() # then it wraps again input = {'disk1': nt(100, 100, 20)} @@ -837,7 +837,7 @@ class TestScripts(PsutilTestCase): return out @staticmethod - def assert_syntax(exe, args=None): + def assert_syntax(exe): exe = os.path.join(SCRIPTS_DIR, exe) if PY3: f = open(exe, 'rt', encoding='utf8') diff --git a/psutil/tests/test_osx.py b/psutil/tests/test_osx.py index af126484..dc0dd6ba 100755 --- a/psutil/tests/test_osx.py +++ b/psutil/tests/test_osx.py @@ -51,33 +51,6 @@ def vm_stat(field): return int(re.search(r'\d+', line).group(0)) * getpagesize() -# http://code.activestate.com/recipes/578019/ -def human2bytes(s): - SYMBOLS = { - 'customary': ('B', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'), - } - init = s - num = "" - while s and s[0:1].isdigit() or s[0:1] == '.': - num += s[0] - s = s[1:] - num = float(num) - letter = s.strip() - for name, sset in SYMBOLS.items(): - if letter in sset: - break - else: - if letter == 'k': - sset = SYMBOLS['customary'] - letter = letter.upper() - else: - raise ValueError("can't interpret %r" % init) - prefix = {sset[0]: 1} - for i, s in enumerate(sset[1:]): - prefix[s] = 1 << (i + 1) * 10 - return int(num * prefix[letter]) - - @unittest.skipIf(not MACOS, "MACOS only") class TestProcess(PsutilTestCase): @@ -200,16 +173,6 @@ class TestSystemAPIs(PsutilTestCase): psutil_val = psutil.swap_memory().sout self.assertAlmostEqual(psutil_val, vmstat_val, delta=TOLERANCE_SYS_MEM) - # Not very reliable. - # def test_swapmem_total(self): - # out = sh('sysctl vm.swapusage') - # out = out.replace('vm.swapusage: ', '') - # total, used, free = re.findall('\d+.\d+\w', out) - # psutil_smem = psutil.swap_memory() - # self.assertEqual(psutil_smem.total, human2bytes(total)) - # self.assertEqual(psutil_smem.used, human2bytes(used)) - # self.assertEqual(psutil_smem.free, human2bytes(free)) - # --- network def test_net_if_stats(self): diff --git a/psutil/tests/test_posix.py b/psutil/tests/test_posix.py index d8732230..0dc1dfda 100755 --- a/psutil/tests/test_posix.py +++ b/psutil/tests/test_posix.py @@ -63,6 +63,8 @@ def ps(fmt, pid=None): cmd.append('ax') if SUNOS: + # XXX: set() has not get() method so this cannot work; not sure + # what I meant in here. fmt_map = set(('command', 'comm', 'start', 'stime')) fmt = fmt_map.get(fmt, fmt) @@ -408,8 +410,7 @@ class TestSystemAPIs(PsutilTestCase): "raw devices not supported" in err or \ "permission denied" in err: continue - else: - raise + raise else: self.assertAlmostEqual(usage.total, total, delta=tolerance) self.assertAlmostEqual(usage.used, used, delta=tolerance) diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index df6a84c3..ec15ffda 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -231,7 +231,7 @@ class TestProcess(PsutilTestCase): p = psutil.Process() p.cpu_percent(interval=0.001) p.cpu_percent(interval=0.001) - for x in range(100): + for _ in range(100): percent = p.cpu_percent(interval=None) self.assertIsInstance(percent, float) self.assertGreaterEqual(percent, 0.0) @@ -611,8 +611,7 @@ class TestProcess(PsutilTestCase): def test_memory_maps(self): p = psutil.Process() maps = p.memory_maps() - paths = [x for x in maps] - self.assertEqual(len(paths), len(set(paths))) + self.assertEqual(len(maps), len(set(maps))) ext_maps = p.memory_maps(grouped=False) for nt in maps: @@ -1035,7 +1034,7 @@ class TestProcess(PsutilTestCase): def test_num_ctx_switches(self): p = psutil.Process() before = sum(p.num_ctx_switches()) - for x in range(500000): + for _ in range(500000): after = sum(p.num_ctx_switches()) if after > before: return @@ -1147,7 +1146,7 @@ class TestProcess(PsutilTestCase): def test_suspend_resume(self): p = self.spawn_psproc() p.suspend() - for x in range(100): + for _ in range(100): if p.status() == psutil.STATUS_STOPPED: break time.sleep(0.01) diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py index 1722b515..c2b1df84 100755 --- a/psutil/tests/test_system.py +++ b/psutil/tests/test_system.py @@ -123,7 +123,7 @@ class TestProcessAPIs(PsutilTestCase): self.assertFalse(hasattr(p, 'returncode')) @retry_on_failure(30) - def test(procs, callback): + def test_1(procs, callback): gone, alive = psutil.wait_procs(procs, timeout=0.03, callback=callback) self.assertEqual(len(gone), 1) @@ -131,7 +131,7 @@ class TestProcessAPIs(PsutilTestCase): return gone, alive sproc3.terminate() - gone, alive = test(procs, callback) + gone, alive = test_1(procs, callback) self.assertIn(sproc3.pid, [x.pid for x in gone]) if POSIX: self.assertEqual(gone.pop().returncode, -signal.SIGTERM) @@ -142,7 +142,7 @@ class TestProcessAPIs(PsutilTestCase): self.assertFalse(hasattr(p, 'returncode')) @retry_on_failure(30) - def test(procs, callback): + def test_2(procs, callback): gone, alive = psutil.wait_procs(procs, timeout=0.03, callback=callback) self.assertEqual(len(gone), 3) @@ -151,7 +151,7 @@ class TestProcessAPIs(PsutilTestCase): sproc1.terminate() sproc2.terminate() - gone, alive = test(procs, callback) + gone, alive = test_2(procs, callback) self.assertEqual(set(pids), set([sproc1.pid, sproc2.pid, sproc3.pid])) for p in gone: self.assertTrue(hasattr(p, 'returncode')) @@ -165,7 +165,7 @@ class TestProcessAPIs(PsutilTestCase): procs = [psutil.Process(x.pid) for x in (sproc1, sproc2, sproc3)] for p in procs: p.terminate() - gone, alive = psutil.wait_procs(procs) + psutil.wait_procs(procs) def test_pid_exists(self): sproc = self.spawn_testproc() @@ -449,7 +449,7 @@ class TestCpuAPIs(PsutilTestCase): def test_cpu_percent(self): last = psutil.cpu_percent(interval=0.001) - for x in range(100): + for _ in range(100): new = psutil.cpu_percent(interval=None) self._test_cpu_percent(new, last, new) last = new @@ -459,7 +459,7 @@ class TestCpuAPIs(PsutilTestCase): def test_per_cpu_percent(self): last = psutil.cpu_percent(interval=0.001, percpu=True) self.assertEqual(len(last), psutil.cpu_count()) - for x in range(100): + for _ in range(100): new = psutil.cpu_percent(interval=None, percpu=True) for percent in new: self._test_cpu_percent(percent, last, new) @@ -469,7 +469,7 @@ class TestCpuAPIs(PsutilTestCase): def test_cpu_times_percent(self): last = psutil.cpu_times_percent(interval=0.001) - for x in range(100): + for _ in range(100): new = psutil.cpu_times_percent(interval=None) for percent in new: self._test_cpu_percent(percent, last, new) @@ -481,7 +481,7 @@ class TestCpuAPIs(PsutilTestCase): def test_per_cpu_times_percent(self): last = psutil.cpu_times_percent(interval=0.001, percpu=True) self.assertEqual(len(last), psutil.cpu_count()) - for x in range(100): + for _ in range(100): new = psutil.cpu_times_percent(interval=None, percpu=True) for cpu in new: for percent in cpu: diff --git a/psutil/tests/test_testutils.py b/psutil/tests/test_testutils.py index e757e017..77e52b69 100755 --- a/psutil/tests/test_testutils.py +++ b/psutil/tests/test_testutils.py @@ -406,16 +406,16 @@ class TestMemLeakClass(TestMemoryLeak): self.assertEqual(len(ls), times + 1) def test_execute_w_exc(self): - def fun(): + def fun_1(): 1 / 0 - self.execute_w_exc(ZeroDivisionError, fun) + self.execute_w_exc(ZeroDivisionError, fun_1) with self.assertRaises(ZeroDivisionError): - self.execute_w_exc(OSError, fun) + self.execute_w_exc(OSError, fun_1) - def fun(): + def fun_2(): pass with self.assertRaises(AssertionError): - self.execute_w_exc(ZeroDivisionError, fun) + self.execute_w_exc(ZeroDivisionError, fun_2) class TestTestingUtils(PsutilTestCase): diff --git a/psutil/tests/test_unicode.py b/psutil/tests/test_unicode.py index 3fa3f017..43cf2b49 100755 --- a/psutil/tests/test_unicode.py +++ b/psutil/tests/test_unicode.py @@ -316,8 +316,7 @@ class TestFSAPIsWithInvalidPath(TestFSAPIs): """Test FS APIs with a funky, invalid path name.""" funky_suffix = INVALID_UNICODE_SUFFIX - @classmethod - def expect_exact_path_match(cls): + def expect_exact_path_match(self): # Invalid unicode names are supposed to work on Python 2. return True |