def test_async_speed(): # given funcs = {'x': x, 'y': y} dependencies = {'x': [], 'y': []} graph = taskmap.create_graph(funcs, dependencies) # when start = time.time() taskmap.run_async(graph, sleep=0.001) end = time.time() # then assert end - start < .8
def test_async_error_raise_errors(): # given funcs = {'e': e, 'control': control} dependencies = {'e': [], 'control': []} # when graph = taskmap.create_graph(funcs, dependencies) with pytest.raises(RuntimeError, match='check your logs'): taskmap.run_async(graph, raise_errors=True) graph = taskmap.create_graph(funcs, dependencies) with pytest.raises(RuntimeError, match='check your logs'): taskmap.run_parallel_async(graph, raise_errors=True)
def test_run_async(): # given dependencies = { 'ac': ['along_task', 'ab'], 'ab': ['along_task'], 'along_task': [], } funcs = { 'along_task': along_task, 'ab': ab, 'ac': ac, } graph = taskmap.create_graph(funcs, dependencies) # when graph = taskmap.run_async(graph, sleep=0.001) # then assert graph.results == {'along_task': 5, 'ab': 15, 'ac': 40}
def test_async_error_handling(): # given dependencies = { 'c': ['e'], 'e': [], 'control': [], } funcs = { 'e': e, 'c': c, 'control': control, } # when graph = taskmap.create_graph(funcs.copy(), dependencies.copy()) graph = taskmap.run_async(graph, sleep=.001) graph_parallel = taskmap.create_graph(funcs.copy(), dependencies.copy()) graph_parallel = taskmap.run_parallel_async(graph_parallel, nprocs=2, sleep=.001) # then expected = { 'e': error, 'control': 5, 'c': 'Ancestor task e failed; task not run', } assert graph.results['c'] == expected['c'] assert graph.results['e'].__class__ == expected['e'].__class__ assert graph.results['e'].args == expected['e'].args assert graph.results['control'] == 5 assert graph_parallel.results['c'] == expected['c'] assert graph_parallel.results['e'].__class__ == expected['e'].__class__ assert graph_parallel.results['e'].args == expected['e'].args assert graph.results['control'] == 5