-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
consistency check between components and models added
- Loading branch information
Showing
4 changed files
with
100 additions
and
30 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
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 |
---|---|---|
@@ -1,19 +1,63 @@ | ||
from pathlib import Path | ||
|
||
from andromede.study.parsing import parse_yaml_components | ||
from andromede.study.resolve_components import resolve_components_and_cnx | ||
import pytest | ||
|
||
from andromede.model.parsing import InputLibrary, parse_yaml_library | ||
from andromede.model.resolve_library import resolve_library | ||
from andromede.study.parsing import ( | ||
InputComponent, | ||
InputComponents, | ||
parse_yaml_components, | ||
) | ||
from andromede.study.resolve_components import ( | ||
consistency_check, | ||
resolve_components_and_cnx, | ||
) | ||
|
||
def test_parsing_components_ok(data_dir: Path): | ||
|
||
@pytest.fixture | ||
def input_component( | ||
data_dir: Path, | ||
) -> InputComponents: | ||
compo_file = data_dir / "components.yml" | ||
|
||
with compo_file.open() as c: | ||
input_compo = parse_yaml_components(c) | ||
assert len(input_compo.components) == 2 | ||
assert len(input_compo.nodes) == 1 | ||
assert len(input_compo.connections) == 2 | ||
return parse_yaml_components(c) | ||
|
||
|
||
@pytest.fixture | ||
def input_library( | ||
data_dir: Path, | ||
) -> InputLibrary: | ||
library = data_dir / "lib.yml" | ||
|
||
with library.open() as lib: | ||
return parse_yaml_library(lib) | ||
|
||
|
||
result = resolve_components_and_cnx(input_compo) | ||
def test_parsing_components_ok(input_component): | ||
assert len(input_component.components) == 2 | ||
assert len(input_component.nodes) == 1 | ||
assert len(input_component.connections) == 2 | ||
|
||
result = resolve_components_and_cnx(input_component) | ||
|
||
assert len(result.components) == 3 | ||
assert len(result.connections) == 2 | ||
|
||
|
||
def test_consistency_check_ok(input_component, input_library): | ||
result_comp = resolve_components_and_cnx(input_component) | ||
result_lib = resolve_library(input_library) | ||
consistency_check(result_comp.components, result_lib.models) | ||
|
||
|
||
def test_consistency_check_ko(input_component, input_library): | ||
result_comp = resolve_components_and_cnx(input_component) | ||
result_lib = resolve_library(input_library) | ||
result_lib.models.pop("generator") | ||
with pytest.raises( | ||
ValueError, | ||
match=r"Error: Component G has invalid model ID: generator", | ||
): | ||
consistency_check(result_comp.components, result_lib.models) |