How to use the flynt.process.fstringify_code_by_line function in flynt

To help you get started, we’ve selected a few flynt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ikamensh / flynt / test / test_process.py View on Github external
def test_indented():
    s_expected = '''    a = f"my string {var}"'''
    s_out, count = process.fstringify_code_by_line(indented)

    assert count == 1
    assert s_out.split("\n")[2] == s_expected
github ikamensh / flynt / test / test_process.py View on Github external
def test_empty_line():
    s_expected = """    attrs = {'r': f'{row_idx}'}"""
    s_out, count = process.fstringify_code_by_line(code_empty_line)

    assert count == 1
    assert s_out.split("\n")[2] == s_expected
github ikamensh / flynt / test / test_process.py View on Github external
def test_chain_fmt_3():
    s_in = """a = "Hello {}".format(d["a{}".format( d["a{}".format(key) ]) ] )"""
    s_out, count = process.fstringify_code_by_line(s_in)

    assert count == 0
github ikamensh / flynt / test / test_process.py View on Github external
def test_invalid_conversion():
    s_in = """a = 'my string {}, but also {!b} and {!a}'.format(var, f, cada_bra)"""
    s_expected = s_in

    s_out, count = process.fstringify_code_by_line(s_in)
    assert s_out == s_expected
github ikamensh / flynt / test / test_process.py View on Github external
def test_percent_tuple():
    s_in = """print("%s %s " % (var+var, abc))"""
    s_expected = """print(f"{var + var} {abc} ")"""

    s_out, count = process.fstringify_code_by_line(s_in)
    assert s_out == s_expected
github ikamensh / flynt / test / test_process.py View on Github external
def test_legacy_fmtspec(aggressive):
    s_in = """d = '%i' % var"""
    s_expected = """d = f'{int(var)}'"""

    out, count = process.fstringify_code_by_line(s_in)
    assert out == s_expected
github ikamensh / flynt / test / test_process.py View on Github external
def test_noqa_other():
    s_in = """a = '%s\\n' % var  # noqa: W731, flynt"""
    s_expected = """a = '%s\\n' % var  # noqa: W731, flynt"""

    s_out, count = process.fstringify_code_by_line(s_in)
    assert s_out == s_expected
github ikamensh / flynt / test / integration / test_files.py View on Github external
def try_on_file(filename: str, multiline):
    """ Given a file name (something.py) find this file in test/integration/samples_in,
    run flint_str on its content, write result
    to test/integration/actual_out/something.py,
    and compare the result with test/integration/expected_out/something.py"""
    txt_in = read_in(filename)
    out, edits = fstringify_code_by_line(txt_in, multiline=multiline, len_limit=None)

    write_output_file(filename, out)
    return out, read_expected(filename)
github ikamensh / flynt / test / test_process.py View on Github external
def test_percent_newline():
    s_in = """a = '%s\\n' % var"""
    s_expected = """a = f'{var}\\n'"""

    s_out, count = process.fstringify_code_by_line(s_in)
    print(s_out)
    print(s_expected)
    assert s_out == s_expected
github ikamensh / flynt / test / test_process.py View on Github external
def test_decimal_precision():
    s_in = """e = '%.03f' % var"""
    s_expected = """e = f'{var:.03f}'"""

    out, count = process.fstringify_code_by_line(s_in)
    assert out == s_expected