def init(ctx): """Initialize the project for use with EasyCI. This installs the necessary git hooks (pre-commit + pre-push) and add a config file if one does not already exists. """ # install hooks git = ctx.obj['vcs'] click.echo("Installing hooks...", nl=False) for old in ['commit-msg']: path = os.path.join(git.path, '.git/hooks', old) if os.path.exists(path): os.remove(path) for new in ['pre-commit', 'pre-push']: git.install_hook(new, hooks_manager.get_hook(new)) click.echo("Done.") # add a config file if one does not exist config_path = os.path.join(git.path, 'eci.yaml') if not os.path.exists(config_path): click.echo("Placing a trivial config file in your project...", nl=False) with open(config_path, 'w') as f: f.write( yaml.safe_dump({ 'tests': ['echo please modify to run your tests', 'true'] })) click.echo("Done.") # initialize lock locking.init(git) # update installed version click.echo("Updating installed version...", nl=False) set_installed_version(git, easyci.__version__) click.echo("Done.")
def test_init_simple(fake_vcs, runner, fake_hooks): with mock.patch('easyci.cli.GitVcs', new=lambda: fake_vcs): result = runner.invoke(cli, ['init']) assert result.exit_code == exit_codes.SUCCESS args = fake_vcs.install_hook.call_args_list calls = set() for pair in args: arg, _ = pair # only get positional arguments calls.add(arg) for hook in ['pre-push', 'pre-commit']: assert (hook, hooks_manager.get_hook(hook)) in calls
def test_get_hook(): assert get_hook('pre-commit') with pytest.raises(HookNotFoundError): get_hook('doesnotexist')