Skip to content

Commit

Permalink
feat: linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
andoludo committed Aug 31, 2024
1 parent 7dc81e8 commit e847628
Show file tree
Hide file tree
Showing 26 changed files with 191 additions and 198 deletions.
68 changes: 44 additions & 24 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@
)
from tests.fixtures.three_spaces import three_spaces
from tests.fixtures.two_spaces import two_spaces
from trano.library.library import Library
from trano.elements.types import Tilt, Azimuth, Flow
from trano.elements import Port, param_from_config
from trano.elements import (
ExternalWall,
FloorOnGround,
InternalElement,
Port,
Window,
param_from_config,
)
from trano.elements.boundary import Boundary
from trano.elements.control import (
AhuControl,
Expand All @@ -40,12 +45,6 @@
EmissionControl,
ThreeWayValveControl,
)
from trano.elements import (
ExternalWall,
FloorOnGround,
InternalElement,
Window,
)
from trano.elements.space import Space
from trano.elements.system import (
AirHandlingUnit,
Expand All @@ -59,6 +58,8 @@
ThreeWayValve,
Weather,
)
from trano.elements.types import Azimuth, Flow, Tilt
from trano.library.library import Library
from trano.topology import Network

OVERWRITE_MODELS = False
Expand Down Expand Up @@ -90,15 +91,19 @@ def simple_space_1() -> Space:
def simple_space_1_with_occupancy() -> Space:
return simple_space_1_with_occupancy_fixture()


@pytest.fixture
def buildings_library() -> Library:
buildings = Library.from_configuration("Buildings")
buildings.constants = """package Medium = Buildings.Media.Air(extraPropertiesNames={"CO2"}) "Medium model";
package MediumW = Buildings.Media.Water "Medium model";"""
return buildings


