def test_invalid_bracket_strings(): for string, brackets in [("]foo]", "foo"), ("something ]f] else", "f")]: with pytest.raises(ValueError): String(string, brackets) for nodes, brackets in [ ([String("hello"), String("world ]foo]")], "foo"), ([String("something"), FComponent([String("world")]), String("]f]")], "f"), ([String("something"), FComponent([Integer(1), String("]f]")])], "f"), ]: with pytest.raises(ValueError): FString(nodes, brackets=brackets)
def t_fstring(state, p): s = p[0].value assert s.startswith('f') or s.startswith('rf') assert isinstance(s, str) s = s.replace('f', '', 1) # Replace the single double quotes with triple double quotes to allow # embedded newlines. try: s = eval(s.replace('"', '"""', 1)[:-1] + '"""') except SyntaxError: raise LexException.from_lexer( f"Can't convert {p[0].value} to a hy.models.FString", state, p[0], ) # internal parser values = _format_string(state, p, s) return FString(values)