def test_decorator_incompatibility_on_task(): from fabric.decorators import task, hosts, runs_once, roles def foo(): return "foo" foo = task(foo) # since we aren't setting foo to be the newly decorated thing, its cool hosts('me@localhost')(foo) runs_once(foo) roles('www')(foo)
def test_runs_once_returns_same_value_each_run(): """ @runs_once memoizes return value of decorated func """ return_value = "foo" task = decorators.runs_once(fake_function().returns(return_value)) for i in range(2): eq_(task(), return_value)
def test_runs_once_runs_only_once(): """ @runs_once prevents decorated func from running >1 time """ func = fake_function(expect_call=True).times_called(1) task = decorators.runs_once(func) for i in range(2): task()
ops.run("mv ~/.pydistutils.cfg.disabled ~/.pydistutils.cfg") @require_role @task def rollover_project_link(): with ctx.cd('~/%s/%s' % (settings.deployment_dir, env.role)): ops.run('rm -f current && ln -s %s current' % prj.build_name) @task @require_role def fab(args='', role=None, version=None): "Run a remove fab command in the currently installed project's root." with ctx.cd("~/%s/%s/%s" % (settings.deployment_dir, env.role, version or 'current')): ops.run("fab environment:%s %s" % (role or env.role, args)) onefab = runs_once(fab) @task def shell(args="bash"): "Run command in a remote shell (in ./~)." with ctx.cd("~/"): ops.run(args) @task @require_role def sudoshell(args="bash"): "Sudo run command in a remote shell (in ./~)." with ctx.cd("~/"): ops.sudo(args) @runs_once
@task def rollover_project_link(): with ctx.cd('~/%s/%s' % (settings.deployment_dir, env.role)): ops.run('rm -f current && ln -s %s current' % prj.build_name) @task @require_role def fab(args='', role=None, version=None): "Run a remote fab command in the currently installed project's root." with ctx.cd("~/%s/%s/%s" % (settings.deployment_dir, env.role, version or 'current')): ops.run(".ve/bin/fab environment:%s %s" % (role or env.role, args)) onefab = runs_once(fab) @task def shell(args="bash"): "Run command in a remote shell (in ./~)." with ctx.cd("~/"): ops.run(args) @task @require_role def sudoshell(args="bash"): "Sudo run command in a remote shell (in ./~)." with ctx.cd("~/"): ops.sudo(args)