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_works(formattable_file):
with open(formattable_file) as f:
content_before = f.read()
modified, _, _, _ = _fstringify_file(formattable_file, True, 1000)
with open(formattable_file) as f:
content_after = f.read()
assert modified
assert content_after != content_before
def test_catches_subtle(formattable_file, monkeypatch):
with open(formattable_file) as f:
content_before = f.read()
def broken_fstringify_by_line(*args, **kwargs):
return "a = 42", 42
monkeypatch.setattr(api, "fstringify_code_by_line", broken_fstringify_by_line)
modified, _, _, _ = _fstringify_file(formattable_file, True, 1000)
with open(formattable_file) as f:
content_after = f.read()
assert not modified
assert content_after == content_before
def test_break_safe(formattable_file, monkeypatch):
with open(formattable_file) as f:
content_before = f.read()
def broken_fstringify_by_line(*args, **kwargs):
return "Hello World", 42
monkeypatch.setattr(api, "fstringify_code_by_line", broken_fstringify_by_line)
modified, _, _, _ = _fstringify_file(formattable_file, True, 1000)
with open(formattable_file) as f:
content_after = f.read()
assert not modified
assert content_after == content_before
def try_on_file_string_concat(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)
path = write_output_file(filename, txt_in)
_fstringify_file(path, multiline=multiline, len_limit=120, transform_concat=True)
out = read_output_file(filename)
return out, read_expected(filename)
def test_py2(py2_file):
with open(py2_file) as f:
content_before = f.read()
modified, _, _, _ = _fstringify_file(py2_file, True, 1000)
with open(py2_file) as f:
content_after = f.read()
assert not modified
assert content_after == content_before