コード例 #1
0
def test_single_match(single_host):
    results = single_host.run(
        task=wrap_task(get_regexp),
        tests=[t_regexp(regexp=r"Ethernet1 is up", assertion="is_not_none")],
    )
    assert results["test"][0].tests[0].passed

    for result in results.values():
        assert len(result[0].tests) == 1
コード例 #2
0
def t_regexp_not_failed(single_host):
    results = single_host.run(
        task=wrap_task(echo_data),
        z="zzzsuperpassword!dkfj",
        tests=[t_regexp(result_attr="result", regexp=r".*uperpas*word")],
    )

    for host, result in results.items():
        assert hasattr(result[0], "tests")
        assert not result[0].failed
        assert len(result[0].tests) > 0
        assert str(result[0]) != ""
コード例 #3
0
def t_regexp_failed(single_host, fail):
    results = single_host.run(
        task=wrap_task(echo_data),
        z="zzzsuperpassword!dkfj",
        tests=[
            t_regexp(result_attr="result", regexp=r".*upexyzrpas*word", fail_task=fail)
        ],
    )

    for host, result in results.items():
        assert hasattr(result[0], "tests")
        assert result[0].failed == fail
        assert len(result[0].tests) > 0
        assert str(result[0].tests[0].exception).find("no match found for regex") != -1
コード例 #4
0
def test_too_many_match_groups(single_host):
    results = single_host.run(
        task=wrap_task(get_regexp),
        tests=[
            t_regexp(
                regexp=r"(.*?) is (.*)",
                assertion="is_equal_to",
                one_of=True,
                value="Ethernet1",
            )
        ],
    )
    assert not results["test"][0].tests[0].passed

    for result in results.values():
        assert len(result[0].tests) == 1
        assert len(result[0].tests[0].matches) == 0