commit
0e509ddcbc
|
@ -75,7 +75,7 @@ xfailif_no_gitlfs = pytest.mark.xfail(
|
||||||
@xfailif_no_gitlfs
|
@xfailif_no_gitlfs
|
||||||
def test_allows_gitlfs(temp_git_dir, monkeypatch): # pragma: no cover
|
def test_allows_gitlfs(temp_git_dir, monkeypatch): # pragma: no cover
|
||||||
with temp_git_dir.as_cwd():
|
with temp_git_dir.as_cwd():
|
||||||
monkeypatch.setenv('HOME', str(temp_git_dir.strpath))
|
monkeypatch.setenv('HOME', str(temp_git_dir))
|
||||||
cmd_output('git', 'lfs', 'install')
|
cmd_output('git', 'lfs', 'install')
|
||||||
temp_git_dir.join('f.py').write('a' * 10000)
|
temp_git_dir.join('f.py').write('a' * 10000)
|
||||||
cmd_output('git', 'lfs', 'track', 'f.py')
|
cmd_output('git', 'lfs', 'track', 'f.py')
|
||||||
|
@ -87,7 +87,7 @@ def test_allows_gitlfs(temp_git_dir, monkeypatch): # pragma: no cover
|
||||||
@xfailif_no_gitlfs
|
@xfailif_no_gitlfs
|
||||||
def test_moves_with_gitlfs(temp_git_dir, monkeypatch): # pragma: no cover
|
def test_moves_with_gitlfs(temp_git_dir, monkeypatch): # pragma: no cover
|
||||||
with temp_git_dir.as_cwd():
|
with temp_git_dir.as_cwd():
|
||||||
monkeypatch.setenv('HOME', str(temp_git_dir.strpath))
|
monkeypatch.setenv('HOME', str(temp_git_dir))
|
||||||
cmd_output('git', 'lfs', 'install')
|
cmd_output('git', 'lfs', 'install')
|
||||||
cmd_output('git', 'lfs', 'track', 'a.bin', 'b.bin')
|
cmd_output('git', 'lfs', 'track', 'a.bin', 'b.bin')
|
||||||
# First add the file we're going to move
|
# First add the file we're going to move
|
||||||
|
|
|
@ -131,19 +131,19 @@ def test_ignore_constructors():
|
||||||
def test_failing_file(tmpdir):
|
def test_failing_file(tmpdir):
|
||||||
f = tmpdir.join('f.py')
|
f = tmpdir.join('f.py')
|
||||||
f.write(BUILTIN_CONSTRUCTORS)
|
f.write(BUILTIN_CONSTRUCTORS)
|
||||||
rc = main([f.strpath])
|
rc = main([str(f)])
|
||||||
assert rc == 1
|
assert rc == 1
|
||||||
|
|
||||||
|
|
||||||
def test_passing_file(tmpdir):
|
def test_passing_file(tmpdir):
|
||||||
f = tmpdir.join('f.py')
|
f = tmpdir.join('f.py')
|
||||||
f.write(BUILTIN_LITERALS)
|
f.write(BUILTIN_LITERALS)
|
||||||
rc = main([f.strpath])
|
rc = main([str(f)])
|
||||||
assert rc == 0
|
assert rc == 0
|
||||||
|
|
||||||
|
|
||||||
def test_failing_file_ignore_all(tmpdir):
|
def test_failing_file_ignore_all(tmpdir):
|
||||||
f = tmpdir.join('f.py')
|
f = tmpdir.join('f.py')
|
||||||
f.write(BUILTIN_CONSTRUCTORS)
|
f.write(BUILTIN_CONSTRUCTORS)
|
||||||
rc = main(['--ignore=complex,dict,float,int,list,str,tuple', f.strpath])
|
rc = main(['--ignore=complex,dict,float,int,list,str,tuple', str(f)])
|
||||||
assert rc == 0
|
assert rc == 0
|
||||||
|
|
|
@ -4,10 +4,10 @@ from pre_commit_hooks import check_byte_order_marker
|
||||||
def test_failure(tmpdir):
|
def test_failure(tmpdir):
|
||||||
f = tmpdir.join('f.txt')
|
f = tmpdir.join('f.txt')
|
||||||
f.write_text('ohai', encoding='utf-8-sig')
|
f.write_text('ohai', encoding='utf-8-sig')
|
||||||
assert check_byte_order_marker.main((f.strpath,)) == 1
|
assert check_byte_order_marker.main((str(f),)) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_success(tmpdir):
|
def test_success(tmpdir):
|
||||||
f = tmpdir.join('f.txt')
|
f = tmpdir.join('f.txt')
|
||||||
f.write_text('ohai', encoding='utf-8')
|
f.write_text('ohai', encoding='utf-8')
|
||||||
assert check_byte_order_marker.main((f.strpath,)) == 0
|
assert check_byte_order_marker.main((str(f),)) == 0
|
||||||
|
|
|
@ -56,12 +56,12 @@ def test_unit(capsys, contents, expected, expected_out):
|
||||||
def test_integration(tmpdir, capsys, contents, expected, expected_out):
|
def test_integration(tmpdir, capsys, contents, expected, expected_out):
|
||||||
f = tmpdir.join('test.py')
|
f = tmpdir.join('test.py')
|
||||||
f.write_binary(contents)
|
f.write_binary(contents)
|
||||||
assert main([f.strpath]) == expected
|
assert main([str(f)]) == expected
|
||||||
assert capsys.readouterr()[0] == expected_out.format(filename=f.strpath)
|
assert capsys.readouterr()[0] == expected_out.format(filename=str(f))
|
||||||
|
|
||||||
|
|
||||||
def test_arbitrary_encoding(tmpdir):
|
def test_arbitrary_encoding(tmpdir):
|
||||||
f = tmpdir.join('f.py')
|
f = tmpdir.join('f.py')
|
||||||
contents = '# -*- coding: cp1252\nx = "£"'.encode('cp1252')
|
contents = '# -*- coding: cp1252\nx = "£"'.encode('cp1252')
|
||||||
f.write_binary(contents)
|
f.write_binary(contents)
|
||||||
assert main([f.strpath]) == 0
|
assert main([str(f)]) == 0
|
||||||
|
|
|
@ -25,7 +25,7 @@ skip_win32 = pytest.mark.skipif(
|
||||||
def test_has_shebang(content, tmpdir):
|
def test_has_shebang(content, tmpdir):
|
||||||
path = tmpdir.join('path')
|
path = tmpdir.join('path')
|
||||||
path.write(content, 'wb')
|
path.write(content, 'wb')
|
||||||
assert main((path.strpath,)) == 0
|
assert main((str(path),)) == 0
|
||||||
|
|
||||||
|
|
||||||
@skip_win32 # pragma: win32 no cover
|
@skip_win32 # pragma: win32 no cover
|
||||||
|
@ -41,7 +41,7 @@ def test_has_shebang(content, tmpdir):
|
||||||
def test_bad_shebang(content, tmpdir, capsys):
|
def test_bad_shebang(content, tmpdir, capsys):
|
||||||
path = tmpdir.join('path')
|
path = tmpdir.join('path')
|
||||||
path.write(content, 'wb')
|
path.write(content, 'wb')
|
||||||
assert main((path.strpath,)) == 1
|
assert main((str(path),)) == 1
|
||||||
_, stderr = capsys.readouterr()
|
_, stderr = capsys.readouterr()
|
||||||
assert stderr.startswith(f'{path}: marked executable but')
|
assert stderr.startswith(f'{path}: marked executable but')
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,13 @@ def f1_is_a_conflict_file(tmpdir):
|
||||||
repo2 = tmpdir.join('repo2')
|
repo2 = tmpdir.join('repo2')
|
||||||
repo2_f1 = repo2.join('f1')
|
repo2_f1 = repo2.join('f1')
|
||||||
|
|
||||||
cmd_output('git', 'init', '--', repo1.strpath)
|
cmd_output('git', 'init', '--', str(repo1))
|
||||||
with repo1.as_cwd():
|
with repo1.as_cwd():
|
||||||
repo1_f1.ensure()
|
repo1_f1.ensure()
|
||||||
cmd_output('git', 'add', '.')
|
cmd_output('git', 'add', '.')
|
||||||
cmd_output('git', 'commit', '--no-gpg-sign', '-m', 'commit1')
|
cmd_output('git', 'commit', '--no-gpg-sign', '-m', 'commit1')
|
||||||
|
|
||||||
cmd_output('git', 'clone', repo1.strpath, repo2.strpath)
|
cmd_output('git', 'clone', str(repo1), str(repo2))
|
||||||
|
|
||||||
# Commit in master
|
# Commit in master
|
||||||
with repo1.as_cwd():
|
with repo1.as_cwd():
|
||||||
|
@ -71,13 +71,13 @@ def repository_pending_merge(tmpdir):
|
||||||
repo2 = tmpdir.join('repo2')
|
repo2 = tmpdir.join('repo2')
|
||||||
repo2_f1 = repo2.join('f1')
|
repo2_f1 = repo2.join('f1')
|
||||||
repo2_f2 = repo2.join('f2')
|
repo2_f2 = repo2.join('f2')
|
||||||
cmd_output('git', 'init', repo1.strpath)
|
cmd_output('git', 'init', str(repo1))
|
||||||
with repo1.as_cwd():
|
with repo1.as_cwd():
|
||||||
repo1_f1.ensure()
|
repo1_f1.ensure()
|
||||||
cmd_output('git', 'add', '.')
|
cmd_output('git', 'add', '.')
|
||||||
cmd_output('git', 'commit', '--no-gpg-sign', '-m', 'commit1')
|
cmd_output('git', 'commit', '--no-gpg-sign', '-m', 'commit1')
|
||||||
|
|
||||||
cmd_output('git', 'clone', repo1.strpath, repo2.strpath)
|
cmd_output('git', 'clone', str(repo1), str(repo2))
|
||||||
|
|
||||||
# Commit in master
|
# Commit in master
|
||||||
with repo1.as_cwd():
|
with repo1.as_cwd():
|
||||||
|
|
|
@ -16,8 +16,8 @@ def test_main(tmpdir, dest, expected): # pragma: no cover (symlinks)
|
||||||
tmpdir.join('exists').ensure()
|
tmpdir.join('exists').ensure()
|
||||||
symlink = tmpdir.join('symlink')
|
symlink = tmpdir.join('symlink')
|
||||||
symlink.mksymlinkto(tmpdir.join(dest))
|
symlink.mksymlinkto(tmpdir.join(dest))
|
||||||
assert main((symlink.strpath,)) == expected
|
assert main((str(symlink),)) == expected
|
||||||
|
|
||||||
|
|
||||||
def test_main_normal_file(tmpdir):
|
def test_main_normal_file(tmpdir):
|
||||||
assert main((tmpdir.join('f').ensure().strpath,)) == 0
|
assert main((str(tmpdir.join('f').ensure()),)) == 0
|
||||||
|
|
|
@ -8,7 +8,7 @@ key = # INVALID
|
||||||
|
|
||||||
= "no key name" # INVALID
|
= "no key name" # INVALID
|
||||||
""")
|
""")
|
||||||
ret = main((filename.strpath,))
|
ret = main((str(filename),))
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,12 +25,12 @@ name = "John"
|
||||||
dob = 1979-05-27T07:32:00-08:00 # First class dates
|
dob = 1979-05-27T07:32:00-08:00 # First class dates
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
ret = main((filename.strpath,))
|
ret = main((str(filename),))
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
|
|
||||||
|
|
||||||
def test_toml_good_unicode(tmpdir):
|
def test_toml_good_unicode(tmpdir):
|
||||||
filename = tmpdir.join('f')
|
filename = tmpdir.join('f')
|
||||||
filename.write_binary('letter = "\N{SNOWMAN}"\n'.encode())
|
filename.write_binary('letter = "\N{SNOWMAN}"\n'.encode())
|
||||||
ret = main((filename.strpath,))
|
ret = main((str(filename),))
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
|
|
|
@ -3,7 +3,7 @@ from pre_commit_hooks.check_vcs_permalinks import main
|
||||||
|
|
||||||
def test_trivial(tmpdir):
|
def test_trivial(tmpdir):
|
||||||
f = tmpdir.join('f.txt').ensure()
|
f = tmpdir.join('f.txt').ensure()
|
||||||
assert not main((f.strpath,))
|
assert not main((str(f),))
|
||||||
|
|
||||||
|
|
||||||
def test_passing(tmpdir):
|
def test_passing(tmpdir):
|
||||||
|
@ -16,7 +16,7 @@ def test_passing(tmpdir):
|
||||||
# regression test for overly-greedy regex
|
# regression test for overly-greedy regex
|
||||||
b'https://github.com/ yes / no ? /blob/master/foo#L1\n',
|
b'https://github.com/ yes / no ? /blob/master/foo#L1\n',
|
||||||
)
|
)
|
||||||
assert not main((f.strpath,))
|
assert not main((str(f),))
|
||||||
|
|
||||||
|
|
||||||
def test_failing(tmpdir, capsys):
|
def test_failing(tmpdir, capsys):
|
||||||
|
|
|
@ -20,16 +20,16 @@ def test_main_allow_multiple_documents(tmpdir):
|
||||||
f.write('---\nfoo\n---\nbar\n')
|
f.write('---\nfoo\n---\nbar\n')
|
||||||
|
|
||||||
# should fail without the setting
|
# should fail without the setting
|
||||||
assert main((f.strpath,))
|
assert main((str(f),))
|
||||||
|
|
||||||
# should pass when we allow multiple documents
|
# should pass when we allow multiple documents
|
||||||
assert not main(('--allow-multiple-documents', f.strpath))
|
assert not main(('--allow-multiple-documents', str(f)))
|
||||||
|
|
||||||
|
|
||||||
def test_fails_even_with_allow_multiple_documents(tmpdir):
|
def test_fails_even_with_allow_multiple_documents(tmpdir):
|
||||||
f = tmpdir.join('test.yaml')
|
f = tmpdir.join('test.yaml')
|
||||||
f.write('[')
|
f.write('[')
|
||||||
assert main(('--allow-multiple-documents', f.strpath))
|
assert main(('--allow-multiple-documents', str(f)))
|
||||||
|
|
||||||
|
|
||||||
def test_main_unsafe(tmpdir):
|
def test_main_unsafe(tmpdir):
|
||||||
|
@ -40,12 +40,12 @@ def test_main_unsafe(tmpdir):
|
||||||
' deadbeefdeadbeefdeadbeef\n',
|
' deadbeefdeadbeefdeadbeef\n',
|
||||||
)
|
)
|
||||||
# should fail "safe" check
|
# should fail "safe" check
|
||||||
assert main((f.strpath,))
|
assert main((str(f),))
|
||||||
# should pass when we allow unsafe documents
|
# should pass when we allow unsafe documents
|
||||||
assert not main(('--unsafe', f.strpath))
|
assert not main(('--unsafe', str(f)))
|
||||||
|
|
||||||
|
|
||||||
def test_main_unsafe_still_fails_on_syntax_errors(tmpdir):
|
def test_main_unsafe_still_fails_on_syntax_errors(tmpdir):
|
||||||
f = tmpdir.join('test.yaml')
|
f = tmpdir.join('test.yaml')
|
||||||
f.write('[')
|
f.write('[')
|
||||||
assert main(('--unsafe', f.strpath))
|
assert main(('--unsafe', str(f)))
|
||||||
|
|
|
@ -6,5 +6,5 @@ from pre_commit_hooks.util import cmd_output
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def temp_git_dir(tmpdir):
|
def temp_git_dir(tmpdir):
|
||||||
git_dir = tmpdir.join('gits')
|
git_dir = tmpdir.join('gits')
|
||||||
cmd_output('git', 'init', '--', git_dir.strpath)
|
cmd_output('git', 'init', '--', str(git_dir))
|
||||||
yield git_dir
|
yield git_dir
|
||||||
|
|
|
@ -33,7 +33,7 @@ def test_finds_breakpoint():
|
||||||
def test_returns_one_for_failing_file(tmpdir):
|
def test_returns_one_for_failing_file(tmpdir):
|
||||||
f_py = tmpdir.join('f.py')
|
f_py = tmpdir.join('f.py')
|
||||||
f_py.write('def f():\n import pdb; pdb.set_trace()')
|
f_py.write('def f():\n import pdb; pdb.set_trace()')
|
||||||
ret = main([f_py.strpath])
|
ret = main([str(f_py)])
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,10 +50,10 @@ def test_syntaxerror_file():
|
||||||
def test_non_utf8_file(tmpdir):
|
def test_non_utf8_file(tmpdir):
|
||||||
f_py = tmpdir.join('f.py')
|
f_py = tmpdir.join('f.py')
|
||||||
f_py.write_binary('# -*- coding: cp1252 -*-\nx = "€"\n'.encode('cp1252'))
|
f_py.write_binary('# -*- coding: cp1252 -*-\nx = "€"\n'.encode('cp1252'))
|
||||||
assert main((f_py.strpath,)) == 0
|
assert main((str(f_py),)) == 0
|
||||||
|
|
||||||
|
|
||||||
def test_py37_breakpoint(tmpdir):
|
def test_py37_breakpoint(tmpdir):
|
||||||
f_py = tmpdir.join('f.py')
|
f_py = tmpdir.join('f.py')
|
||||||
f_py.write('def f():\n breakpoint()\n')
|
f_py.write('def f():\n breakpoint()\n')
|
||||||
assert main((f_py.strpath,)) == 1
|
assert main((str(f_py),)) == 1
|
||||||
|
|
|
@ -21,4 +21,4 @@ TESTS = (
|
||||||
def test_main(input_s, expected_retval, tmpdir):
|
def test_main(input_s, expected_retval, tmpdir):
|
||||||
path = tmpdir.join('file.txt')
|
path = tmpdir.join('file.txt')
|
||||||
path.write_binary(input_s)
|
path.write_binary(input_s)
|
||||||
assert main([path.strpath]) == expected_retval
|
assert main([str(path)]) == expected_retval
|
||||||
|
|
|
@ -35,7 +35,7 @@ def test_integration(input_s, expected_retval, output, tmpdir):
|
||||||
path = tmpdir.join('file.txt')
|
path = tmpdir.join('file.txt')
|
||||||
path.write_binary(input_s)
|
path.write_binary(input_s)
|
||||||
|
|
||||||
ret = main([path.strpath])
|
ret = main([str(path)])
|
||||||
file_output = path.read_binary()
|
file_output = path.read_binary()
|
||||||
|
|
||||||
assert file_output == output
|
assert file_output == output
|
||||||
|
|
|
@ -27,7 +27,7 @@ def test_integration(input_s, expected_retval, output, tmpdir):
|
||||||
path = tmpdir.join('file.txt')
|
path = tmpdir.join('file.txt')
|
||||||
path.write_binary(input_s)
|
path.write_binary(input_s)
|
||||||
|
|
||||||
output_retval = main([path.strpath])
|
output_retval = main([str(path)])
|
||||||
|
|
||||||
assert path.read_binary() == output
|
assert path.read_binary() == output
|
||||||
assert output_retval == expected_retval
|
assert output_retval == expected_retval
|
||||||
|
|
|
@ -11,7 +11,7 @@ def test_integration_inserting_pragma(tmpdir):
|
||||||
path = tmpdir.join('foo.py')
|
path = tmpdir.join('foo.py')
|
||||||
path.write_binary(b'import httplib\n')
|
path.write_binary(b'import httplib\n')
|
||||||
|
|
||||||
assert main((path.strpath,)) == 1
|
assert main((str(path),)) == 1
|
||||||
|
|
||||||
assert path.read_binary() == (
|
assert path.read_binary() == (
|
||||||
b'# -*- coding: utf-8 -*-\n'
|
b'# -*- coding: utf-8 -*-\n'
|
||||||
|
@ -22,14 +22,14 @@ def test_integration_inserting_pragma(tmpdir):
|
||||||
def test_integration_ok(tmpdir):
|
def test_integration_ok(tmpdir):
|
||||||
path = tmpdir.join('foo.py')
|
path = tmpdir.join('foo.py')
|
||||||
path.write_binary(b'# -*- coding: utf-8 -*-\nx = 1\n')
|
path.write_binary(b'# -*- coding: utf-8 -*-\nx = 1\n')
|
||||||
assert main((path.strpath,)) == 0
|
assert main((str(path),)) == 0
|
||||||
|
|
||||||
|
|
||||||
def test_integration_remove(tmpdir):
|
def test_integration_remove(tmpdir):
|
||||||
path = tmpdir.join('foo.py')
|
path = tmpdir.join('foo.py')
|
||||||
path.write_binary(b'# -*- coding: utf-8 -*-\nx = 1\n')
|
path.write_binary(b'# -*- coding: utf-8 -*-\nx = 1\n')
|
||||||
|
|
||||||
assert main((path.strpath, '--remove')) == 1
|
assert main((str(path), '--remove')) == 1
|
||||||
|
|
||||||
assert path.read_binary() == b'x = 1\n'
|
assert path.read_binary() == b'x = 1\n'
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ def test_integration_remove(tmpdir):
|
||||||
def test_integration_remove_ok(tmpdir):
|
def test_integration_remove_ok(tmpdir):
|
||||||
path = tmpdir.join('foo.py')
|
path = tmpdir.join('foo.py')
|
||||||
path.write_binary(b'x = 1\n')
|
path.write_binary(b'x = 1\n')
|
||||||
assert main((path.strpath, '--remove')) == 0
|
assert main((str(path), '--remove')) == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
@ -140,20 +140,20 @@ def test_integration_alternate_pragma(tmpdir, capsys):
|
||||||
f.write('x = 1\n')
|
f.write('x = 1\n')
|
||||||
|
|
||||||
pragma = '# coding: utf-8'
|
pragma = '# coding: utf-8'
|
||||||
assert main((f.strpath, '--pragma', pragma)) == 1
|
assert main((str(f), '--pragma', pragma)) == 1
|
||||||
assert f.read() == '# coding: utf-8\nx = 1\n'
|
assert f.read() == '# coding: utf-8\nx = 1\n'
|
||||||
out, _ = capsys.readouterr()
|
out, _ = capsys.readouterr()
|
||||||
assert out == f'Added `# coding: utf-8` to {f.strpath}\n'
|
assert out == f'Added `# coding: utf-8` to {str(f)}\n'
|
||||||
|
|
||||||
|
|
||||||
def test_crlf_ok(tmpdir):
|
def test_crlf_ok(tmpdir):
|
||||||
f = tmpdir.join('f.py')
|
f = tmpdir.join('f.py')
|
||||||
f.write_binary(b'# -*- coding: utf-8 -*-\r\nx = 1\r\n')
|
f.write_binary(b'# -*- coding: utf-8 -*-\r\nx = 1\r\n')
|
||||||
assert not main((f.strpath,))
|
assert not main((str(f),))
|
||||||
|
|
||||||
|
|
||||||
def test_crfl_adds(tmpdir):
|
def test_crfl_adds(tmpdir):
|
||||||
f = tmpdir.join('f.py')
|
f = tmpdir.join('f.py')
|
||||||
f.write_binary(b'x = 1\r\n')
|
f.write_binary(b'x = 1\r\n')
|
||||||
assert main((f.strpath,))
|
assert main((str(f),))
|
||||||
assert f.read_binary() == b'# -*- coding: utf-8 -*-\r\nx = 1\r\n'
|
assert f.read_binary() == b'# -*- coding: utf-8 -*-\r\nx = 1\r\n'
|
||||||
|
|
|
@ -15,7 +15,7 @@ def git_dir_with_git_dir(tmpdir):
|
||||||
subprocess.check_call(('git', 'init', 'foo'))
|
subprocess.check_call(('git', 'init', 'foo'))
|
||||||
subprocess.check_call(
|
subprocess.check_call(
|
||||||
('git', 'commit', '-m', 'init', '--allow-empty', '--no-gpg-sign'),
|
('git', 'commit', '-m', 'init', '--allow-empty', '--no-gpg-sign'),
|
||||||
cwd=tmpdir.join('foo').strpath,
|
cwd=str(tmpdir.join('foo')),
|
||||||
)
|
)
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ from pre_commit_hooks.mixed_line_ending import main
|
||||||
def test_mixed_line_ending_fixes_auto(input_s, output, tmpdir):
|
def test_mixed_line_ending_fixes_auto(input_s, output, tmpdir):
|
||||||
path = tmpdir.join('file.txt')
|
path = tmpdir.join('file.txt')
|
||||||
path.write_binary(input_s)
|
path.write_binary(input_s)
|
||||||
ret = main((path.strpath,))
|
ret = main((str(path),))
|
||||||
|
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
assert path.read_binary() == output
|
assert path.read_binary() == output
|
||||||
|
@ -34,7 +34,7 @@ def test_mixed_line_ending_fixes_auto(input_s, output, tmpdir):
|
||||||
def test_non_mixed_no_newline_end_of_file(tmpdir):
|
def test_non_mixed_no_newline_end_of_file(tmpdir):
|
||||||
path = tmpdir.join('f.txt')
|
path = tmpdir.join('f.txt')
|
||||||
path.write_binary(b'foo\nbar\nbaz')
|
path.write_binary(b'foo\nbar\nbaz')
|
||||||
assert not main((path.strpath,))
|
assert not main((str(path),))
|
||||||
# the hook *could* fix the end of the file, but leaves it alone
|
# the hook *could* fix the end of the file, but leaves it alone
|
||||||
# this is mostly to document the current behaviour
|
# this is mostly to document the current behaviour
|
||||||
assert path.read_binary() == b'foo\nbar\nbaz'
|
assert path.read_binary() == b'foo\nbar\nbaz'
|
||||||
|
@ -43,7 +43,7 @@ def test_non_mixed_no_newline_end_of_file(tmpdir):
|
||||||
def test_mixed_no_newline_end_of_file(tmpdir):
|
def test_mixed_no_newline_end_of_file(tmpdir):
|
||||||
path = tmpdir.join('f.txt')
|
path = tmpdir.join('f.txt')
|
||||||
path.write_binary(b'foo\r\nbar\nbaz')
|
path.write_binary(b'foo\r\nbar\nbaz')
|
||||||
assert main((path.strpath,))
|
assert main((str(path),))
|
||||||
# the hook rewrites the end of the file, this is slightly inconsistent
|
# the hook rewrites the end of the file, this is slightly inconsistent
|
||||||
# with the non-mixed case but I think this is the better behaviour
|
# with the non-mixed case but I think this is the better behaviour
|
||||||
# this is mostly to document the current behaviour
|
# this is mostly to document the current behaviour
|
||||||
|
@ -66,7 +66,7 @@ def test_mixed_no_newline_end_of_file(tmpdir):
|
||||||
def test_line_endings_ok(fix_option, input_s, tmpdir, capsys):
|
def test_line_endings_ok(fix_option, input_s, tmpdir, capsys):
|
||||||
path = tmpdir.join('input.txt')
|
path = tmpdir.join('input.txt')
|
||||||
path.write_binary(input_s)
|
path.write_binary(input_s)
|
||||||
ret = main((fix_option, path.strpath))
|
ret = main((fix_option, str(path)))
|
||||||
|
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert path.read_binary() == input_s
|
assert path.read_binary() == input_s
|
||||||
|
@ -78,7 +78,7 @@ def test_no_fix_does_not_modify(tmpdir, capsys):
|
||||||
path = tmpdir.join('input.txt')
|
path = tmpdir.join('input.txt')
|
||||||
contents = b'foo\r\nbar\rbaz\nwomp\n'
|
contents = b'foo\r\nbar\rbaz\nwomp\n'
|
||||||
path.write_binary(contents)
|
path.write_binary(contents)
|
||||||
ret = main(('--fix=no', path.strpath))
|
ret = main(('--fix=no', str(path)))
|
||||||
|
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
assert path.read_binary() == contents
|
assert path.read_binary() == contents
|
||||||
|
@ -89,7 +89,7 @@ def test_no_fix_does_not_modify(tmpdir, capsys):
|
||||||
def test_fix_lf(tmpdir, capsys):
|
def test_fix_lf(tmpdir, capsys):
|
||||||
path = tmpdir.join('input.txt')
|
path = tmpdir.join('input.txt')
|
||||||
path.write_binary(b'foo\r\nbar\rbaz\n')
|
path.write_binary(b'foo\r\nbar\rbaz\n')
|
||||||
ret = main(('--fix=lf', path.strpath))
|
ret = main(('--fix=lf', str(path)))
|
||||||
|
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
assert path.read_binary() == b'foo\nbar\nbaz\n'
|
assert path.read_binary() == b'foo\nbar\nbaz\n'
|
||||||
|
@ -100,7 +100,7 @@ def test_fix_lf(tmpdir, capsys):
|
||||||
def test_fix_crlf(tmpdir):
|
def test_fix_crlf(tmpdir):
|
||||||
path = tmpdir.join('input.txt')
|
path = tmpdir.join('input.txt')
|
||||||
path.write_binary(b'foo\r\nbar\rbaz\n')
|
path.write_binary(b'foo\r\nbar\rbaz\n')
|
||||||
ret = main(('--fix=crlf', path.strpath))
|
ret = main(('--fix=crlf', str(path)))
|
||||||
|
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
assert path.read_binary() == b'foo\r\nbar\r\nbaz\r\n'
|
assert path.read_binary() == b'foo\r\nbar\r\nbaz\r\n'
|
||||||
|
@ -110,7 +110,7 @@ def test_fix_lf_all_crlf(tmpdir):
|
||||||
"""Regression test for #239"""
|
"""Regression test for #239"""
|
||||||
path = tmpdir.join('input.txt')
|
path = tmpdir.join('input.txt')
|
||||||
path.write_binary(b'foo\r\nbar\r\n')
|
path.write_binary(b'foo\r\nbar\r\n')
|
||||||
ret = main(('--fix=lf', path.strpath))
|
ret = main(('--fix=lf', str(path)))
|
||||||
|
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
assert path.read_binary() == b'foo\nbar\n'
|
assert path.read_binary() == b'foo\nbar\n'
|
||||||
|
|
|
@ -67,16 +67,16 @@ def test_autofix_main(tmpdir):
|
||||||
srcfile = tmpdir.join('to_be_json_formatted.json')
|
srcfile = tmpdir.join('to_be_json_formatted.json')
|
||||||
shutil.copyfile(
|
shutil.copyfile(
|
||||||
get_resource_path('not_pretty_formatted_json.json'),
|
get_resource_path('not_pretty_formatted_json.json'),
|
||||||
srcfile.strpath,
|
str(srcfile),
|
||||||
)
|
)
|
||||||
|
|
||||||
# now launch the autofix on that file
|
# now launch the autofix on that file
|
||||||
ret = main(['--autofix', srcfile.strpath])
|
ret = main(['--autofix', str(srcfile)])
|
||||||
# it should have formatted it
|
# it should have formatted it
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
|
|
||||||
# file was formatted (shouldn't trigger linter again)
|
# file was formatted (shouldn't trigger linter again)
|
||||||
ret = main([srcfile.strpath])
|
ret = main([str(srcfile)])
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ def test_integration(input_s, expected_retval, output, tmpdir):
|
||||||
path = tmpdir.join('file.txt')
|
path = tmpdir.join('file.txt')
|
||||||
path.write_binary(input_s)
|
path.write_binary(input_s)
|
||||||
|
|
||||||
output_retval = main([path.strpath])
|
output_retval = main([str(path)])
|
||||||
|
|
||||||
assert path.read_binary() == output
|
assert path.read_binary() == output
|
||||||
assert output_retval == expected_retval
|
assert output_retval == expected_retval
|
||||||
|
|
|
@ -39,7 +39,7 @@ TEST_SORTS = [
|
||||||
|
|
||||||
@pytest.mark.parametrize('bad_lines,good_lines,retval', TEST_SORTS)
|
@pytest.mark.parametrize('bad_lines,good_lines,retval', TEST_SORTS)
|
||||||
def test_integration_good_bad_lines(tmpdir, bad_lines, good_lines, retval):
|
def test_integration_good_bad_lines(tmpdir, bad_lines, good_lines, retval):
|
||||||
file_path = os.path.join(tmpdir.strpath, 'foo.yaml')
|
file_path = os.path.join(str(tmpdir), 'foo.yaml')
|
||||||
|
|
||||||
with open(file_path, 'w') as f:
|
with open(file_path, 'w') as f:
|
||||||
f.write('\n'.join(bad_lines) + '\n')
|
f.write('\n'.join(bad_lines) + '\n')
|
||||||
|
|
|
@ -42,7 +42,7 @@ TESTS = (
|
||||||
def test_rewrite(input_s, output, expected_retval, tmpdir):
|
def test_rewrite(input_s, output, expected_retval, tmpdir):
|
||||||
path = tmpdir.join('file.py')
|
path = tmpdir.join('file.py')
|
||||||
path.write(input_s)
|
path.write(input_s)
|
||||||
retval = main([path.strpath])
|
retval = main([str(path)])
|
||||||
assert path.read() == output
|
assert path.read() == output
|
||||||
assert retval == expected_retval
|
assert retval == expected_retval
|
||||||
|
|
||||||
|
@ -50,5 +50,5 @@ def test_rewrite(input_s, output, expected_retval, tmpdir):
|
||||||
def test_rewrite_crlf(tmpdir):
|
def test_rewrite_crlf(tmpdir):
|
||||||
f = tmpdir.join('f.py')
|
f = tmpdir.join('f.py')
|
||||||
f.write_binary(b'"foo"\r\n"bar"\r\n')
|
f.write_binary(b'"foo"\r\n"bar"\r\n')
|
||||||
assert main((f.strpath,))
|
assert main((str(f),))
|
||||||
assert f.read_binary() == b"'foo'\r\n'bar'\r\n"
|
assert f.read_binary() == b"'foo'\r\n'bar'\r\n"
|
||||||
|
|
|
@ -13,14 +13,14 @@ from pre_commit_hooks.trailing_whitespace_fixer import main
|
||||||
def test_fixes_trailing_whitespace(input_s, expected, tmpdir):
|
def test_fixes_trailing_whitespace(input_s, expected, tmpdir):
|
||||||
path = tmpdir.join('file.md')
|
path = tmpdir.join('file.md')
|
||||||
path.write(input_s)
|
path.write(input_s)
|
||||||
assert main((path.strpath,)) == 1
|
assert main((str(path),)) == 1
|
||||||
assert path.read() == expected
|
assert path.read() == expected
|
||||||
|
|
||||||
|
|
||||||
def test_ok_no_newline_end_of_file(tmpdir):
|
def test_ok_no_newline_end_of_file(tmpdir):
|
||||||
filename = tmpdir.join('f')
|
filename = tmpdir.join('f')
|
||||||
filename.write_binary(b'foo\nbar')
|
filename.write_binary(b'foo\nbar')
|
||||||
ret = main((filename.strpath,))
|
ret = main((str(filename),))
|
||||||
assert filename.read_binary() == b'foo\nbar'
|
assert filename.read_binary() == b'foo\nbar'
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ def test_ok_no_newline_end_of_file(tmpdir):
|
||||||
def test_ok_with_dos_line_endings(tmpdir):
|
def test_ok_with_dos_line_endings(tmpdir):
|
||||||
filename = tmpdir.join('f')
|
filename = tmpdir.join('f')
|
||||||
filename.write_binary(b'foo\r\nbar\r\nbaz\r\n')
|
filename.write_binary(b'foo\r\nbar\r\nbaz\r\n')
|
||||||
ret = main((filename.strpath,))
|
ret = main((str(filename),))
|
||||||
assert filename.read_binary() == b'foo\r\nbar\r\nbaz\r\n'
|
assert filename.read_binary() == b'foo\r\nbar\r\nbaz\r\n'
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ def test_fixes_markdown_files(tmpdir, ext):
|
||||||
'\t\n' # trailing tabs are stripped anyway
|
'\t\n' # trailing tabs are stripped anyway
|
||||||
'\n ', # whitespace at the end of the file is removed
|
'\n ', # whitespace at the end of the file is removed
|
||||||
)
|
)
|
||||||
ret = main((path.strpath, f'--markdown-linebreak-ext={ext}'))
|
ret = main((str(path), f'--markdown-linebreak-ext={ext}'))
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
assert path.read() == (
|
assert path.read() == (
|
||||||
'foo \n'
|
'foo \n'
|
||||||
|
@ -63,7 +63,7 @@ def test_markdown_linebreak_ext_badopt(arg):
|
||||||
|
|
||||||
def test_prints_warning_with_no_markdown_ext(capsys, tmpdir):
|
def test_prints_warning_with_no_markdown_ext(capsys, tmpdir):
|
||||||
f = tmpdir.join('f').ensure()
|
f = tmpdir.join('f').ensure()
|
||||||
assert main((f.strpath, '--no-markdown-linebreak-ext')) == 0
|
assert main((str(f), '--no-markdown-linebreak-ext')) == 0
|
||||||
out, _ = capsys.readouterr()
|
out, _ = capsys.readouterr()
|
||||||
assert out == '--no-markdown-linebreak-ext now does nothing!\n'
|
assert out == '--no-markdown-linebreak-ext now does nothing!\n'
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ def test_preserve_non_utf8_file(tmpdir):
|
||||||
non_utf8_bytes_content = b'<a>\xe9 \n</a>\n'
|
non_utf8_bytes_content = b'<a>\xe9 \n</a>\n'
|
||||||
path = tmpdir.join('file.txt')
|
path = tmpdir.join('file.txt')
|
||||||
path.write_binary(non_utf8_bytes_content)
|
path.write_binary(non_utf8_bytes_content)
|
||||||
ret = main([path.strpath])
|
ret = main([str(path)])
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
assert path.size() == (len(non_utf8_bytes_content) - 1)
|
assert path.size() == (len(non_utf8_bytes_content) - 1)
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ def test_custom_charset_change(tmpdir):
|
||||||
# strip spaces only, no tabs
|
# strip spaces only, no tabs
|
||||||
path = tmpdir.join('file.txt')
|
path = tmpdir.join('file.txt')
|
||||||
path.write('\ta \t \n')
|
path.write('\ta \t \n')
|
||||||
ret = main([path.strpath, '--chars', ' '])
|
ret = main([str(path), '--chars', ' '])
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
assert path.read() == '\ta \t\n'
|
assert path.read() == '\ta \t\n'
|
||||||
|
|
||||||
|
@ -89,13 +89,13 @@ def test_custom_charset_change(tmpdir):
|
||||||
def test_custom_charset_no_change(tmpdir):
|
def test_custom_charset_no_change(tmpdir):
|
||||||
path = tmpdir.join('file.txt')
|
path = tmpdir.join('file.txt')
|
||||||
path.write('\ta \t\n')
|
path.write('\ta \t\n')
|
||||||
ret = main([path.strpath, '--chars', ' '])
|
ret = main([str(path), '--chars', ' '])
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
|
|
||||||
|
|
||||||
def test_markdown_with_custom_charset(tmpdir):
|
def test_markdown_with_custom_charset(tmpdir):
|
||||||
path = tmpdir.join('file.md')
|
path = tmpdir.join('file.md')
|
||||||
path.write('\ta \t \n')
|
path.write('\ta \t \n')
|
||||||
ret = main([path.strpath, '--chars', ' ', '--markdown-linebreak-ext', '*'])
|
ret = main([str(path), '--chars', ' ', '--markdown-linebreak-ext', '*'])
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
assert path.read() == '\ta \t \n'
|
assert path.read() == '\ta \t \n'
|
||||||
|
|
Loading…
Reference in New Issue