def test_process_matches(ps_line, ps_pattern, user_pattern, result): psi = ps.ps_info(ps_line[0]) # type: ignore[call-arg] matches_attr = ps.process_attributes_match(psi, user_pattern, (None, False)) matches_proc = ps.process_matches(ps_line[1:], ps_pattern) assert (matches_attr and matches_proc) == result
def test_parse_ps(capture, result): cpu_core, lines = ps_section.parse_ps(capture) assert cpu_core == result[0] # cpu_cores for (ps_info_item, cmd_line), ref in itertools.zip_longest(lines, result[1]): assert ps_info_item == ps.ps_info(*ref[0]) assert cmd_line == ref[1:]
def test_host_labels_ps_match(): section = ( 1, [ ( ps.ps_info("(root,4056,1512,0.0/52-04:56:05,5689)".split() ), # type: ignore[call-arg] ["/usr/lib/ssh/sshd"], ), ]) params = [ { "default_params": {}, "descr": "SSH", "match": "~.*ssh?", "label": { 'marco': 'polo' }, }, {}, ] assert list(ps.host_labels_ps(params, section)) == [ # type: ignore[arg-type] HostLabel('marco', 'polo') ]
def test_host_labels_ps_no_match_pattern(): section = ( 1, [ ( ps.ps_info("(root,4056,1512,0.0/52-04:56:05,5689)".split() ), # type: ignore[call-arg] ["/usr/lib/ssh/sshd"], ), ]) params = [ Parameters({ "default_params": {}, "descr": "SSH", "match": "~wat?", "label": DiscoveredHostLabels(HostLabel(u'marco', u'polo')), }), Parameters({}), ] assert list(ps.host_labels_ps(params, section)) == []
def test_host_labels_ps_no_match_attr(): section = ( 1, [ ( ps.ps_info("(root,4056,1512,0.0/52-04:56:05,5689)".split() ), # type: ignore[call-arg] ["/usr/lib/ssh/sshd"], ), ]) params = [ Parameters({ "default_params": {}, "descr": "SSH", "match": "~.*ssh?", "user": "******", "label": { 'marco': 'polo' }, }), Parameters({}), ] assert list(ps.host_labels_ps(params, section)) == []