How to use the flynt.transform.transform.transform_chunk 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_transform.py View on Github external
def test_fmt_spec():
    code = """"my string {:.2f}".format(var)"""
    expected = '''f"""my string {var:.2f}"""'''

    new, changed = transform_chunk(code)

    assert changed
    assert new == expected
github ikamensh / flynt / test / test_transform.py View on Github external
def test_expr_no_paren():
    code = """"my string {:.2f}".format(var+1)"""
    expected = '''f"""my string {var + 1:.2f}"""'''

    new, changed = transform_chunk(code)

    assert changed
    assert new == expected
github ikamensh / flynt / test / test_transform.py View on Github external
def test_fix_fstrings(s, expected):
    new, changed = transform_chunk(s)
    assert changed
    assert new == expected
github ikamensh / flynt / test / test_transform.py View on Github external
def test_fix_fstrings_noop(s):
    new, changed = transform_chunk(s)
    assert new == s
    assert not changed
github ikamensh / flynt / test / test_transform.py View on Github external
def test_digit_grouping():
    code = """"Failed after {:,}".format(x)"""
    expected = '''f"""Failed after {x:,}"""'''

    new, changed = transform_chunk(code)

    assert changed
    assert new == expected
github ikamensh / flynt / test / test_transform.py View on Github external
def test_newline():
    code = r""""echo '{}'\n".format(self.FLUSH_CMD)"""
    expected = '''f"""echo '{self.FLUSH_CMD}'\\n"""'''

    new, changed = transform_chunk(code)

    assert changed
    assert new == expected
github ikamensh / flynt / test / test_transform.py View on Github external
def test_mixed_numbered():
    code = (
        """"Flask Documentation ({1} {0:.2f} {name})".format(version,sprt,name=NAME)"""
    )
    expected = '''f"""Flask Documentation ({sprt} {version:.2f} {NAME})"""'''

    new, changed = transform_chunk(code)

    assert changed
    assert new == expected
github ikamensh / flynt / test / test_transform.py View on Github external
def test_digit_grouping_2():
    code = """
    "Search: finished in {0:,} ms.".format(vm.search_time_elapsed_ms)
    """.strip()
    expected = '''
    f"""Search: finished in {vm.search_time_elapsed_ms:,} ms."""
    '''.strip()

    new, changed = transform_chunk(code)

    assert changed
    assert new == expected
github ikamensh / flynt / test / test_transform.py View on Github external
def test_multiline():
    code = """
    "Flask Documentation ({})".format(
    version
)
    """.strip()
    expected = '''f"""Flask Documentation ({version})"""'''

    new, changed = transform_chunk(code)

    assert changed
    assert new == expected
github ikamensh / flynt / src / flynt / process.py View on Github external
def fstringify_code_by_line(code: str, multiline=True, len_limit=88) -> Tuple[str, int]:
    """ returns fstringified version of the code and amount of lines edited."""
    return _transform_code(
        code, split.get_fstringify_chunks, transform_chunk, multiline, len_limit
    )