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_invalid_unicode(invalid_unicode_file): modified, _, _, _ = _fstringify_file(invalid_unicode_file, True, 1000) with open(invalid_unicode_file, "rb") as f: content_after = f.read() assert not modified assert content_after == invalid_unicode
def test_mixed_line_endings(mixed_line_endings_file): modified, _, _, _ = _fstringify_file(mixed_line_endings_file, True, 1000) with open(mixed_line_endings_file, "rb") as f: content_after = f.read() assert modified assert content_after == mixed_line_endings_after
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""" in_path = os.path.join(in_dir, filename) out_path = os.path.join(out_dir, filename) shutil.copyfile(in_path, out_path) _fstringify_file(out_path, multiline=multiline, len_limit=120, transform_concat=True) out = read_output_file(filename) return out, read_expected(filename)
def test_dry_run(formattable_file, monkeypatch): monkeypatch.setattr(state, "dry_run", True) 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_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_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
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