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_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]
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)"
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]
def test_line_continuation():
generator = split.get_fstringify_chunks(line_continuation)
assert len(list(generator)) == 1
def test_tuple_list():
generator = split.get_fstringify_chunks(tuple_in_list)
assert len(list(generator)) == 1
def test_tuple_percent():
code = """print("%s %s " % (var+var, abc))"""
generator = split.get_fstringify_chunks(tuple_in_list)
assert len(list(generator)) == 1
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)"
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
def test_str_newline():
s_in = """a = '%s\\n' % var"""
generator = split.get_fstringify_chunks(s_in)
assert len(list(generator)) == 1