def test_resolve_complex(): explorer = Explorer() @explorer.add_function(provides=('x'), requires=('a',)) def x(a): pass @explorer.add_function(provides=('y'), requires=('x','m','n')) def y(x): pass @explorer.add_function(provides=('m','n'), requires=('y',)) def mn(y): pass with pytest.raises(RuntimeError) as e: funcs_to_call, all_requires = explorer._resolve_call(need=('y',), have=('a',)) assert 'circular' in str(e.value) assert 'provider' in str(e.value) funcs_to_call = explorer._resolve_call(need=('y',), have=('a', 'm', 'n')) print('comlex with amn', funcs_to_call) assert funcs_to_call == (y, x) funcs_to_call = explorer._resolve_call(need=('y',), have=('x', 'm', 'n')) print('comlex with xmn', funcs_to_call) assert (funcs_to_call) == (y, )
def test_resolve_linear(): explorer = Explorer() @explorer.add_function(provides=('y'), requires=('x',)) def y(x): pass @explorer.add_function(provides=('z',), requires=('y',)) def z(y): pass @explorer.add_function(provides=('k',), requires=('z',)) def k(z): pass funcs_to_call = explorer._resolve_call(need=('k',), have=('x',)) print('linear when have x', funcs_to_call) assert len(funcs_to_call) == 3 funcs_to_call = explorer._resolve_call(need=('k',), have=('y',)) print('linear when have y', funcs_to_call) assert len(funcs_to_call) == 2