Exemple #1
0
def test_run(monkeypatch):
    m_args = []
    m_input = ""
    m_timeout = 0

    def mock_check_output(args, stderr, universal_newlines, input, timeout):
        nonlocal m_args
        nonlocal m_input
        nonlocal m_timeout
        m_args = args
        m_input = input
        m_timeout = timeout
        return ""

    monkeypatch.setattr(subprocess, "check_output", mock_check_output)
    m = Matcher(rule_1)

    m.run("org.reactobus", "uuid", "0", "lavauser", {})
    assert m_args == [m.binary, "topic", "org.reactobus", "username", "lavauser"]
    assert m_input == ""
    assert m_timeout == 1

    m.run("org.reactobus.test", "uuid", "0", "kernel", {})
    assert m_args == [m.binary, "topic", "org.reactobus.test", "username", "kernel"]
    assert m_input == ""
    assert m_timeout == 1

    m = Matcher(rule_7)
    m.run("org.reactobus.test", "uuid", "0", "lavaserver", {"submitter": "myself"})
    assert m_args == [m.binary, "stdin", "myself"]
    assert m_input == "hello\norg.reactobus.test\nmyself"
    assert m_timeout == 4

    m_args = None
    m.run("org.reactobus.test", "uuid", "0", "lavaserver", {"something": "myself"})
    assert m_args is None