def main(): t0 = time.time() for iteration in range(LAPS): px_process.get_all() t1 = time.time() dt_seconds = t1 - t0 print("Getting all processes takes {:.0f}ms".format(1000 * dt_seconds / LAPS))
def test_get_screen_lines(): loadbar = px_load_bar.PxLoadBar(1, 1) baseline = px_process.get_all() SCREEN_ROWS = 10 SCREEN_COLUMNS = 70 lines = px_top.get_screen_lines(loadbar, baseline, SCREEN_ROWS, SCREEN_COLUMNS) # Top row should contain ANSI escape codes CSI = b"\x1b[" assert b'CSI' in lines[0].replace(CSI, b'CSI') assert len(lines) == SCREEN_ROWS # Row three is the heading line, it should span the full width of the screen # and be in inverse video. assert len(lines[2]) == len(px_terminal.inverse_video('x' * SCREEN_COLUMNS)) # The actual process information starts at line four for line in lines[3:]: # No line can be longer than the screen width; long lines should have # been cut assert len(line) <= SCREEN_COLUMNS
def _test_get_all(): all = px_process.get_all() assert len(all) >= 4 # Expect at least kernel, init, bash and python for process in all: assert process is not None pids = list(map(lambda p: p.pid, all)) # Finding ourselves is just confusing... assert os.getpid() not in pids # ... but all other processes should be there assert os.getppid() in pids # PID 1 is launchd on OS X, init on Linux. # # If there's a system where PID 1 doesn't exist this test needs to be modded # and that system documented here. assert 1 in pids # Assert that all contains no duplicate PIDs seen_pids = set() # type: MutableSet[int] for process in all: pid = process.pid assert pid not in seen_pids seen_pids.add(pid) # Assert that there are processes with the current user name current_users_processes = ( filter(lambda process: process.username == getpass.getuser(), all)) assert current_users_processes _validate_references(all) now = testutils.now() for process in all: # Scores should be computed via multiplications and divisions of # positive numbers, if this value is negative something is wrong. assert process.score >= 0 # Processes created in the future = fishy assert process.age_seconds >= 0 assert process.start_time < now for process in all: assert isinstance(process.cmdline, six.text_type) assert isinstance(process.username, six.text_type)
def test_redraw(): # Just make sure it doesn't crash loadbar = px_load_bar.PxLoadBar(1, 1) baseline = px_process.get_all() px_top.redraw(loadbar, baseline, 100, 10, clear=False)
def test_get_toplist(): # Just make sure this call doesn't crash px_top.get_toplist(px_process.get_all())
def test_print_starttime(): # Just make sure it doesn't crash all = px_process.get_all() process0 = list(filter(lambda p: p.pid == 0, all))[0] px_processinfo.print_start_time(process0)