Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_existing_fstr_expr():
txt = """f'blah{thing}' + otherThing + f'blah{thing + 1}'"""
expected = '''f"blah{thing}{otherThing}blah{thing + 1}"'''
new, changed = transform_concat(txt)
assert changed
assert new == expected
def test_transform_attribute():
txt = """'blah' + blah.blah"""
expected = '''f"blah{blah.blah}"'''
new, changed = transform_concat(txt)
assert changed
assert new == expected
def test_transform():
txt = """a + 'Hello' + b + 'World'"""
expected = '''f"{a}Hello{b}World"'''
new, changed = transform_concat(txt)
assert changed
assert new == expected
def test_string_in_string_x3():
txt = """'blah' + blah.blah('more' + vars.foo('other' + b))"""
new, changed = transform_concat(txt)
assert changed
assert "'blah' +" in new
def test_string_in_string():
txt = """'blah' + blah.blah('more' + vars)"""
expected = '''f"blah{blah.blah(f'more{vars}')}"'''
new, changed = transform_concat(txt)
assert changed
assert new == expected
def test_transform_complex():
txt = """'blah' + lst[123].process(x, y, z) + 'Yeah'"""
expected = '''f"blah{lst[123].process(x, y, z)}Yeah"'''
new, changed = transform_concat(txt)
assert changed
assert new == expected
def test_concats_fstring():
txt = """print(f'blah{thing}' + 'blah' + otherThing + f"is {x:d}")"""
expected = """print(f'blah{thing}blah{otherThing}is {x:d}')"""
new, changed = transform_concat(txt)
assert changed
assert new == expected
def test_existing_fstr():
txt = """f'blah{thing}' + otherThing + 'blah'"""
expected = '''f"blah{thing}{otherThing}blah"'''
new, changed = transform_concat(txt)
assert changed
assert new == expected
def test_transform_nonatomic():
txt = """'blah' + (thing - 1)"""
expected = '''f"blah{thing - 1}"'''
new, changed = transform_concat(txt)
assert changed
assert new == expected
def test_embedded_fstr():
txt = """print(f"{f'blah{var}' + abc}blah")"""
expected = """print(f'blah{var}{abc}blah')"""
new, changed = transform_concat(txt)
assert changed
assert new == expected