Skip to content

Commit

Permalink
remove psutil.test() ps-like function
Browse files Browse the repository at this point in the history
It could not be called anymore via:

$ python3 -m psutil
/usr/bin/python3: No module named psutil.__main__; 'psutil' is a package and cannot be directly executed

...plus code it's a duplicate of scripts/ps.py.
  • Loading branch information
giampaolo committed Dec 20, 2024
1 parent 508fb5d commit 318807f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 88 deletions.
78 changes: 0 additions & 78 deletions psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2395,82 +2395,4 @@ def _set_debug(value):
_psplatform.cext.set_debug(bool(value))


def test(): # pragma: no cover
import shutil

from ._common import bytes2human

today_day = datetime.date.today()
# fmt: off
templ = "%-10s %5s %5s %7s %7s %5s %6s %6s %6s %s"
attrs = ['pid', 'memory_percent', 'name', 'cmdline', 'cpu_times',
'create_time', 'memory_info', 'status', 'nice', 'username']
print(templ % ("USER", "PID", "%MEM", "VSZ", "RSS", "NICE", # NOQA
"STATUS", "START", "TIME", "CMDLINE"))
# fmt: on
for p in process_iter(attrs, ad_value=None):
if p.info['create_time']:
ctime = datetime.datetime.fromtimestamp(p.info['create_time'])
if ctime.date() == today_day:
ctime = ctime.strftime("%H:%M")
else:
ctime = ctime.strftime("%b%d")
else:
ctime = ''
if p.info['cpu_times']:
cputime = time.strftime(
"%M:%S", time.localtime(sum(p.info['cpu_times']))
)
else:
cputime = ''

user = p.info['username'] or ''
if not user and POSIX:
try:
user = p.uids()[0]
except Error:
pass
if user and WINDOWS and '\\' in user:
user = user.split('\\')[1]
user = user[:9]
vms = (
bytes2human(p.info['memory_info'].vms)
if p.info['memory_info'] is not None
else ''
)
rss = (
bytes2human(p.info['memory_info'].rss)
if p.info['memory_info'] is not None
else ''
)
memp = (
round(p.info['memory_percent'], 1)
if p.info['memory_percent'] is not None
else ''
)
nice = int(p.info['nice']) if p.info['nice'] else ''
if p.info['cmdline']:
cmdline = ' '.join(p.info['cmdline'])
else:
cmdline = p.info['name']
status = p.info['status'][:5] if p.info['status'] else ''

line = templ % (
user[:10],
p.info['pid'],
memp,
vms,
rss,
nice,
status,
ctime,
cputime,
cmdline,
)
print(line[: shutil.get_terminal_size()[0]]) # NOQA


del memoize_when_activated

if __name__ == "__main__":
test()
10 changes: 0 additions & 10 deletions psutil/tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from psutil import WINDOWS
from psutil.tests import ASCII_FS
from psutil.tests import CI_TESTING
from psutil.tests import DEVNULL
from psutil.tests import GITHUB_ACTIONS
from psutil.tests import GLOBAL_TIMEOUT
from psutil.tests import HAS_BATTERY
Expand Down Expand Up @@ -261,15 +260,6 @@ def test_users(self):
else:
psutil.Process(user.pid)

def test_test(self):
# test for psutil.test() function
stdout = sys.stdout
sys.stdout = DEVNULL
try:
psutil.test()
finally:
sys.stdout = stdout

def test_os_constants(self):
names = [
"POSIX",
Expand Down

0 comments on commit 318807f

Please sign in to comment.