コード例 #1
0
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
コード例 #2
0
ファイル: test_setuputils.py プロジェクト: jaraco/paver
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
コード例 #3
0
ファイル: test_tasks.py プロジェクト: BBBSnowball/paver
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
コード例 #4
0
ファイル: test_tasks.py プロジェクト: GitSullied/paver
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
コード例 #5
0
ファイル: test_tasks.py プロジェクト: swayf/paver
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
コード例 #6
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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
コード例 #7
0
ファイル: test_setuputils.py プロジェクト: jaraco/paver
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
コード例 #8
0
ファイル: test_setuputils.py プロジェクト: vamega/paver
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
コード例 #9
0
ファイル: test_setuputils.py プロジェクト: vamega/paver
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
コード例 #10
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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
コード例 #11
0
ファイル: test_tasks.py プロジェクト: swayf/paver
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
コード例 #12
0
ファイル: test_tasks.py プロジェクト: paver/paver
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
コード例 #13
0
ファイル: test_tasks.py プロジェクト: swayf/paver
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
コード例 #14
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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
コード例 #15
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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
コード例 #16
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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"
コード例 #17
0
ファイル: test_tasks.py プロジェクト: swayf/paver
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
コード例 #18
0
ファイル: test_tasks.py プロジェクト: swayf/paver
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"
コード例 #19
0
ファイル: test_tasks.py プロジェクト: paver/paver
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
コード例 #20
0
ファイル: test_setuputils.py プロジェクト: jaraco/paver
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
コード例 #21
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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"
コード例 #22
0
ファイル: test_setuputils.py プロジェクト: vamega/paver
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
コード例 #23
0
ファイル: test_tasks.py プロジェクト: swayf/paver
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"
コード例 #24
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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
コード例 #25
0
ファイル: test_tasks.py プロジェクト: swayf/paver
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"
コード例 #26
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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"
コード例 #27
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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'])
コード例 #28
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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())
コード例 #29
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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]
コード例 #30
0
ファイル: test_tasks.py プロジェクト: paver/paver
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())
コード例 #31
0
ファイル: test_tasks.py プロジェクト: paver/paver
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"])
コード例 #32
0
ファイル: test_setuputils.py プロジェクト: vamega/paver
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
コード例 #33
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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
コード例 #34
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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
コード例 #35
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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
コード例 #36
0
ファイル: test_setuputils.py プロジェクト: jaraco/paver
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
コード例 #37
0
ファイル: test_tasks.py プロジェクト: swayf/paver
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
コード例 #38
0
ファイル: test_tasks.py プロジェクト: swayf/paver
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
コード例 #39
0
ファイル: test_tasks.py プロジェクト: swayf/paver
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]
コード例 #40
0
ファイル: test_tasks.py プロジェクト: swayf/paver
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
コード例 #41
0
ファイル: test_tasks.py プロジェクト: swayf/paver
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 is 'foo'
        assert optarg2 is 'bar'

    env = _set_environment(t1=t1, t2=t2)
    tasks._process_commands(['t1', 't2'])
    assert t1.called
    assert t2.called
コード例 #42
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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
コード例 #43
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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
コード例 #44
0
ファイル: test_tasks.py プロジェクト: swayf/paver
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
コード例 #45
0
ファイル: test_tasks.py プロジェクト: swayf/paver
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'])
コード例 #46
0
ファイル: test_tasks.py プロジェクト: paver/paver
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
コード例 #47
0
ファイル: test_tasks.py プロジェクト: paver/paver
def test_setting_of_options_with_equals():
    @tasks.task
    def t1(options):
        assert options.foo == "1"
        assert not hasattr(options, "bar")

    @tasks.task
    def t2(options):
        assert options.foo == "1"
        assert options.bar == "2"

    environment = _set_environment(t1=t1, t2=t2)
    tasks._process_commands(["foo=1", "t1", "bar=2", "t2"])
    assert t1.called
    assert t2.called
コード例 #48
0
ファイル: test_tasks.py プロジェクト: swayf/paver
def test_setting_of_options_with_equals():
    @tasks.task
    def t1(options):
        assert options.foo == '1'
        assert not hasattr(options, 'bar')
    
    @tasks.task
    def t2(options):
        assert options.foo == '1'
        assert options.bar == '2'
    
    environment = _set_environment(t1=t1, t2=t2)
    tasks._process_commands(['foo=1', 't1', 'bar=2', 't2'])
    assert t1.called
    assert t2.called
コード例 #49
0
ファイル: test_tasks.py プロジェクト: swayf/paver
def test_depending_on_a_function_rather_than_task():
    def bar():
        pass

    @tasks.task
    @tasks.needs('bar')
    def foo():
        pass

    env = _set_environment(foo=foo, bar=bar)
    try:
        tasks._process_commands(['foo'])
        assert False, "Expected a BuildFailure when depending on something that is not a task."
    except tasks.BuildFailure:
        pass
