def test_input_string_not_a_string_throw(): with pytest.raises(TypeError) as err_info: context = Context({'key1': 'value1'}) input_string = 77 context.get_formatted_string(input_string) assert repr(err_info.value) == ( "TypeError(\"can only format on strings. 77 is a <class 'int'> " "instead.\",)")
def test_input_string_tag_not_in_context_should_throw(): with pytest.raises(KeyNotInContextError) as err_info: context = Context({'key1': 'value1'}) input_string = '{key1} this is {key2} string' context.get_formatted_string(input_string) assert repr(err_info.value) == ( "KeyNotInContextError(\"Unable to format '{key1} this is " "{key2} string' with {key2}, because context['key2'] doesn't " "exist\",)")
def test_input_string_interpolate_sic(): context = Context({'key1': 'down', 'key2': 'valleys', 'key3': 'value3'}) input_string = '[sic]"Piping {key1} the {key2} wild"' output = context.get_formatted_string(input_string) assert output == "Piping {key1} the {key2} wild", ( "string interpolation incorrect")
def test_input_string_interpolate_works(): context = Context({'key1': 'down', 'key2': 'valleys', 'key3': 'value3'}) input_string = 'Piping {key1} the {key2} wild' output = context.get_formatted_string(input_string) assert output == 'Piping down the valleys wild', ( "string interpolation incorrect")