def test_tasks_dont_repeat(): called = [0, 0, 0, 0] @tasks.task def t1(): assert called == [0, 0, 0, 0] called[0] += 1 @tasks.task @tasks.needs('t1') def t2(): assert called == [1, 0, 0, 0] called[1] += 1 @tasks.task @tasks.needs('t1') def t3(): assert called == [1, 1, 0, 0] called[2] += 1 @tasks.task @tasks.needs('t2', 't3') def t4(): assert called == [1, 1, 1, 0] called[3] += 1 _set_environment(t1=t1,t2=t2,t3=t3,t4=t4) t4() assert called == [1, 1, 1, 1]
def test_chained_dependencies(): called = [False, False, False, False] @tasks.task def t1(): assert called == [False, False, False, False] called[0] = True @tasks.task @tasks.needs('t1') def t2(): assert called == [True, False, False, False] called[1] = True @tasks.task def t3(): assert called == [True, True, False, False] called[2] = True @tasks.task @tasks.needs('t2', 't3') def t4(): assert called == [True, True, True, False] called[3] = True _set_environment(t1=t1,t2=t2,t3=t3,t4=t4) t4() assert called == [True, True, True, True], "Called was: %s" % (called)
def test_environment_insertion(): @tasks.task def t1(env): pass _set_environment(t1=t1) t1() assert t1.called
def test_list_tasks(): from paver import doctools @tasks.task def t1(): pass _set_environment(t1=t1, doctools=doctools) task_list = tasks.environment.get_tasks() assert t1 in task_list assert doctools.html in task_list
def test_longname_resolution_in_dependencies(): global_t1.called = False global_t1.t2_was_called = False @tasks.task @tasks.needs('paver.tests.test_tasks.global_t1') def t2(): assert global_t1.called global_t1.t2_was_called = True _set_environment(t2=t2) t2() assert global_t1.t2_was_called
def test_alternate_pavement_option(): env = _set_environment() tasks._parse_global_options([]) assert env.pavement_file == 'pavement.py' env = _set_environment() tasks._parse_global_options(['--file=foo.py']) set_pavement = env.pavement_file assert set_pavement == 'foo.py' env = _set_environment() tasks._parse_global_options(['-f', 'foo.py']) set_pavement = env.pavement_file assert set_pavement == 'foo.py'
def test_auto_task_is_run_when_present(): @tasks.task def t1(): pass @tasks.task def auto(): pass _set_environment(auto=auto, t1=t1) tasks._process_commands(['t1'], auto_pending=True) assert t1.called assert auto.called
def test_alternate_pavement_option(): env = _set_environment() tasks._parse_global_options([]) assert env.pavement_file == "pavement.py" env = _set_environment() tasks._parse_global_options(["--file=foo.py"]) set_pavement = env.pavement_file assert set_pavement == "foo.py" env = _set_environment() tasks._parse_global_options(["-f", "foo.py"]) set_pavement = env.pavement_file assert set_pavement == "foo.py"
def test_auto_task_is_not_run_with_noauto(): @tasks.no_auto @tasks.task def t1(): pass @tasks.task def auto(): pass _set_environment(auto=auto, t1=t1) tasks._process_commands(['t1'], auto_pending=True) assert t1.called assert not auto.called, "t1 is decorated with no_auto, it should not be called"
def test_task_with_distutils_dep(): _sdist.reset() @tasks.task @tasks.needs("paver.tests.test_setuputils.sdist") def sdist(): assert _sdist.called env = _set_environment(sdist=sdist) env.options = options.Bunch(setup=options.Bunch()) install_distutils_tasks() d = _get_distribution() d.cmdclass['sdist'] = _sdist task_obj = env.get_task('sdist') assert task_obj == sdist needs_obj = env.get_task(task_obj.needs[0]) assert isinstance(needs_obj, DistutilsTask) assert needs_obj.command_class == _sdist tasks._process_commands(['sdist', "-f"]) assert sdist.called assert _sdist.called cmd = d.get_command_obj('sdist') print_("Cmd is: %s" % cmd) assert cmd.foo assert _sdist.foo_set
def test_needs_sdist_without_options(): """Test that a custom sdist can be used in needs() w/o options.setup""" _sdist.reset() @tasks.task @tasks.needs("paver.tests.test_setuputils.sdist") def sdist(): assert _sdist.called @tasks.task @tasks.needs("sdist") def t1(): pass env = _set_environment(sdist=sdist, t1=t1) env.options = options.Bunch() install_distutils_tasks() d = _get_distribution() d.cmdclass['sdist'] = _sdist tasks._process_commands(['t1']) assert sdist.called assert _sdist.called assert t1.called cmd = d.get_command_obj('sdist') assert not cmd.foo assert not _sdist.foo_set
def test_consume_nargs_and_options(): from optparse import make_option @tasks.task @tasks.consume_nargs(2) @tasks.cmdopts([make_option("-f", "--foo", help="foo")]) def t1(options): assert options.foo == "1" assert options.t1.foo == "1" assert options.args == ['abc', 'def'] @tasks.task @tasks.consume_nargs(2) @tasks.cmdopts([make_option("-f", "--foo", help="foo")]) def t2(options): assert options.foo == "2" assert options.t2.foo == "2" assert options.args == ['ghi', 'jkl'] environment = _set_environment(t1=t1, t2=t2) tasks._process_commands([ 't1', '--foo', '1', 'abc', 'def', 't2', '--foo', '2', 'ghi', 'jkl', ]) assert t1.called
def test_options_in_option_group_are_available_to_all_tasks(): tasks.register_cmdoptsgroup("abc", ('foo=', 'f', "Foo!"), ('bar=', 'b', "Bar!")) @tasks.task @tasks.cmdoptsgroup("abc") def task1(options): foo = options.task1.foo bar = options.task1.bar assert foo == "1" and bar == "2" @tasks.task @tasks.needs("task1", "task3") @tasks.cmdoptsgroup("abc") def task2(options): foo = options.task2.foo bar = options.task2.bar assert foo == "1" and bar == "2" @tasks.task @tasks.needs("task1") @tasks.cmdoptsgroup("abc") def task3(options): foo = options.task3.foo bar = options.task3.bar assert foo == "1" and bar == "2" environment = _set_environment(task1=task1, task2=task2, task3=task3) tasks._process_commands("task2 --foo 1 -b 2".split()) assert task1.called assert task2.called assert task3.called
def test_options_may_overlap_between_multiple_tasks_even_when_specified_in_reverse_order( ): @tasks.task @tasks.cmdopts([('foo=', 'f', "Foo!")], share_with=['t2', 't3']) def t1(options): assert options.t1.foo == "1" @tasks.task @tasks.needs('t1') @tasks.cmdopts([('foo=', 'f', "Foo!")]) def t2(options): assert options.t2.foo == "1" @tasks.task @tasks.needs('t1') @tasks.cmdopts([('foo=', 'f', "Foo!")]) def t3(options): assert options.t3.foo == "1" environment = _set_environment(t1=t1, t2=t2, t3=t3) tasks._process_commands("t2 -f 1".split()) assert t1.called assert t2.called tasks._process_commands("t3 -f 1".split()) assert t1.called assert t3.called
def test_consume_nargs_and_options(): from optparse import make_option @tasks.task @tasks.consume_nargs(2) @tasks.cmdopts([ make_option("-f", "--foo", help="foo") ]) def t1(options): assert options.foo == "1" assert options.t1.foo == "1" assert options.args == ['abc', 'def'] @tasks.task @tasks.consume_nargs(2) @tasks.cmdopts([ make_option("-f", "--foo", help="foo") ]) def t2(options): assert options.foo == "2" assert options.t2.foo == "2" assert options.args == ['ghi', 'jkl'] environment = _set_environment(t1=t1, t2=t2) tasks._process_commands([ 't1', '--foo', '1', 'abc', 'def', 't2', '--foo', '2', 'ghi', 'jkl', ]) assert t1.called
def test_options_may_overlap_between_multiple_tasks_even_when_specified_in_reverse_order(): @tasks.task @tasks.cmdopts([('foo=', 'f', "Foo!")], share_with=['t2', 't3']) def t1(options): assert options.t1.foo == "1" @tasks.task @tasks.needs('t1') @tasks.cmdopts([('foo=', 'f', "Foo!")]) def t2(options): assert options.t2.foo == "1" @tasks.task @tasks.needs('t1') @tasks.cmdopts([('foo=', 'f', "Foo!")]) def t3(options): assert options.t3.foo == "1" environment = _set_environment(t1=t1, t2=t2, t3=t3) tasks._process_commands("t2 -f 1".split()) assert t1.called assert t2.called tasks._process_commands("t3 -f 1".split()) assert t1.called assert t3.called
def test_task_finders(): env = _set_environment() mtf = MyTaskFinder() env.task_finders.append(mtf) t = env.get_task("foo") assert t == mtf.foo all_tasks = env.get_tasks() assert mtf.foo in all_tasks
def test_calling_task_with_option_arguments(): @tasks.task @tasks.cmdopts([('foo=', 'f', "Foo!")]) def t1(options): assert options.foo == 'true story' env = _set_environment(t1=t1) env.call_task('t1', options={'foo': 'true story'})
def test_calling_task_with_option_arguments(): @tasks.task @tasks.cmdopts([("foo=", "f", "Foo!")]) def t1(options): assert options.foo == "true story" env = _set_environment(t1=t1) env.call_task("t1", options={"foo": "true story"})
def test_basic_command_line(): @tasks.task def t1(): pass _set_environment(t1=t1) try: tr, args = tasks._parse_command_line(['foo']) print_(tr) assert False, "Expected BuildFailure exception for unknown task" except tasks.BuildFailure: pass task, args = tasks._parse_command_line(['t1']) assert task == t1 task, args = tasks._parse_command_line(['t1', 't2']) assert task == t1 assert args == ['t2']
def test_task_command_line_options(): @tasks.task @tasks.cmdopts([('foo=', 'f', 'Foobeedoobee!')]) def t1(options): assert options.foo == "1" assert options.t1.foo == "1" environment = _set_environment(t1=t1) tasks._process_commands(['t1', '--foo', '1']) assert t1.called
def test_longname_access(): environment = _set_environment(tasks=tasks) task = environment.get_task("paver.tasks.help") assert task is not None task = environment.get_task("nosuchmodule.nosuchtask") assert task is None task = environment.get_task("paver.tasks.nosuchtask") assert task is None
def test_basic_dependencies(): @tasks.task def t1(): pass t1.called = False t1.t2_was_called = False @tasks.task @tasks.needs('t1') def t2(): assert t1.called t1.t2_was_called = True _set_environment(t1 = t1, t2=t2) assert hasattr(tasks.environment.pavement, 't1') t2() assert t1.t2_was_called
def test_basic_dependencies(): @tasks.task def t1(): pass t1.called = False t1.t2_was_called = False @tasks.task @tasks.needs('t1') def t2(): assert t1.called t1.t2_was_called = True _set_environment(t1=t1, t2=t2) assert hasattr(tasks.environment.pavement, 't1') t2() assert t1.t2_was_called
def test_calling_a_function_rather_than_task(): def foo(): pass env = _set_environment(foo=foo) try: tasks._process_commands(['foo']) assert False, "Expected a BuildFailure when calling something that is not a task." except tasks.BuildFailure: pass
def test_task_command_line_options(): @tasks.task @tasks.cmdopts([("foo=", "f", "Foobeedoobee!")]) def t1(options): assert options.foo == "1" assert options.t1.foo == "1" environment = _set_environment(t1=t1) tasks._process_commands(["t1", "--foo", "1"]) assert t1.called
def test_distutils_task_finder(): env = _set_environment() env.options = options.Bunch(setup=options.Bunch()) dist = _get_distribution() dutf = DistutilsTaskFinder() task = dutf.get_task('distutils.command.install') assert task task = dutf.get_task('install') assert task task = dutf.get_task('foo') assert task is None
def test_calling_task_with_option_arguments(): @tasks.task @tasks.cmdopts([('foo=', 'f', "Foo!")]) def t1(options): assert options.foo == 'true story' env = _set_environment(t1=t1) env.call_task('t1', options={ 'foo' : 'true story' })
def test_base_logging(): @tasks.task def t1(info): info("Hi %s", "you") env = _set_environment(t1=t1, patch_print=True) tasks._process_commands(['t1']) assert env.patch_captured[-1] == 'Hi you' env.patch_captured = [] tasks._process_commands(['-q', 't1']) assert not env.patch_captured
def test_debug_logging(): @tasks.task def t1(debug): debug("Hi %s", "there") env = _set_environment(t1=t1, patch_print=True) tasks._process_commands(['-v', 't1']) assert env.patch_captured[-1] == "Hi there" env.patch_captured = [] tasks._process_commands(['t1']) assert env.patch_captured[-1] != "Hi there"
def test_messages_with_formatting_and_no_args_still_work(): @tasks.task def t1(error): error("This is a %s message") env = _set_environment(t1=t1, patch_print=True) tasks._process_commands(['t1']) assert env.patch_captured[-1] == "This is a %s message" env.patch_captured = [] tasks._process_commands(['-q', 't1']) assert env.patch_captured[-1] == "This is a %s message"
def test_error_show_up_no_matter_what(): @tasks.task def t1(error): error("Hi %s", "error") env = _set_environment(t1=t1, patch_print=True) tasks._process_commands(['t1']) assert env.patch_captured[-1] == "Hi error" env.patch_captured = [] tasks._process_commands(['-q', 't1']) assert env.patch_captured[-1] == "Hi error"
def test_negative_opts_handled_for_distutils(): _sdist.reset() env = _set_environment() env.options = options.Bunch(setup=options.Bunch()) install_distutils_tasks() d = _get_distribution() d.cmdclass['sdist'] = _sdist_with_default_foo tasks._process_commands(['sdist', '--no-foo']) assert _sdist.called assert not _sdist.foo_set
def test_options_passed_to_task(): from optparse import make_option @tasks.task @tasks.cmdopts([make_option("-f", "--foo", help="foo")]) def t1(options): assert options.foo == "1" assert options.t1.foo == "1" environment = _set_environment(t1=t1) tasks._process_commands(['t1', '--foo', '1']) assert t1.called
def test_options_passed_to_task(): from optparse import make_option @tasks.task @tasks.cmdopts([make_option("-f", "--foo", help="foo")]) def t1(options): assert options.foo == "1" assert options.t1.foo == "1" environment = _set_environment(t1=t1) tasks._process_commands(["t1", "--foo", "1"]) assert t1.called
def test_all_messages_for_a_task_are_captured(): @tasks.task def t1(debug, error): debug("This is debug msg") error("This is error msg") raise tasks.BuildFailure("Yo, problem, yo") env = _set_environment(t1=t1, patch_print=True) try: tasks._process_commands(['t1']) except FakeExitException: assert "This is debug msg" in "\n".join(env.patch_captured) assert env.exit_code == 1
def test_captured_output_shows_up_on_exception(): @tasks.task def t1(debug, error): debug("Dividing by zero!") 1 / 0 env = _set_environment(t1=t1, patch_print=True, patch_exit=1) try: tasks._process_commands(['t1']) assert False and "Expecting FakeExitException" except FakeExitException: assert "Dividing by zero!" in "\n".join(env.patch_captured) assert env.exit_code == 1
def test_calling_subpavement(): @tasks.task def private_t1(options): options.foo = 2 tasks.call_pavement(subpavement, "t1") # our options should not be mangled assert options.foo == 2 env = _set_environment(private_t1=private_t1) tasks._process_commands(['private_t1']) # the value should be set by the other pavement, which runs # in the same process assert OP_T1_CALLED == 1
def test_task_can_be_called_repeatedly(): @tasks.consume_args @tasks.task def t1(options, info): info(options.args[0]) env = _set_environment(t1=t1, patch_print=True) tasks._process_commands(['t1', 'spam']) tasks._process_commands(['t1', 'eggs']) assert 'eggs' == env.patch_captured[~0] assert 'spam' == env.patch_captured[~2]
def test_options_might_be_provided_if_task_might_be_called(): @tasks.task @tasks.cmdopts([('foo=', 'f', "Foo!")]) def t1(options): assert options.foo == "YOUHAVEBEENFOOD" @tasks.task @tasks.might_call('t1') def t2(options): pass environment = _set_environment(t1=t1, t2=t2) tasks._process_commands("t2 -f YOUHAVEBEENFOOD".split())
def test_calling_task_with_arguments(): @tasks.task @tasks.consume_args def t2(args): assert args[0] == 'SOPA' @tasks.task def t1(options): env.call_task('t2', args=['SOPA']) env = _set_environment(t1=t1, t2=t2) tasks._process_commands(['t1'])
def test_distutils_tasks_should_not_get_extra_options(): _sdist.reset() env = _set_environment() env.options = options.Bunch(setup=options.Bunch()) install_distutils_tasks() d = _get_distribution() d.cmdclass['sdist'] = _sdist tasks._process_commands(['sdist']) assert _sdist.called assert not _sdist.foo_set opts = d.get_option_dict('sdist') assert 'foo' not in opts
def test_consume_args(): @tasks.task @tasks.consume_args def t1(options): assert options.args == ["1", "t2", "3"] @tasks.task def t2(options): assert False, "Should not have run t2 because of consume_args" env = _set_environment(t1=t1, t2=t2) tasks._process_commands("t1 1 t2 3".split()) assert t1.called @tasks.task @tasks.consume_args def t3(options): assert options.args[0] == '-v' assert options.args[1] == '1' env = _set_environment(t3=t3) tasks._process_commands("t3 -v 1".split()) assert t3.called
def test_optional_args_in_tasks(): @tasks.task def t1(options, optarg=None): assert optarg is None @tasks.task def t2(options, optarg1='foo', optarg2='bar'): assert optarg1 == 'foo' assert optarg2 == 'bar' env = _set_environment(t1=t1, t2=t2) tasks._process_commands(['t1', 't2']) assert t1.called assert t2.called