@pytest.fixture
def buildings_free_float_single_zone(simple_space_1_with_occupancy: Space, buildings_library) -> Network:
def buildings_free_float_single_zone(
simple_space_1_with_occupancy: Space, buildings_library: Library
) -> Network:
network = Network(
name="buildings_free_float_single_zone",
library=buildings_library,
Expand All @@ -110,20 +115,18 @@ def buildings_free_float_single_zone(simple_space_1_with_occupancy: Space, build
@pytest.fixture
def ideas_free_float_single_zone(simple_space_1: Space) -> Network:
ideas = Library.from_configuration("IDEAS")
ideas.constants ="""
ideas.constants = """
replaceable package Medium = IDEAS.Media.Air(extraPropertiesNames={"CO2"})
constrainedby Modelica.Media.Interfaces.PartialMedium
"Medium in the component"
annotation (choicesAllMatching = true);"""
network = Network(
name="ideas_free_float_single_zone",
library=ideas)
network = Network(name="ideas_free_float_single_zone", library=ideas)
network.add_boiler_plate_spaces([simple_space_1])
return network


@pytest.fixture
def buildings_free_float_two_zones(buildings_library) -> Network:
def buildings_free_float_two_zones(buildings_library: Library) -> Network:

network = Network(
name="buildings_free_float_two_zones",
Expand All @@ -146,7 +149,7 @@ def ideas_free_float_three_zones_spaces() -> list:

@pytest.fixture
def buildings_free_float_three_zones(
buildings_free_float_three_zones_spaces: list,buildings_library
buildings_free_float_three_zones_spaces: list, buildings_library: Library
) -> Network:
network = Network(
name="buildings_free_float_three_zones",
Expand Down Expand Up @@ -323,7 +326,10 @@ def buildings_simple_hydronic_three_zones(
def ideas_simple_hydronic_three_zones(
space_1: Space, space_2: Space, space_3: Space
) -> Network:
network = Network(name="ideas_simple_hydronic_three_zones", library=Library.from_configuration("IDEAS"))
network = Network(
name="ideas_simple_hydronic_three_zones",
library=Library.from_configuration("IDEAS"),
)
network.add_boiler_plate_spaces([space_1, space_2, space_3])

pump = Pump(name="pump", control=CollectorControl(name="pump_control"))
Expand Down Expand Up @@ -380,7 +386,10 @@ def space_1_no_occupancy() -> Space:

@pytest.fixture
def ideas_simple_hydronic_no_occupancy(space_1_no_occupancy: Space) -> Network:
network = Network(name="ideas_simple_hydronic_no_occupancy", library=Library.from_configuration("IDEAS"))
network = Network(
name="ideas_simple_hydronic_no_occupancy",
library=Library.from_configuration("IDEAS"),
)
network.add_boiler_plate_spaces([space_1_no_occupancy])

pump = Pump(name="pump", control=CollectorControl(name="pump_control"))
Expand Down Expand Up @@ -522,7 +531,9 @@ def ideas_many_spaces_simple_ventilation(

@pytest.fixture
def many_spaces_simple_ventilation(
space_1_simple_ventilation: Space, space_2_simple_ventilation: Space, buildings_library
space_1_simple_ventilation: Space,
space_2_simple_ventilation: Space,
buildings_library: Library,
) -> Network:
network = Network(
name="many_spaces_simple_ventilation",
Expand Down Expand Up @@ -552,14 +563,17 @@ def many_spaces_simple_ventilation(
def space_1_different_construction_types_network(
space_1_different_construction_types: Space,
) -> Network:
network = Network(name="space_1_different_construction_types", library=Library.from_configuration("IDEAS"))
network = Network(
name="space_1_different_construction_types",
library=Library.from_configuration("IDEAS"),
)
network.add_boiler_plate_spaces([space_1_different_construction_types])
return network


@pytest.fixture
def buildings_free_float_single_zone_ahu_complex(
space_1_simple_ventilation: Space,buildings_library
space_1_simple_ventilation: Space, buildings_library: Library
) -> Network:
network = Network(
name="buildings_free_float_single_zone_ahu_complex",
Expand Down Expand Up @@ -643,7 +657,9 @@ def space_1_simple_ventilation_vav_control() -> Space:


@pytest.fixture
def vav_ventilation_control(space_1_simple_ventilation_vav_control: Space, buildings_library) -> Network:
def vav_ventilation_control(
space_1_simple_ventilation_vav_control: Space, buildings_library: Library
) -> Network:
network = Network(
name="vav_ventilation_control",
library=buildings_library,
Expand All @@ -662,7 +678,9 @@ def vav_ventilation_control(space_1_simple_ventilation_vav_control: Space, build


@pytest.fixture
def one_spaces_air_handling_unit(space_1_simple_ventilation: Space, buildings_library) -> Network:
def one_spaces_air_handling_unit(
space_1_simple_ventilation: Space, buildings_library: Library
) -> Network:

network = Network(
name="one_spaces_air_handling_unit",
Expand All @@ -685,7 +703,9 @@ def one_spaces_air_handling_unit(space_1_simple_ventilation: Space, buildings_li

@pytest.fixture
def two_spaces_air_handling_unit(
space_1_simple_ventilation: Space, space_2_simple_ventilation: Space, buildings_library
space_1_simple_ventilation: Space,
space_2_simple_ventilation: Space,
buildings_library: Library,
) -> Network:

network = Network(
Expand Down
11 changes: 10 additions & 1 deletion tests/constructions/constructions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
from trano.elements.construction import Construction, Layer, GlassLayer, GasLayer, Glass, Material, GlassMaterial, Gas
from trano.elements.construction import (
Construction,
Gas,
GasLayer,
Glass,
GlassLayer,
GlassMaterial,
Layer,
Material,
)


class Materials:
Expand Down
16 changes: 8 additions & 8 deletions tests/fixtures/house.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
from pathlib import Path

from trano.elements.construction import Construction, Layer, Material
from tests.constructions.constructions import GasMaterials, Glasses
from trano.elements.types import Tilt, Azimuth
from trano.elements import param_from_config
from trano.elements.control import (
CollectorControl,
EmissionControl,
ThreeWayValveControl,
)
from trano.elements import (
ExternalDoor,
ExternalWall,
FloorOnGround,
InternalElement,
Window,
param_from_config,
)
from trano.elements.construction import Construction, Layer, Material
from trano.elements.control import (
CollectorControl,
EmissionControl,
ThreeWayValveControl,
)
from trano.elements.space import Space
from trano.elements.system import (
Expand All @@ -28,6 +27,7 @@
Valve,
Weather,
)
from trano.elements.types import Azimuth, Tilt
from trano.topology import Network

BoilerParameters = param_from_config("Boiler")
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/simple_space_1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from tests.constructions.constructions import Constructions, Glasses
from trano.elements.types import Tilt, Azimuth
from trano.elements import ExternalWall, FloorOnGround, Window
from trano.elements.space import Space
from trano.elements.types import Azimuth, Tilt


def simple_space_1_fixture() -> Space:
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/simple_space_1_with_occupancy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from tests.constructions.constructions import Constructions, Glasses
from trano.elements.types import Tilt, Azimuth
from trano.elements import ExternalWall, FloorOnGround, Window
from trano.elements.space import Space
from trano.elements.system import Occupancy
from trano.elements.types import Azimuth, Tilt


def simple_space_1_with_occupancy_fixture() -> Space:
Expand Down
5 changes: 2 additions & 3 deletions tests/fixtures/spaces_with_different_construction_types.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from tests.constructions.constructions import Constructions, Glasses
from trano.elements.types import Tilt, Azimuth
from trano.elements import param_from_config
from trano.elements import ExternalDoor, ExternalWall, Window
from trano.elements import ExternalDoor, ExternalWall, Window, param_from_config
from trano.elements.space import Space
from trano.elements.system import Occupancy
from trano.elements.types import Azimuth, Tilt

SpaceParameter = param_from_config("Space")

Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/spaces_with_emissions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from tests.constructions.constructions import Constructions, Glasses
from trano.elements.types import Tilt, Azimuth
from trano.elements.control import EmissionControl
from trano.elements import ExternalWall, FloorOnGround, Window
from trano.elements.control import EmissionControl
from trano.elements.space import Space
from trano.elements.system import Occupancy, Radiator, Valve
from trano.elements.types import Azimuth, Tilt


def space_1_fixture() -> Space:
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/spaces_with_ventilation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from tests.constructions.constructions import Constructions, Glasses
from trano.elements.types import Tilt, Azimuth
from trano.elements.control import VAVControl
from trano.elements import ExternalWall, FloorOnGround, Window
from trano.elements.control import VAVControl
from trano.elements.space import Space
from trano.elements.system import VAV, DamperVariant, Duct, Occupancy
from trano.elements.types import Azimuth, Tilt


def space_1_simple_ventilation_fixture() -> Space:
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/three_spaces.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import List

from tests.constructions.constructions import Constructions, Glasses
from trano.elements.types import Tilt, Azimuth
from trano.elements import ExternalWall, FloorOnGround, Window
from trano.elements.space import Space
from trano.elements.system import Occupancy
from trano.elements.types import Azimuth, Tilt


def three_spaces(occupancy: bool = True) -> List[Space]:
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/two_spaces.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import List

from tests.constructions.constructions import Constructions, Glasses
from trano.elements.types import Tilt, Azimuth
from trano.elements import ExternalWall, FloorOnGround, Window
from trano.elements.space import Space
from trano.elements.system import Occupancy
from trano.elements.types import Azimuth, Tilt


def two_spaces() -> List[Space]:
Expand Down
62 changes: 2 additions & 60 deletions tests/test_element.py
Original file line number Diff line number Diff line change
@@ -1,76 +1,18 @@
from pathlib import Path

import yaml
from linkml.validator import validate_file

from trano.library.library import Ideas, Buildings, Library


# from trano.models.elements.materials.properties import BuildingsData, IdeasData


def test_validate_schema() -> None:
for name in ["boiler", "valve", "window"]:

element = (
Path(__file__)
.parents[1]
.joinpath("trano", "models", "elements", "models", f"{name}.yaml")
.joinpath("trano", "elements", "models", f"{name}.yaml")
)
data_model_path = (
Path(__file__)
.parents[1]
.joinpath("trano", "models", "elements", "element.yaml")
Path(__file__).parents[1].joinpath("trano", "elements", "element.yaml")
)
report = validate_file(element, data_model_path, "Building")
assert report.results == []


def test_material():
buildings_data = BuildingsData()
ideas_data = IdeasData()

materials_path = Path(
"/trano/elements/materials/materials.yaml"
)

with materials_path.open("w") as f:
yaml.safe_dump(
{"ideas": ideas_data.model_dump(), "building": buildings_data.model_dump()},
f,
)


def test_library():
def get_library(name, library):
materials_path = Path(
"/trano/elements/materials/materials.yaml"
)
templates = yaml.safe_load(materials_path.read_text())
library_template = templates[name]
templates = {
"construction": library_template["construction"]["template"],
"glazing": library_template["glazing"]["template"],
"material": library_template["material"]["template"],
"main": library_template["template"],
}
library_ = library().model_dump()
library_.pop("functions")
library_["templates"] = templates
return library_
ideas = get_library("ideas", Ideas)
buildings = get_library("building", Buildings)
materials_path = Path(
"/home/aan/Documents/trano/trano/library/library.yaml"
)

with materials_path.open("w") as f:
yaml.safe_dump(
{"IDEAS": ideas, "Buildings": buildings},
f,
)


def test_load():
# Library.from_configuration("IDEAS")
Library.load_default()
Loading

0 comments on commit e847628

Please sign in to comment.