def test_added_file_not_in_pre_commits_list(temp_git_dir): with temp_git_dir.as_cwd(): temp_git_dir.join(REQUIRED_FILES[0]).write("print('hello world')") cmd_output('git', 'add', REQUIRED_FILES[0]) # Should pass even with a size of 0 assert check_added_plugin_files(['g.py']) == 0
def test_added_file_not_in_pre_commits_list(temp_git_dir): with temp_git_dir.as_cwd(): temp_git_dir.join("1.py").write(TEST_FILE_CONTENT) cmd_output('git', 'add', "1.py") # File not present assert main(['-i', 'g.py']) == 3
def test_adding_something(temp_git_dir): with temp_git_dir.as_cwd(): for test_file in REQUIRED_FILES: temp_git_dir.join(test_file).write("print('hello world')") cmd_output('git', 'add', test_file) assert check_added_plugin_files(REQUIRED_FILES) == 0
def test_adding_not_allowed(temp_git_dir): with temp_git_dir.as_cwd(): all_files = REQUIRED_FILES + NOT_ALLOWED_FILES for test_file in all_files: temp_git_dir.join(test_file).write("print('hello world')") cmd_output('git', 'add', test_file) assert check_added_plugin_files(all_files) >= 1
def temp_git_dir(tmpdir): global GIT_DIR GIT_DIR = tmpdir.join('gits') cmd_output('git', 'init', '--', GIT_DIR.strpath) try: yield GIT_DIR finally: clean_up()
def test_adding_something(temp_git_dir): with temp_git_dir.as_cwd(): test_files = [] for test_file in range(3): test_file_name = str(test_file) + ".py" temp_git_dir.join(test_file_name).write(TEST_FILE_CONTENT) cmd_output('git', 'add', test_file_name) test_files.append(test_file_name) assert main(argv=['-i'] + test_files) == 0
def test_moves_with_gitlfs(temp_git_dir): # pragma: no cover with temp_git_dir.as_cwd(): cmd_output('git', 'lfs', 'install') cmd_output('git', 'lfs', 'track', 'a.tar', 'b.tar') # First add the file we're going to move temp_git_dir.join('a.tar').write('a' * 10000) cmd_output('git', 'add', '--', '.') cmd_output('git', 'commit', '--no-gpg-sign', '-am', 'foo') # Now move it and make sure the hook still succeeds cmd_output('git', 'mv', 'a.tar', 'b.tar') assert main(('b.tar', )) == 0
def test_integration(temp_git_dir): with temp_git_dir.as_cwd(): assert main(argv=[]) == 0 with temp_git_dir.as_cwd(): for test_file in REQUIRED_FILES: temp_git_dir.join(test_file).write("print('hello world')") cmd_output('git', 'add', test_file) # Should not fail with default assert main(argv=REQUIRED_FILES) == 3
def lfs_files(): try: # Introduced in git-lfs 2.2.0, first working in 2.2.1 lfs_ret = cmd_output('git', 'lfs', 'status', '--json') except CalledProcessError: # pragma: no cover (with git-lfs) lfs_ret = '{"files":{}}' return set(json.loads(lfs_ret)['files'])
def test_allows_gitlfs(temp_git_dir): # pragma: no cover with temp_git_dir.as_cwd(): cmd_output('git', 'lfs', 'install') temp_git_dir.join('f.py').write('a' * 10000) cmd_output('git', 'lfs', 'track', 'f.py') cmd_output('git', 'add', '--', '.') # Should succeed assert main(('f.py', )) == 0
def has_gitlfs(): output = cmd_output('git', 'lfs', retcode=None, stderr=subprocess.STDOUT) return 'git lfs status' in output