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)
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([])
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"), )
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([])
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([])
def test_validate_parse_function_value(parse_function): with pytest.raises(ValueError): section_plugins._validate_parse_function(parse_function)
def test_validate_parse_function_value(parse_function): with pytest.raises(ValueError): section_plugins._validate_parse_function( parse_function, expected_annotation=(str, "str"), # ignored )
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 )