Skip to content

Commit 0ecc73b

Browse files
authored
refactor tests (#120)
1 parent 65bd445 commit 0ecc73b

File tree

15 files changed

+102
-108
lines changed

15 files changed

+102
-108
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
mkdir tmp-build
3434
cd tmp-build
3535
cmake $GITHUB_WORKSPACE/pythonfmu/pythonfmu-export -DCMAKE_BUILD_TYPE=Release
36-
cmake --build . --config Release
36+
cmake --build .
3737
cd ..
3838
- name: Archive wrapper library
3939
uses: actions/upload-artifact@v2

MANIFEST.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
include LICENSE
22
include README.md
33

4-
include pythonfmu/tests/csvdemo.csv
4+
recursive-include pythonfmu/tests/data *
5+
recursive-include pythonfmu/tests/slaves *
56

6-
recursive-include pythonfmu/pythonfmu-export *
77
recursive-include pythonfmu/resources *
8+
recursive-include pythonfmu/pythonfmu-export *
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mkdir build
2+
cd build
3+
cmake .. -DCMAKE_BUILD_TYPE=Release
4+
cmake --build .
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mkdir build
2+
cd build
3+
cmake .. -DCMAKE_BUILD_TYPE=Release -A x64
4+
cmake --build . --config Release
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from pythonfmu.fmi2slave import Fmi2Slave, Fmi2Causality, Real
2+
3+
4+
class PythonSlaveWithException(Fmi2Slave):
5+
6+
def __init__(self, **kwargs):
7+
super().__init__(**kwargs)
8+
9+
self.realIn = 22.0
10+
self.realOut = 0.0
11+
self.register_variable(Real("realIn", causality=Fmi2Causality.input))
12+
self.register_variable(Real("realOut", causality=Fmi2Causality.output))
13+
14+
def do_step(self, current_time, step_size):
15+
raise RuntimeError()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
3+
def get_amplitude():
4+
return 5.
5+
6+
7+
def get_time_constant():
8+
return 0.1
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import math
2+
from pythonfmu.fmi2slave import Fmi2Slave, Fmi2Causality, Real
3+
from localmodule import get_amplitude, get_time_constant
4+
5+
6+
class PythonSlaveWithDep(Fmi2Slave):
7+
8+
def __init__(self, **kwargs):
9+
super().__init__(**kwargs)
10+
11+
self.realIn = 22.0
12+
self.realOut = 0.0
13+
self.register_variable(Real("realIn", causality=Fmi2Causality.input))
14+
self.register_variable(Real("realOut", causality=Fmi2Causality.output))
15+
16+
def do_step(self, current_time, step_size):
17+
self.realOut = self.realIn * get_amplitude() * math.exp((current_time + step_size) / get_time_constant())
18+
return True

pythonfmu/tests/test_builder.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import itertools
22
import platform
3-
import sys
43
import tempfile
54
import zipfile
65
from pathlib import Path
@@ -10,7 +9,6 @@
109
import pythonfmu
1110
from pythonfmu.builder import FmuBuilder, get_platform
1211

13-
DEMO = "pythonslave.py"
1412
PROJECT_TEST_CASES = [
1513
("dummy.txt",),
1614
("dummy.py", "subdir/dummy.txt"),
@@ -25,8 +23,9 @@
2523

2624

2725
def test_zip_content(tmp_path):
28-
script_file = Path(__file__).parent / DEMO
2926

27+
script_name = "pythonslave.py"
28+
script_file = Path(__file__).parent / "slaves" / script_name
3029
fmu = FmuBuilder.build_FMU(script_file, dest=tmp_path)
3130
assert fmu.exists()
3231
assert zipfile.is_zipfile(fmu)
@@ -35,7 +34,7 @@ def test_zip_content(tmp_path):
3534
names = files.namelist()
3635

3736
assert "modelDescription.xml" in names
38-
assert "/".join(("resources", DEMO)) in names
37+
assert "/".join(("resources", script_name)) in names
3938
module_file = "/".join(("resources", "slavemodule.txt"))
4039
assert module_file in names
4140

@@ -72,9 +71,8 @@ def test_zip_content(tmp_path):
7271

7372
@pytest.mark.parametrize("pfiles", PROJECT_TEST_CASES)
7473
def test_project_files(tmp_path, pfiles):
75-
script_file = Path(__file__).parent / DEMO
7674
pfiles = map(Path, pfiles)
77-
75+
script_file = Path(__file__).parent / "slaves/pythonslave.py"
7876
def build():
7977
with tempfile.TemporaryDirectory() as project_dir:
8078
project_dir = Path(project_dir)
@@ -120,13 +118,13 @@ def build():
120118

121119
@pytest.mark.parametrize("pfiles", PROJECT_TEST_CASES)
122120
def test_project_files_containing_script(tmp_path, pfiles):
123-
orig_script_file = Path(__file__).parent / DEMO
121+
orig_script_file = Path(__file__).parent / "slaves/pythonslave.py"
124122
pfiles = map(Path, pfiles)
125123

126124
def build():
127125
with tempfile.TemporaryDirectory() as project_dir:
128126
project_dir = Path(project_dir)
129-
script_file = project_dir / DEMO
127+
script_file = project_dir / "slave.py"
130128
with open(orig_script_file) as script_f:
131129
script_file.write_text(script_f.read())
132130

@@ -159,8 +157,7 @@ def build():
159157

160158

161159
def test_documentation(tmp_path):
162-
script_file = Path(__file__).parent / DEMO
163-
160+
script_file = Path(__file__).parent / "slaves/pythonslave.py"
164161
def build():
165162
with tempfile.TemporaryDirectory() as documentation_dir:
166163
doc_dir = Path(documentation_dir)

0 commit comments

Comments
 (0)