Skip to content

Commit

Permalink
refact some asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jan 5, 2024
1 parent ffefb82 commit a26f0c1
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
6 changes: 1 addition & 5 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -2031,11 +2031,7 @@ def memory_full_info(self):
if HAS_PROC_SMAPS_ROLLUP: # faster
try:
uss, pss, swap = self._parse_smaps_rollup()
except (ProcessLookupError, FileNotFoundError) as err:
debug(
"ignore %r for pid %s and retry using /proc/pid/smaps"
% (err, self.pid)
)
except (ProcessLookupError, FileNotFoundError):
uss, pss, swap = self._parse_smaps()
else:
uss, pss, swap = self._parse_smaps()
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def check_conn(proc, conn, family, type, laddr, raddr, status, kinds):
for kind in all_kinds:
cons = proc.connections(kind=kind)
if kind in kinds:
assert cons
self.assertNotEqual(cons, [])
else:
self.assertEqual(cons, [])
# compare against system-wide connections
Expand Down
4 changes: 2 additions & 2 deletions psutil/tests/test_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def username(self, ret, info):

def status(self, ret, info):
self.assertIsInstance(ret, str)
assert ret
assert ret, ret
self.assertNotEqual(ret, '?') # XXX
self.assertIn(ret, VALID_PROC_STATUSES)

Expand Down Expand Up @@ -706,7 +706,7 @@ def is_running(self, ret, info):

def cpu_affinity(self, ret, info):
self.assertIsInstance(ret, list)
assert ret != [], ret
self.assertNotEqual(ret, [])
cpus = list(range(psutil.cpu_count()))
for n in ret:
self.assertIsInstance(n, int)
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/test_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def path_exists_mock(path):
with mock.patch("os.path.exists", side_effect=path_exists_mock):
reload_module(psutil._pslinux)
ret = psutil.cpu_freq()
assert ret
assert ret, ret
self.assertEqual(ret.max, 0.0)
self.assertEqual(ret.min, 0.0)
for freq in psutil.cpu_freq(percpu=True):
Expand Down

0 comments on commit a26f0c1

Please sign in to comment.