コード例 #50
0
ファイル: test_tasks.py プロジェクト: swayf/paver
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"
コード例 #51
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
def test_depending_on_a_function_rather_than_task():
    def bar():
        pass

    @tasks.task
    @tasks.needs('bar')
    def foo():
        pass

    env = _set_environment(foo=foo, bar=bar)
    try:
        tasks._process_commands(['foo'])
        assert False, "Expected a BuildFailure when depending on something that is not a task."
    except tasks.BuildFailure:
        pass
コード例 #52
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
def test_setting_of_options_with_equals():
    @tasks.task
    def t1(options):
        assert options.foo == '1'
        assert not hasattr(options, 'bar')

    @tasks.task
    def t2(options):
        assert options.foo == '1'
        assert options.bar == '2'

    environment = _set_environment(t1=t1, t2=t2)
    tasks._process_commands(['foo=1', 't1', 'bar=2', 't2'])
    assert t1.called
    assert t2.called
コード例 #53
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
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"
コード例 #54
0
ファイル: test_tasks.py プロジェクト: spacefan/paver
def test_consume_args_and_options_trailing_options_not_passed():
    @tasks.task
    @tasks.cmdopts([
        ("foo=", "f", "Help for foo")
    ])
    @tasks.consume_args
    def t1(options):
        assert not hasattr(options, 'foo')
        assert not hasattr(options.t1, 'foo')
        assert options.args == ['abc', 'def', '--foo', '1']

    environment = _set_environment(t1=t1)
    tasks._process_commands([
        't1', 'abc', 'def', '--foo', '1',
    ])
    assert t1.called
コード例 #55
0
ファイル: test_tasks.py プロジェクト: spacefan/paver
def test_consume_args_and_options_conflict():
    @tasks.task
    @tasks.cmdopts([
        ("foo=", "f", "Help for foo")
    ])
    @tasks.consume_args
    def t1(options):
        assert options.foo == "1"
        assert options.t1.foo == "1"
        assert options.args == ['abc', 'def', '--foo', '2']

    environment = _set_environment(t1=t1)
    tasks._process_commands([
        't1', '--foo', '1', 'abc', 'def', '--foo', '2',
    ])
    assert t1.called
コード例 #56
0
ファイル: test_tasks.py プロジェクト: swayf/paver
def test_options_inherited_via_needs():
    @tasks.task
    @tasks.cmdopts([('foo=', 'f', "Foo!")])
    def t1(options):
        assert options.t1.foo == "1"
    
    @tasks.task
    @tasks.needs('t1')
    @tasks.cmdopts([('bar=', 'b', "Bar!")])
    def t2(options):
        assert options.t2.bar == '2'
        
    environment = _set_environment(t1=t1, t2=t2)
    tasks._process_commands("t2 --foo 1 -b 2".split())
    assert t1.called
    assert t2.called
コード例 #57
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
def test_options_inherited_via_needs():
    @tasks.task
    @tasks.cmdopts([('foo=', 'f', "Foo!")])
    def t1(options):
        assert options.t1.foo == "1"

    @tasks.task
    @tasks.needs('t1')
    @tasks.cmdopts([('bar=', 'b', "Bar!")])
    def t2(options):
        assert options.t2.bar == '2'

    environment = _set_environment(t1=t1, t2=t2)
    tasks._process_commands("t2 --foo 1 -b 2".split())
    assert t1.called
    assert t2.called
コード例 #58
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
def test_options_might_be_shared_both_way():
    @tasks.task
    @tasks.cmdopts([('foo=', 'f', "Foo!")], share_with=['t2'])
    def t1(options):
        assert options.t1.foo == "1"

    @tasks.task
    @tasks.needs('t1')
    @tasks.cmdopts([('foo=', 'f', "Foo!")], share_with=['t1'])
    def t2(options):
        assert options.t2.foo == "1"

    environment = _set_environment(t1=t1, t2=t2)

    tasks._process_commands("t2 -f 1".split())

    assert t1.called
    assert t2.called
コード例 #59
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
def test_dest_parameter_should_map_opt_to_property():
    from optparse import make_option as opt

    @tasks.task
    @tasks.cmdopts([opt('-f', '--force', dest='force')])
    def t1(options):
        assert options.force == '1'

    @tasks.task
    @tasks.cmdopts([opt('-f', '--force', dest='foo_force')])
    def t2(options):
        assert options.foo_force == '1'

    environment = _set_environment(t1=t1, t2=t2)
    tasks._process_commands("t1 -f 1".split())
    tasks._process_commands("t2 -f 1".split())
    assert t1.called
    assert t2.called
コード例 #60
0
ファイル: test_tasks.py プロジェクト: apilar/backup_tools
def test_exactly_same_parameters_must_be_specified_in_order_to_allow_sharing():
    @tasks.task
    @tasks.cmdopts([('foo=', 'f', "Foo!")])
    def t1(options):
        assert False

    @tasks.task
    @tasks.needs('t1')
    @tasks.cmdopts([('force=', 'f', "Force!")], share_with=['t1'])
    def t2(options):
        assert False

    environment = _set_environment(t1=t1, t2=t2)
    try:
        tasks._process_commands("t2 -f 1".split())
        assert False, "should have gotten a PavementError"
    except tasks.PavementError:
        pass