Skip to content

Commit

Permalink
Drop unitest in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Nov 21, 2023
1 parent 21382bd commit 999727f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 50 deletions.
70 changes: 39 additions & 31 deletions test/test_initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,56 @@
Use FMU deviation to check if initialization is taken into account.
"""

import unittest
import otfmi
import otfmi.example.utility
import numpy as np
import os
import pytest


class TestModel(unittest.TestCase):
def setUp(self):
"""Load FMU"""
@pytest.fixture
def model():
"""Load FMU"""
path_fmu = otfmi.example.utility.get_path_fmu("deviation")
model = otfmi.fmi.load_fmu(path_fmu)
return model

path_fmu = otfmi.example.utility.get_path_fmu("deviation")
self.model = otfmi.fmi.load_fmu(path_fmu)
self.var_name = "L"
self.var_val = float(300)

def test_no_default(self):
default_init_var = self.model.get_variable_start(self.var_name)
assert self.var_val != default_init_var
@pytest.fixture
def var_name():
return "L"

def test_inline_initialization(self):
"""Test initialization inline"""
result = otfmi.fmi.simulate(
self.model, input=(self.var_name, np.atleast_2d([0, self.var_val]))
)
obtained = result.final(self.var_name)
assert self.var_val == obtained

def test_initialization_script(self):
"""Test initialization scripts"""
@pytest.fixture
def var_val():
return 300.0

temporary_file = "initialization.mos"
with open(temporary_file, "w") as f:
f.write("{} = {};".format(self.var_name, self.var_val))

# Simulate with this script
result = otfmi.fmi.simulate(
self.model, initialization_script=os.path.abspath(temporary_file)
)
obtained = result.final(self.var_name)
assert self.var_val == obtained
def test_no_default(model, var_name, var_val):
default_init_var = model.get_variable_start(var_name)
assert var_val != default_init_var


if __name__ == "__main__":
unittest.main()
def test_inline_initialization(model, var_name, var_val):
"""Test initialization inline"""
result = otfmi.fmi.simulate(
model, input=(var_name, np.atleast_2d([0, var_val]))
)
obtained = result.final(var_name)
assert var_val == obtained


def test_initialization_script(model, var_name, var_val):
"""Test initialization scripts"""

temporary_file = "initialization.mos"
with open(temporary_file, "w") as f:
f.write("{} = {};".format(var_name, var_val))

# Simulate with this script
result = otfmi.fmi.simulate(
model, initialization_script=os.path.abspath(temporary_file)
)
obtained = result.final(var_name)
assert var_val == obtained

22 changes: 3 additions & 19 deletions test/test_variables.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env python

import otfmi
import unittest
import os
import pytest
import tempfile
import shutil


@pytest.mark.parametrize("varType", ["input", "parameter"])
@pytest.mark.parametrize("fmuType", ["cs", "me"])
def variable_tcase(varType, fmuType):

temp_path = tempfile.mkdtemp()
Expand Down Expand Up @@ -38,21 +40,3 @@ def variable_tcase(varType, fmuType):
print(y)
assert abs(y[0] - 24.0) < 1e-4, "wrong value"
shutil.rmtree(temp_path)


class TestExport(unittest.TestCase):
def test_input_cs(self):
variable_tcase("input", "cs")

def test_parameter_cs(self):
variable_tcase("parameter", "cs")

def test_input_me(self):
variable_tcase("input", "me")

def test_parameter_me(self):
variable_tcase("parameter", "me")


if __name__ == "__main__":
unittest.main()

0 comments on commit 999727f

Please sign in to comment.