Ejemplo n.º 1
0
def test_failed_task():
    from jug.jug import execution_loop
    from jug.task import alltasks
    from jug.tests.jugfiles.exceptions import FailingTask
    options = parse(['execute'])
    options.jugfile = find_test_jugfile('failing.py')
    # keep_failed ensures errored tasks are marked as failed
    options.execute_keep_failed = True
    options.execute_target = None

    store, space = jug.jug.init(options.jugfile, 'dict_store')
    # the failing.py jugfile has a total of 20 reachable tasks
    assert len(alltasks) == 20
    # Keep a copy of all tasks to check for failed tasks later
    alltasks_copy = alltasks[:]

    try:
        execution_loop(alltasks, options)
    except FailingTask:  # Using a custom exception to make sure we don't silence any errors
        pass

    # The third task fails so we get 2 results and 1 failed lock
    # NOTE: This might be incorrect if order of execution is not guaranteed
    assert len(store.store) == 3
    # 10 tasks could be run and were taken. Only the 10 waiting remain
    assert len(alltasks) == 10
    assert len([x for x in alltasks_copy if x.is_failed()]) == 1
Ejemplo n.º 2
0
def test_failed_task_keep_going():
    from jug.jug import execution_loop
    from jug.task import alltasks
    options = parse(['execute'])
    options.jugfile = find_test_jugfile('failing.py')
    # these 3 silence errors during execution and ensure jug isn't kept waiting
    options.execute_keep_going = True
    options.execute_nr_wait_cycles = 1
    options.execute_wait_cycle_time = 0
    # keep_failed ensures errored tasks are marked as failed
    options.execute_keep_failed = True

    options.execute_target = None
    store, space = jug.jug.init(options.jugfile, 'dict_store')
    # the failing.py jugfile has a total of 20 reachable tasks
    assert len(alltasks) == 20
    # Keep a copy of all tasks to check for failed tasks later
    alltasks_copy = alltasks[:]

    execution_loop(alltasks, options)

    # 14 results + 3 failures
    assert len(store.store) == 17
    # 3 tasks should remain in waiting state due to 3 failures upstream
    assert len(alltasks) == 3
    assert len([x for x in alltasks_copy if x.is_failed()]) == 3
Ejemplo n.º 3
0
def test_aggressive_unload(jugfile):
    from jug.jug import execution_loop
    from jug.task import alltasks

    options = parse(['execute'])
    options.aggressive_unload = True
    options.execute_target = None
    store, space = jug.jug.init(find_test_jugfile(jugfile), 'dict_store')
    execution_loop(alltasks, options)
Ejemplo n.º 4
0
def test_target_wild():
    from jug.jug import execution_loop
    from jug.task import alltasks
    options = parse(['execute'])
    options.jugfile = find_test_jugfile('simple_multiple.py')
    # Test if restricting to this target we skip the other tasks
    options.execute_target = "simple_multiple.sum_"

    store, space = jug.jug.init(options.jugfile, 'dict_store')
    execution_loop(alltasks, options)

    assert len(store.store) < len(alltasks)
    assert len(store.store) == 16
Ejemplo n.º 5
0
    def test_options_cmdline(self):
        clear_default("hello_other_value")
        clear_default("hello_value")

        assert CMD not in cmdapi._commands

        HelloCommand()

        options = parse([CMD, "--value", "FooBar"])
        assert options.hello_value == "FooBar"
        assert options.hello_other_value == "undefined"

        output = cmdapi.run(CMD, options=options)
        assert output == "Hello world", "Got '{0}'".format(output)
Ejemplo n.º 6
0
    def test_options_cmdline(self):
        clear_default("hello_other_value")
        clear_default("hello_value")

        assert CMD not in cmdapi._commands

        HelloCommand()

        options = parse([CMD, "--value", "FooBar"])
        assert options.hello_value == "FooBar"
        assert options.hello_other_value == "undefined"

        output = cmdapi.run(CMD, options=options)
        assert output == "Hello world", "Got '{0}'".format(output)
Ejemplo n.º 7
0
    def test_options_config(self):
        "Test if settings read from config file work even for custom subcommands"

        _options_file = '''
[hello]
other-value=someone
'''

        clear_default("hello_other_value")
        clear_default("hello_value")

        cmd = HelloCommand()
        defaults = cmd.parse_defaults()
        assert defaults["hello_other_value"] == "undefined"
        assert defaults["hello_value"] == "option"

        options = parse([CMD], StringIO(_options_file))

        assert options.hello_other_value == "someone"
        assert options.hello_value == "option"
Ejemplo n.º 8
0
    def test_options_config(self):
        "Test if settings read from config file work even for custom subcommands"

        _options_file = '''
[hello]
other-value=someone
'''

        clear_default("hello_other_value")
        clear_default("hello_value")

        cmd = HelloCommand()
        defaults = cmd.parse_defaults()
        assert defaults["hello_other_value"] == "undefined"
        assert defaults["hello_value"] == "option"

        options = parse([CMD], StringIO(_options_file))

        assert options.hello_other_value == "someone"
        assert options.hello_value == "option"
Ejemplo n.º 9
0
def test_sys_argv():
    payload = """
import json, sys
sys.stdout.write(json.dumps(sys.argv) + '\\n')
"""
    jugfile = tempfile.NamedTemporaryFile(suffix=".py")
    jugfile.write(payload.encode("utf8"))
    jugfile.flush()

    options = parse(["execute", jugfile.name, '--', '--noarg', 'here'])
    assert sys.argv[0] == jugfile.name

    store, space = init(jugfile.name, 'dict_store')

    with catch_stdout() as stdout:
        execute.run(options=options, store=store, jugspace=space)

    output = stdout.readline()
    args = json.loads(output)
    expected = [jugfile.name, "--noarg", "here"]
    assert args == expected, "Saw {}, expected {}".format(args, expected)
Ejemplo n.º 10
0
def test_sys_argv():
    payload = """
import json, sys
sys.stdout.write(json.dumps(sys.argv) + '\\n')
"""
    jugfile = tempfile.NamedTemporaryFile(suffix=".py")
    jugfile.write(payload.encode("utf8"))
    jugfile.flush()

    options = parse(["execute", jugfile.name, '--', '--noarg', 'here'])
    assert sys.argv[0] == jugfile.name

    store, space = init(jugfile.name, 'dict_store')

    with catch_stdout() as stdout:
        execute.run(options=options, store=store, jugspace=space)

    output = stdout.readline()
    args = json.loads(output)
    expected = [jugfile.name, "--noarg", "here"]
    assert args == expected, "Saw {}, expected {}".format(args, expected)
Ejemplo n.º 11
0
def simple_execute():
    from jug.jug import execution_loop
    from jug.task import alltasks
    from jug.options import parse
    execution_loop(alltasks, parse(['execute']))