コード例 #1
0
def test_create_snmp_parse_function():
    compliant_parse_function = section_plugins_legacy._create_snmp_parse_function(
        original_parse_function=old_school_parse_function,
        recover_layout_function=lambda x: x,
        handle_empty_info=False,
    )

    with pytest.raises(ValueError):
        # raises b/c of wrong signature!
        section_plugins._validate_parse_function(
            old_school_parse_function,
            expected_annotation=(str, "str"),  # irrelevant in test
        )

    section_plugins._validate_parse_function(
        compliant_parse_function,
        expected_annotation=(
            str,
            "str"),  # irrel. in test, SNMP parse function is not annotated
    )

    arbitrary_non_empty_input = [[['moo']]]
    assert compliant_parse_function([[]]) is None
    assert compliant_parse_function(
        arbitrary_non_empty_input  # type: ignore[arg-type]
    ) == old_school_parse_function(arbitrary_non_empty_input)
コード例 #2
0
def test_create_parse_function(creator_func):
    compliant_parse_function = creator_func(old_school_parse_function)

    with pytest.raises(ValueError):
        # raises b/c of wrong signature!
        section_plugins._validate_parse_function(old_school_parse_function)

    section_plugins._validate_parse_function(compliant_parse_function)

    assert old_school_parse_function([]) == compliant_parse_function([])
コード例 #3
0
ファイル: test_section_plugins.py プロジェクト: jsjhb/checkmk
def test_validate_parse_function_annotation_string_table():
    def _parse_function(string_table: SNMPStringTable):
        return string_table

    with pytest.raises(TypeError):
        section_plugins._validate_parse_function(
            _parse_function,
            expected_annotation=(SNMPStringByteTable, "SNMPStringByteTable"),
        )

    section_plugins._validate_parse_function(
        _parse_function,
        expected_annotation=(SNMPStringTable, "SNMPStringTable"),
    )
コード例 #4
0
def test_create_agent_parse_function():
    compliant_parse_function = section_plugins_legacy._create_agent_parse_function(
        old_school_parse_function)

    with pytest.raises(ValueError):
        # raises b/c of wrong signature!
        section_plugins._validate_parse_function(
            old_school_parse_function,
            expected_annotation=(str, "str"),  # irrelevant in test
        )

    section_plugins._validate_parse_function(
        compliant_parse_function,
        expected_annotation=(StringTable, "StringTable"),
    )

    assert old_school_parse_function([]) == compliant_parse_function([])
コード例 #5
0
def test_create_snmp_parse_function():
    compliant_parse_function = section_plugins_legacy._create_snmp_parse_function(
        old_school_parse_function, lambda x: x)

    with pytest.raises(ValueError):
        # raises b/c of wrong signature!
        section_plugins._validate_parse_function(
            old_school_parse_function,
            expected_annotation=(str, "str"),  # irrelevant in test
        )

    section_plugins._validate_parse_function(
        compliant_parse_function,
        expected_annotation=(str, "str"),  # irrel. in test, SNMP parse function is not annotated
    )

    assert old_school_parse_function([]) == compliant_parse_function([])
コード例 #6
0
def test_validate_parse_function_value(parse_function):
    with pytest.raises(ValueError):
        section_plugins._validate_parse_function(parse_function)
コード例 #7
0
ファイル: test_section_plugins.py プロジェクト: jsjhb/checkmk
def test_validate_parse_function_value(parse_function):
    with pytest.raises(ValueError):
        section_plugins._validate_parse_function(
            parse_function,
            expected_annotation=(str, "str"),  # ignored
        )
コード例 #8
0
ファイル: test_section_plugins.py プロジェクト: jsjhb/checkmk
def test_validate_parse_function_type(parse_function):
    with pytest.raises(TypeError):
        section_plugins._validate_parse_function(
            parse_function,
            expected_annotation=(str, "str"),  # irrelevant for test
        )