| from __future__ import annotations |
| from pre_commit_hooks.string_fixer import main |
| (r"'\"\"'", r"'\"\"'", 0), |
| # String somewhere in the line |
| ('x = "foo"', "x = 'foo'", 1), |
| # Test escaped characters |
| ('""" Foo """', '""" Foo """', 0), |
| ('"foo""bar"', "'foo''bar'", 1), |
| id='ignore nested fstrings', |
| @pytest.mark.parametrize(('input_s', 'output', 'expected_retval'), TESTS) |
| def test_rewrite(input_s, output, expected_retval, tmpdir): |
| path = tmpdir.join('file.py') |
| retval = main([str(path)]) |
| assert path.read() == output |
| assert retval == expected_retval |
| def test_rewrite_crlf(tmpdir): |
| f.write_binary(b'"foo"\r\n"bar"\r\n') |
| assert f.read_binary() == b"'foo'\r\n'bar'\r\n" |