示例#1
0
def test_sync_error_raise_errors():
    # given
    dependencies = {'c': ['d'], 'd': []}
    funcs = {'d': d, 'c': c}

    # when
    graph = taskmap.create_graph(funcs, dependencies)
    with pytest.raises(RuntimeError, match='some error'):
        taskmap.run(graph, raise_errors=True)

    graph = taskmap.create_graph(funcs, dependencies)
    with pytest.raises(RuntimeError, match='some error'):
        taskmap.run_parallel(graph, raise_errors=True)
示例#2
0
def test_sync_error_handling():
    # given
    dependencies = {
        'c': ['d'],
        'd': [],
    }

    funcs = {
        'd': d,
        'c': c,
    }

    # when
    graph = taskmap.create_graph(funcs.copy(), dependencies.copy())
    graph = taskmap.run(graph)

    graph_parallel = taskmap.create_graph(funcs.copy(), dependencies.copy())
    graph_parallel = taskmap.run_parallel(graph, nprocs=2, sleep=.001)

    # then
    expected = {
        'd': error,
        'c': 'Ancestor task d failed; task not run',
    }
    assert graph.results['c'] == expected['c']
    assert graph.results['d'].__class__ == expected['d'].__class__
    assert graph.results['d'].args == expected['d'].args

    assert graph_parallel.results['c'] == expected['c']
    assert graph_parallel.results['d'].__class__ == expected['d'].__class__
    assert graph_parallel.results['d'].args == expected['d'].args
示例#3
0
def test_logging_filename_change():
    # given
    dependencies = {'a': []}
    funcs = {'a': a}
    name = 'test-taskmap-name'
    graph = taskmap.create_graph(funcs, dependencies, name=name,
                                 logging_config={'write': True})

    # when
    graph = taskmap.run(graph)

    # then
    assert any(name in f for f in os.listdir('./'))
示例#4
0
def test_cached_results_are_used():
    # given
    funcs = {'a': a, 'b': b}
    dependencies = {'b': ['a'], 'a': []}
    results = {'a': 5}

    graph = taskmap.create_graph(
        funcs, dependencies, done=['a'], results=results)

    # when
    graph = taskmap.run(graph)

    # then
    assert graph.results['b'] == 15
示例#5
0
def test_run_pass_args():
    # given
    dependencies = {
        'c': ['a', 'b'],
        'b': ['a'],
        'a': [],
    }

    funcs = {
        'a': a,
        'b': b,
        'c': c,
    }

    graph = taskmap.create_graph(funcs, dependencies)

    # when
    graph = taskmap.run(graph)

    # then
    assert graph.results == {'a': 5, 'b': 15, 'c': 40}