def test_fix_failing_check_no_changes(file_config_files, capfd): autofix_lib.fix( ( str(file_config_files.output_dir.join('repo1')), str(file_config_files.output_dir.join('repo2')), ), apply_fix=lower_case_f, check_fix=failing_check_fix, config=load_config(file_config_files.cfg), commit=autofix_lib.Commit('message!', 'test-branch', None), autofix_settings=autofix_lib.AutofixSettings( jobs=1, color=False, limit=None, dry_run=False, interactive=False, ), ) out, err = capfd.readouterr() assert 'nope!' in err assert out.count('Errored') == 2 # An error while checking should not allow the changes assert file_config_files.dir1.join('f').read() == 'OHAI\n' assert file_config_files.dir2.join('f').read() == 'OHELLO\n'
def test_fix_dry_run_no_change(file_config_files, capfd): autofix_lib.fix( ( str(file_config_files.output_dir.join('repo1')), str(file_config_files.output_dir.join('repo2')), ), apply_fix=lower_case_f, config=load_config(file_config_files.cfg), commit=autofix_lib.Commit('message!', 'test-branch', None), autofix_settings=autofix_lib.AutofixSettings( jobs=1, color=False, limit=None, dry_run=True, interactive=False, ), ) out, err = capfd.readouterr() assert err == '' assert 'Errored' not in out # Showed the diff of what would have happened assert '-OHAI\n+ohai\n' in out assert '-OHELLO\n+ohello\n' in out # Didn't actually perform any changes assert file_config_files.dir1.join('f').read() == 'OHAI\n' assert file_config_files.dir2.join('f').read() == 'OHELLO\n'
def test_autofix_makes_commits(file_config_files, capfd): autofix_lib.fix( ( str(file_config_files.output_dir.join('repo1')), str(file_config_files.output_dir.join('repo2')), ), apply_fix=lower_case_f, config=load_config(file_config_files.cfg), commit=autofix_lib.Commit('message!', 'test-branch', 'A B <[email protected]>'), autofix_settings=autofix_lib.AutofixSettings( jobs=1, color=False, limit=None, dry_run=False, interactive=False, ), ) out, err = capfd.readouterr() assert err == '' assert 'Errored' not in out assert file_config_files.dir1.join('f').read() == 'ohai\n' assert file_config_files.dir2.join('f').read() == 'ohello\n' # The branch name should be what we specified last_commit_msg = subprocess.check_output(( 'git', '-C', file_config_files.dir1, 'log', '--format=%s', '--first-parent', '-1', )).strip().decode() potential_msgs = testing.git.merge_msgs('all-repos_autofix_test-branch') assert last_commit_msg in potential_msgs # We should see a commit from the autofix change we made commit = subprocess.check_output(( 'git', '-C', file_config_files.dir1, 'log', '--patch', '--grep', 'message!', '--format=%an %ae\n%B', )).decode() assert commit.startswith( 'A B [email protected]\n' 'message!\n' '\n' 'Committed via https://github.com/asottile/all-repos\n', ) assert commit.endswith('-OHAI\n+ohai\n')
def test_fix_non_default_branch(file_config_non_default): clone.main(('--config-filename', str(file_config_non_default.cfg))) autofix_lib.fix( (str(file_config_non_default.output_dir.join('repo1')), ), apply_fix=lower_case_f, config=load_config(file_config_non_default.cfg), commit=autofix_lib.Commit('message!', 'test-branch', 'A B <[email protected]>'), autofix_settings=autofix_lib.AutofixSettings( jobs=1, color=False, limit=None, dry_run=False, interactive=False, ), ) assert file_config_non_default.dir1.join('f').read() == 'ohai\n'
def test_fix_interactive(file_config_files, capfd, mock_input): mock_input.set_side_effect('y', 'n') autofix_lib.fix( ( str(file_config_files.output_dir.join('repo1')), str(file_config_files.output_dir.join('repo2')), ), apply_fix=lower_case_f, config=load_config(file_config_files.cfg), commit=autofix_lib.Commit('message!', 'test-branch', None), autofix_settings=autofix_lib.AutofixSettings( jobs=1, color=False, limit=None, dry_run=False, interactive=True, ), ) assert file_config_files.dir1.join('f').read() == 'ohai\n' assert file_config_files.dir2.join('f').read() == 'OHELLO\n'
def test_noop_does_not_commit(file_config_files, capfd): rev_before1 = testing.git.revparse(file_config_files.dir1) rev_before2 = testing.git.revparse(file_config_files.dir2) autofix_lib.fix( ( str(file_config_files.output_dir.join('repo1')), str(file_config_files.output_dir.join('repo2')), ), apply_fix=lambda: None, config=load_config(file_config_files.cfg), commit=autofix_lib.Commit('message!', 'test-branch', None), autofix_settings=autofix_lib.AutofixSettings( jobs=1, color=False, limit=None, dry_run=False, interactive=False, ), ) rev_after1 = testing.git.revparse(file_config_files.dir1) rev_after2 = testing.git.revparse(file_config_files.dir2) assert (rev_before1, rev_before2) == (rev_after1, rev_after2)
def test_fix_with_limit(file_config_files, capfd): autofix_lib.fix( ( str(file_config_files.output_dir.join('repo1')), str(file_config_files.output_dir.join('repo2')), ), apply_fix=lower_case_f, config=load_config(file_config_files.cfg), commit=autofix_lib.Commit('message!', 'test-branch', None), autofix_settings=autofix_lib.AutofixSettings( jobs=1, color=False, limit=1, dry_run=True, interactive=False, ), ) out, err = capfd.readouterr() assert err == '' assert 'Errored' not in out # Should still see the diff from the first repository assert '-OHAI\n+ohai\n' in out assert '-OHELLO\n+ohello\n' not in out