def test_psalxwww_and_psauxww_and_psaux_and_psef_and_psauxcww_and_ps_eo_cmd_parsers( ): ps_alxwww = PsAlxwww(context_wrap(PS_ALXWWW_LINES)) ps_auxww = PsAuxww(context_wrap(PS_AUXWW_LINES)) ps_aux = PsAux(context_wrap(PS_AUX_LINES)) ps_ef = PsEf(context_wrap(PS_EF_LINES)) ps_auxcww = PsAuxcww(context_wrap(PS_AUXCWW_LINES)) ps_eo_cmd = PsEoCmd(context_wrap(PS_EO_CMD_LINES, strip=False)) ps_combiner = Ps(ps_alxwww, ps_auxww, ps_aux, ps_ef, ps_auxcww, None, ps_eo_cmd) len(ps_combiner.processes) == 9 ps = ps_combiner[1] assert ps['PID'] == 1 assert ps['USER'] == 'root' assert ps['UID'] == 0 assert ps['PPID'] == 0 assert ps['%CPU'] == 0.1 assert ps['%MEM'] == 0.0 assert ps['VSZ'] == 195712.0 assert ps['RSS'] == 7756.0 assert ps['STAT'] == 'Ss' assert ps['TTY'] == '?' assert ps['START'] == '2019' assert ps['TIME'] == '478:05' assert ps[ 'COMMAND'] == '/usr/lib/systemd/systemd --switched-root --system --deserialize 21' assert ps['COMMAND_NAME'] == 'systemd' assert ps['F'] == '4' assert ps['PRI'] == 20 assert ps['NI'] == '0' assert ps['WCHAN'] == 'ep_pol' assert ps_combiner[13]['COMMAND'] == '/usr/bin/python3.6'
def test_psalxwww_and_psauxww_and_psaux_parsers(): ps_alxwww = PsAlxwww(context_wrap(PS_ALXWWW_LINES)) ps_auxww = PsAuxww(context_wrap(PS_AUXWW_LINES)) ps_aux = PsAux(context_wrap(PS_AUX_LINES)) ps = Ps(ps_alxwww, ps_auxww, ps_aux, None, None, None, None) len(ps.processes) == 5 ps = ps[1] assert ps['PID'] == 1 assert ps['USER'] == 'root' assert ps['UID'] == 0 assert ps['PPID'] == 0 assert ps['%CPU'] == 0.1 assert ps['%MEM'] == 0.0 assert ps['VSZ'] == 195712.0 assert ps['RSS'] == 7756.0 assert ps['STAT'] == 'Ss' assert ps['TTY'] == '?' assert ps['START'] == '2019' assert ps['TIME'] == '478:05' assert ps[ 'COMMAND'] == '/usr/lib/systemd/systemd --switched-root --system --deserialize 21' assert ps['COMMAND_NAME'] == 'systemd' assert ps['F'] == '4' assert ps['PRI'] == 20 assert ps['NI'] == '0' assert ps['WCHAN'] == 'ep_pol'
def test_docs(): ps_alxwww = PsAlxwww(context_wrap(PS_ALXWWW_LINES)) ps_auxww = PsAuxww(context_wrap(PS_AUXWW_LINES)) ps_aux = PsAux(context_wrap(PS_AUX_LINES)) ps_ef = PsEf(context_wrap(PS_EF_LINES)) ps_auxcww = PsAuxcww(context_wrap(PS_AUXCWW_LINES)) ps_eo = PsEo(context_wrap(PS_EO_LINES, strip=False)) ps_combiner = Ps(ps_alxwww, ps_auxww, ps_aux, ps_ef, ps_auxcww, ps_eo) env = {'ps_combiner': ps_combiner} failed, total = doctest.testmod(ps, globs=env) assert failed == 0
def test_type_conversion(): ps_alxwww = PsAlxwww(context_wrap(PS_ALXWWW_LINES)) ps_ef = PsEf(context_wrap(PS_EF_LINES)) ps_auxcww = PsAuxcww(context_wrap(PS_AUXCWW_LINES)) ps = Ps(ps_alxwww, None, None, ps_ef, ps_auxcww, None, None) assert all(isinstance(p['PID'], int) for p in ps.processes) assert all(p['UID'] is None or isinstance(p['UID'], int) for p in ps.processes) assert all(p['PID'] is None or isinstance(p['PID'], int) for p in ps.processes) assert all(p['%CPU'] is None or isinstance(p['%CPU'], float) for p in ps.processes) assert all(p['%MEM'] is None or isinstance(p['%MEM'], float) for p in ps.processes) assert all(p['VSZ'] is None or isinstance(p['VSZ'], float) for p in ps.processes) assert all(p['RSS'] is None or isinstance(p['RSS'], float) for p in ps.processes) assert all(p['PRI'] is None or isinstance(p['PRI'], int) for p in ps.processes)
def test_search_ps_alxwww_w_grep(): p = PsAlxwww(context_wrap(PS_ALXWWW_W_GREP)) ps = Ps(p, None, None, None, None, None, None) assert len(ps.search(COMMAND_NAME__contains='dbus')) == 1