Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link ml #8

Merged
merged 11 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
rev: 4.0.1
hooks:
- id: flake8
args: ["--ignore=ANN101,ANN102,W503,INP001,FS003", "--max-line-length=120"]
args: ["--ignore=ANN101,ANN102,W503,INP001,FS003,SIM106", "--max-line-length=120"]
exclude: tests/excl/
additional_dependencies:
- flake8-annotations==2.9.0
Expand Down
2,142 changes: 1,805 additions & 337 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ plotly = "^5.22.0"
json2html = "^1.3.0"
yattag = "^1.15.2"
python-docx = "^1.1.2"
linkml = "^1.8.1"
cruft = "^2.15.0"
rdflib = "^7.0.0"
owlready2 = "^0.46"


[tool.poetry.group.dev.dependencies]
Expand Down
60 changes: 60 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import re
from pathlib import Path
from typing import Set

import docker
import pytest
Expand Down Expand Up @@ -54,6 +56,8 @@
from trano.models.elements.weather import Weather
from trano.topology import Network

OVERWRITE_MODELS = False


def is_success(results: docker.models.containers.ExecResult) -> bool:
return "The simulation finished successfully" in results.output.decode()
Expand Down Expand Up @@ -799,3 +803,59 @@ def building_multiple_internal_walls_ideas() -> Network:
@pytest.fixture
def house_model() -> Network:
return house_model_fixture()


def remove_annotation(model: str) -> str:
for documentation in re.findall(r"Documentation(.*?)</html>", model, re.DOTALL):
model = model.replace(documentation, "").replace("Documentation", "")

model = model.replace(" ", "").replace("\n", "")
for annotation in re.findall(r"annotation(.*?);", model):
model = model.replace(annotation, "").replace("annotation", "")

return model


def remove_common_package(model: str) -> str:
for annotation in re.findall(r"package Common(.*?)end Common;", model, re.DOTALL):
model = (
model.replace(annotation, "")
.replace("package Common", "")
.replace("end Common;", "")
)
return model


def clean_model(model: str, model_name: str) -> set:
if OVERWRITE_MODELS:
path_file = Path(__file__).parent.joinpath("data", f"{model_name}.mo")
with path_file.open("w") as f:
f.write(model)
model = remove_common_package(model)
model_ = remove_annotation(model)
return {
line
for line in set(
model_.replace("record", ";").replace(f"model{model_name}", "").split(";")
)
if "ReaderTMY3weather" not in line
}


def _read(file_name: str) -> Set:
return {
line
for line in set(
remove_annotation(
remove_common_package(
Path(__file__)
.parent.joinpath("data", f"{file_name}.mo")
.read_text()
)
)
.replace("record", ";")
.replace(f"model{file_name}", "")
.split(";")
)
if "ReaderTMY3weather" not in line
}
3,307 changes: 3,307 additions & 0 deletions tests/data/house.mo

Large diffs are not rendered by default.

Loading
Loading