def test_node_returns_details_only():
    node_results = _check_function_node((Result(state=state.OK, details="This is detailed"),))
    result = aggregate_node_details("test_node", node_results)
    assert result is not None
    assert result.state is state.OK
    assert result.summary == ""
    assert result.details == "[test_node]: This is detailed"
def test_node_returns_ok_and_warn():
    node_results = _check_function_node((_OK_RESULT, _WARN_RESULT))
    state, text = aggregate_node_details("test_node", node_results)
    assert state is State.WARN
    assert text == (
        "[test_node]: I am fine\n"  #
        "[test_node]: Watch out(!)")
def test_node_returns_metric():
    node_results = _check_function_node((_OK_RESULT, Metric("panic", 42)))
    result = aggregate_node_details("test_node", node_results)
    assert result is not None
    assert result.state is state.OK
    assert result.summary == ""
    assert result.details == "[test_node]: I am fine"
def test_node_raises():
    def _check_node_raises():
        raise IgnoreResultsError()
        yield  # pylint: disable=unreachable

    assert aggregate_node_details("test_node",
                                  _check_node_raises()) == (State.OK, None)
def test_node_returns_ok_and_warn():
    node_results = _check_function_node((_OK_RESULT, _WARN_RESULT))
    result = aggregate_node_details("test_node", node_results)
    assert result is not None
    assert result.state is state.WARN
    assert result.summary == ""
    assert result.details == (
        "[test_node]: I am fine\n"  #
        "[test_node]: Watch out(!)")
def test_node_mutliline():
    node_results = (Result(state=state.WARN, details="These\nare\nfour\nlines"),)
    result = aggregate_node_details("test_node", _check_function_node(node_results))
    assert result is not None
    assert result.state is state.WARN
    assert result.summary == ""
    assert result.details == ("[test_node]: These\n"
                              "[test_node]: are\n"
                              "[test_node]: four\n"
                              "[test_node]: lines(!)")
def test_node_mutliline():
    node_results = (Result(state=State.WARN,
                           notice="These\nare\nfour\nlines"), )
    state, text = aggregate_node_details("test_node",
                                         _check_function_node(node_results))
    assert state is State.WARN
    assert text == ("[test_node]: These\n"
                    "[test_node]: are\n"
                    "[test_node]: four\n"
                    "[test_node]: lines(!)")
def test_node_ignore_results():
    node_results = _check_function_node((_OK_RESULT, IgnoreResults()))
    assert aggregate_node_details("test_node", node_results) is None
def test_node_returns_nothing():
    assert aggregate_node_details("test_node", _check_function_node(())) is None
    assert aggregate_node_details("test_node", ()) is None
def test_node_returns_details_only():
    node_results = _check_function_node((Result(state=State.OK,
                                                notice="This is detailed"), ))
    state, text = aggregate_node_details("test_node", node_results)
    assert state is State.OK
    assert text == "[test_node]: This is detailed"
def test_node_returns_metric():
    node_results = _check_function_node((_OK_RESULT, Metric("panic", 42)))
    state, text = aggregate_node_details("test_node", node_results)
    assert state is State.OK
    assert text == "[test_node]: I am fine"
def test_node_returns_nothing():
    assert aggregate_node_details("test_node", _check_function_node(
        ())) == (State.OK, None)
    assert aggregate_node_details("test_node", ()) == (State.OK, None)