def test_separate_async_optionals_two_exist(): """confirms that when two creation group classes have async dependencies the class that has shared item as a dependency occurs first in a separate creation group """ order = has_create.creation_order( has_create.optional_dependency_graph(Four, Three, Two)) assert has_create.separate_async_optionals(order) == [ set([One]), set([Two]), set([Three]), set([Four]) ]
def test_separate_async_optionals_not_has_create(): """confirms that when a dependency isn't a HasCreate has_create.separate_aysnc_optionals doesn't unnecessarily move it from the initial creation group """ order = has_create.creation_order( has_create.optional_dependency_graph(Seven, Six)) assert has_create.separate_async_optionals(order) == [ set([One, IsntAHasCreate]), set([Two, Seven]), set([Six]) ]
def test_creation_order_with_loop(): """confirms that `has_create.creation_order()` raises toposort.CircularDependencyError when evaluating a cyclic dependency graph """ dependency_graph = dict(eight=set(['seven', 'six']), seven=set(['five']), six=set(), five=set(['two', 'one']), four=set(['one']), three=set(['two']), two=set(['one']), one=set(['eight'])) with pytest.raises(CircularDependencyError): assert has_create.creation_order(dependency_graph)
def test_creation_order(): """confirms that `has_create.creation_order()` returns a valid creation order in the desired list of sets format""" dependency_graph = dict( eight=set(['seven', 'six']), seven=set(['five']), six=set(), five=set(['two', 'one']), four=set(['one']), three=set(['two']), two=set(['one']), one=set(), ) desired = [set(['one', 'six']), set(['two', 'four']), set(['three', 'five']), set(['seven']), set(['eight'])] assert has_create.creation_order(dependency_graph) == desired
def test_separate_async_optionals_none_exist(): """confirms that when creation group classes have no async optional dependencies the order is unchanged""" order = has_create.creation_order( has_create.optional_dependency_graph(Three, Two, One)) assert has_create.separate_async_optionals(order) == order