-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Component ordering based on dependencies (#250)
* Component ordering * Added component ordering * Documentation of the component sorting code * tests * Better sorting algorithm and tests * version bump
- Loading branch information
Showing
3 changed files
with
252 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from oarepo_runtime.services.components import _sort_components | ||
|
||
|
||
class FakeComponent: | ||
pass | ||
|
||
|
||
def make_component(name, depends_on=None, affects=None): | ||
fields = {} | ||
if depends_on: | ||
fields["depends_on"] = depends_on | ||
if affects: | ||
fields["affects"] = affects | ||
return type(name, (FakeComponent,), fields) | ||
|
||
|
||
def test_component_no_dependencies(): | ||
components = [ | ||
make_component("A"), | ||
make_component("B"), | ||
make_component("C"), | ||
make_component("D"), | ||
] | ||
assert _sort_components(components) == components | ||
|
||
|
||
def test_component_after_all(): | ||
components = [ | ||
make_component("A", depends_on=["*"]), | ||
make_component("B"), | ||
make_component("C"), | ||
make_component("D"), | ||
] | ||
assert [x.__name__ for x in _sort_components(components)] == ["B", "C", "D", "A"] | ||
|
||
|
||
def test_component_after_all_2(): | ||
components = [ | ||
make_component("A", depends_on="*"), | ||
make_component("B"), | ||
make_component("C"), | ||
make_component("D"), | ||
] | ||
assert [x.__name__ for x in _sort_components(components)] == ["B", "C", "D", "A"] | ||
|
||
|
||
def test_component_after_all_direct(): | ||
components = [ | ||
a := make_component("A", depends_on="*"), | ||
make_component("B", depends_on=[a]), | ||
make_component("C"), | ||
make_component("D"), | ||
] | ||
assert [x.__name__ for x in _sort_components(components)] == ["C", "D", "A", "B"] | ||
|
||
|
||
def test_component_before_all(): | ||
components = [ | ||
make_component("A"), | ||
make_component("B"), | ||
make_component("C"), | ||
make_component("D", affects=["*"]), | ||
] | ||
assert [x.__name__ for x in _sort_components(components)] == ["D", "A", "B", "C"] | ||
|
||
|
||
def test_component_before_all_direct(): | ||
components = [ | ||
make_component("A"), | ||
make_component("B"), | ||
make_component("C"), | ||
d := make_component("D", affects=["*"]), | ||
make_component("E", affects=[d]), | ||
] | ||
assert [x.__name__ for x in _sort_components(components)] == [ | ||
"E", | ||
"D", | ||
"A", | ||
"B", | ||
"C", | ||
] | ||
|
||
|
||
def test_component_in_between(): | ||
a = make_component("A") | ||
c = make_component("C") | ||
b = make_component("B", affects=[a], depends_on=[c]) | ||
components = [a, b, c] | ||
assert [x.__name__ for x in _sort_components(components)] == ["C", "B", "A"] |