How to use the flynt.lexer.split.get_fstringify_chunks 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_lexer.py View on Github external
def test_two_strings():
    s = (
        'a = "my string {}, but also {} and {}".format(var, f, cada_bra)\n'
        + 'b = "my string {}, but also {} and {}".format(var, what, cada_bra)'
    )

    chunks_gen = split.get_fstringify_chunks(s)
    assert len(list(chunks_gen)) == 2

    generator = split.get_fstringify_chunks(s)
    lines = s.split("\n")

    chunk = next(generator)

    assert chunk.start_line == 0
    assert lines[0][: chunk.end_idx] == lines[0]

    chunk = next(generator)

    assert chunk.start_line == 1
    assert lines[1][: chunk.end_idx] == lines[1]
github ikamensh / flynt / test / test_lexer.py View on Github external
def test_empty_line():
    code_empty_line = """
    def write_row(self, xf, row, row_idx):
    
        attrs = {'r': '{}'.format(row_idx)}""".strip()

    generator = split.get_fstringify_chunks(code_empty_line)
    lines = code_empty_line.split("\n")

    chunk = next(generator)

    assert chunk.start_line == 2
    assert lines[2][chunk.start_idx : chunk.end_idx] == "'{}'.format(row_idx)"
github ikamensh / flynt / test / test_lexer.py View on Github external
def test_two_strings():
    s = (
        'a = "my string {}, but also {} and {}".format(var, f, cada_bra)\n'
        + 'b = "my string {}, but also {} and {}".format(var, what, cada_bra)'
    )

    chunks_gen = split.get_fstringify_chunks(s)
    assert len(list(chunks_gen)) == 2

    generator = split.get_fstringify_chunks(s)
    lines = s.split("\n")

    chunk = next(generator)

    assert chunk.start_line == 0
    assert lines[0][: chunk.end_idx] == lines[0]

    chunk = next(generator)

    assert chunk.start_line == 1
    assert lines[1][: chunk.end_idx] == lines[1]
github ikamensh / flynt / test / test_lexer.py View on Github external
def test_line_continuation():
    generator = split.get_fstringify_chunks(line_continuation)
    assert len(list(generator)) == 1
github ikamensh / flynt / test / test_lexer.py View on Github external
def test_tuple_list():
    generator = split.get_fstringify_chunks(tuple_in_list)
    assert len(list(generator)) == 1
github ikamensh / flynt / test / test_lexer.py View on Github external
def test_tuple_percent():
    code = """print("%s %s " % (var+var, abc))"""
    generator = split.get_fstringify_chunks(tuple_in_list)
    assert len(list(generator)) == 1
github ikamensh / flynt / test / test_lexer.py View on Github external
def test_yields_parsable():
    code_in = """attrs = {'r': '{}'.format(row_idx)}"""
    generator = split.get_fstringify_chunks(code_in)
    chunk = next(generator)

    assert chunk.is_parseable
    assert code_in[chunk.start_idx : chunk.end_idx] == "'{}'.format(row_idx)"
github ikamensh / flynt / test / test_lexer.py View on Github external
def test_one_string():
    s = """"my string {}, but also {} and {}".format(var, f, cada_bra)"""
    chunks_gen = split.get_fstringify_chunks(s)
    assert len(list(chunks_gen)) == 1

    generator = split.get_fstringify_chunks(s)
    chunk = next(generator)

    assert chunk.start_line == 0
    assert s[: chunk.end_idx] == s
github ikamensh / flynt / test / test_lexer.py View on Github external
def test_str_newline():
    s_in = """a = '%s\\n' % var"""
    generator = split.get_fstringify_chunks(s_in)
    assert len(list(generator)) == 1