Skip to content

Commit

Permalink
wip: green test (refactoring).
Browse files Browse the repository at this point in the history
  • Loading branch information
andoludo committed Aug 31, 2024
1 parent e15fcfe commit 7dc81e8
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 148 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ instance/
# Scrapy stuff:
.scrapy

# Sphinx documentation
# Sphinx reporting
docs/_build/

# PyBuilder
Expand Down Expand Up @@ -142,7 +142,7 @@ venv.bak/
# Rope project settings
.ropeproject

# mkdocs documentation
# mkdocs reporting
/site

# mypy
Expand Down
71 changes: 41 additions & 30 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions tests/test_documentation.py → tests/test_reporting.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import tempfile
from pathlib import Path

from trano.documentation.documentation import (
from trano.reporting.reproting import (
ContentDocumentation,
ContentModelDocumentation,
ModelDocumentation,
ResultFile,
)
from trano.documentation.docx import to_docx
from trano.documentation.html import to_html_documentation
from trano.reporting.docx import to_docx
from trano.reporting.html import to_html_reporting
from trano.topology import Network


def test_documentation_buildings_two_rooms_with_storage(
def test_reporting_buildings_two_rooms_with_storage(
buildings_two_rooms_with_storage: Network,
) -> None:
documentation = ModelDocumentation.from_network(buildings_two_rooms_with_storage)
assert documentation
reporting = ModelDocumentation.from_network(buildings_two_rooms_with_storage)
assert reporting


def test_documentation_generate_html(
def test_reporting_generate_html(
buildings_two_rooms_with_storage: Network,
) -> None:
content = ContentModelDocumentation(
Expand All @@ -39,33 +39,33 @@ def test_documentation_generate_html(
conclusions="results",
),
)
documentation = ModelDocumentation.from_network(
reporting = ModelDocumentation.from_network(
buildings_two_rooms_with_storage, content
)
html = to_html_documentation(documentation)
html = to_html_reporting(reporting)
assert html


def test_documentation_generate_docx(
def test_reporting_generate_docx(
buildings_two_rooms_with_storage: Network,
) -> None:
documentation = ModelDocumentation.from_network(buildings_two_rooms_with_storage)
reporting = ModelDocumentation.from_network(buildings_two_rooms_with_storage)
with tempfile.NamedTemporaryFile(suffix=".docx") as tmpfile:
document = to_docx(documentation, Path(tmpfile.name))
document = to_docx(reporting, Path(tmpfile.name))
assert len(document.tables) == 6
assert len(document.inline_shapes) == 0


def test_documentation_generate_docx_with_figures(
def test_reporting_generate_docx_with_figures(
buildings_two_rooms_with_storage: Network, result_data_path: Path
) -> None:
documentation = ModelDocumentation.from_network(
reporting = ModelDocumentation.from_network(
buildings_two_rooms_with_storage,
result=ResultFile(
path=result_data_path,
),
)
with tempfile.NamedTemporaryFile(suffix=".docx") as tmpfile:
document = to_docx(documentation, Path(tmpfile.name))
document = to_docx(reporting, Path(tmpfile.name))
assert len(document.tables) == 6
assert len(document.inline_shapes) == 13
22 changes: 0 additions & 22 deletions trano/data_models/include.d/dummy_parameters.yaml

This file was deleted.

Empty file removed trano/documentation/__init__.py
Empty file.
5 changes: 3 additions & 2 deletions trano/elements/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from trano.elements.base import param_from_config, BaseElement, BaseParameter, Connection, Control, \
DynamicTemplateCategories, connect, Port
DynamicTemplateCategories, connect, Port, Figure
from trano.elements.envelope import (
ExternalDoor,
ExternalWall,
Expand All @@ -24,5 +24,6 @@
Connection,
Control,
DynamicTemplateCategories,
connect, Port
connect, Port,
Figure
]
5 changes: 3 additions & 2 deletions trano/elements/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
)
from pydantic.fields import computed_field

from trano.controller.parser import ControllerBus
from trano.elements.types import Flow

from trano.elements.types import Flow
from trano.elements.controller_bus import ControllerBus
if TYPE_CHECKING:
from trano.library.library import Libraries


Boolean = Literal["true", "false"]


Expand Down
4 changes: 3 additions & 1 deletion trano/elements/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import pandas as pd
from pydantic import BaseModel, Field, computed_field

from trano.controller.parser import BaseInput
from trano.elements.base import BaseElement
from trano.elements.inputs import BaseInput


class ValidationData(BaseModel):
Expand Down Expand Up @@ -42,3 +42,5 @@ def transform_csv_to_table(
if data_str.endswith(";"):
data_str = data_str[:-1]
return ValidationData(data=data_str, columns=data.columns.tolist())


74 changes: 7 additions & 67 deletions trano/controller/parser.py → trano/elements/controller_bus.py
Original file line number Diff line number Diff line change
@@ -1,75 +1,15 @@
import json
from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, List
from typing import List, Dict, Any, TYPE_CHECKING

from pydantic import BaseModel, Field, computed_field

if TYPE_CHECKING:

from trano.elements import BaseElement


class BaseInput(BaseModel):
name: str
component: str
port: str
multi: bool = False
target: str
input_template: str
default: float | str | int
evaluated_element_name: str = ""

def __hash__(self) -> int:
return hash((self.name, self.target))

def __eq__(self, other: object) -> bool:
return hash(self) == hash(other)

@computed_field # type: ignore
@property
def input_model(self) -> str:
if self.evaluated_element_name:
return f"""{self.input_template}
{self.name}{self.evaluated_element_name.capitalize()}
(y={self.default});"""
return ""


class RealInput(BaseInput):
default: float = 0.0
target: str = "Space"
input_template: str = "Modelica.Blocks.Sources.RealExpression"
from pydantic import BaseModel, Field


class IntegerInput(BaseInput):
default: int = 0
target: str = "Space"
input_template: str = "Modelica.Blocks.Sources.IntegerExpression"


class BooleanInput(BaseInput):
default: str = "false"
target: str = "Space"
input_template: str = "Modelica.Blocks.Sources.BooleanExpression"


class BooleanOutput(BaseInput):
default: str = "false"
target: str = "Controlled"
input_template: str = "Modelica.Blocks.Sources.BooleanExpression"


class IntegerOutput(BaseInput):
default: int = 0
target: str = "Controlled"
input_template: str = "Modelica.Blocks.Sources.IntegerExpression"


class RealOutput(BaseInput):
default: float = 0.0
target: str = "Controlled"
input_template: str = "Modelica.Blocks.Sources.RealExpression"
from trano.elements.inputs import RealInput, RealOutput, IntegerInput, IntegerOutput, BooleanInput, BooleanOutput, \
BaseInput

if TYPE_CHECKING:
from trano.elements import BaseElement

class ControllerBus(BaseModel):
template: str = """Controls.BaseClasses.DataBus dataBus
Expand All @@ -95,7 +35,7 @@ def inputs(
| RealOutput
| RealInput
| BooleanOutput
]:
]:
return (
self.real_inputs
+ self.real_outputs
Expand Down
Loading

0 comments on commit 7dc81e8

Please sign in to comment.