Skip to content

Commit ea89cbf

Browse files
committed
Updated and debugged all tests to the new Json5 code.
1 parent a91b152 commit ea89cbf

6 files changed

Lines changed: 25 additions & 20 deletions

File tree

‎tests/test_cli.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_run():
119119
case = "gravity"
120120
path = Path(__file__).parent / "data" / "BouncingBall3D"
121121
cases = path / "BouncingBall3D.cases"
122-
res = path / f"{case}.js5"
122+
res = Path(f"{case}.js5")
123123
log = Path("test.log")
124124
if res.exists():
125125
res.unlink()
@@ -141,8 +141,8 @@ def test_Run():
141141
case = "restitution"
142142
path = Path(__file__).parent / "data" / "BouncingBall3D"
143143
cases = path / "BouncingBall3D.cases"
144-
res = path / f"{case}.js5"
145-
res2 = path / "restitutionAndGravity.js5"
144+
res = Path(f"{case}.js5")
145+
res2 = Path("restitutionAndGravity.js5")
146146
if res.exists():
147147
res.unlink()
148148
if res2.exists():

‎tests/test_oscillator_fmu.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def force(t: float, ampl: float = 1.0, omega: float = 0.1):
6262
return np.array((0, 0, ampl * sin(omega * t)), dtype=float)
6363

6464

65-
@pytest.fixture(scope="session")
65+
@pytest.fixture
6666
def oscillator_fmu():
6767
return _oscillator_fmu()
6868

@@ -79,7 +79,7 @@ def _oscillator_fmu():
7979
return fmu_path
8080

8181

82-
@pytest.fixture(scope="session")
82+
@pytest.fixture
8383
def driver_fmu():
8484
return _driver_fmu()
8585

@@ -97,15 +97,15 @@ def _driver_fmu():
9797
return fmu_path
9898

9999

100-
@pytest.fixture(scope="session")
100+
@pytest.fixture
101101
def system_structure():
102102
return _system_structure()
103103

104104

105105
def _system_structure():
106106
"""Make a OSP structure file and return the path"""
107107
path = make_osp_system_structure(
108-
name="ForcedOscillator",
108+
name="OspSystemStructure",
109109
simulators={
110110
"osc": {"source": "HarmonicOscillator.fmu", "stepSize": 0.01},
111111
"drv": {"source": "DrivingForce.fmu", "stepSize": 0.01},
@@ -115,7 +115,8 @@ def _system_structure():
115115
start=0.0,
116116
base_step=0.01,
117117
algorithm="fixedStep",
118-
path=Path(__file__).parent / "data" / "Oscillator",
118+
# path=Path(__file__).parent / "data" / "Oscillator",
119+
path=Path.cwd(),
119120
)
120121

121122
return path
@@ -171,6 +172,7 @@ def test_make_fmus(
171172
assert not len(val), f"Validation of of {oscillator_fmu.name} was not successful. Errors: {val}"
172173

173174

175+
@pytest.mark.usefixtures("oscillator_fmu", "driver_fmu")
174176
def test_make_system_structure(system_structure: Path):
175177
assert Path(system_structure).exists(), "System structure not created"
176178
el = from_xml(Path(system_structure))
@@ -228,6 +230,7 @@ def test_run_osp(oscillator_fmu: Path, driver_fmu: Path):
228230

229231

230232
@pytest.mark.skipif(sys.platform.startswith("linux"), reason="HarmonicOsciallator.fmu throws an error on Linux")
233+
@pytest.mark.usefixtures("oscillator_fmu", "driver_fmu")
231234
def test_run_osp_system_structure(system_structure: Path, show: bool):
232235
"Run an OSP simulation in the same way as the SimulatorInterface of case_study is implemented"
233236
log_output_level(CosimLogLevel.TRACE)

‎tests/test_pyjson5.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def do_file(file: Path):
2727
json5_write(js5, Path(file.name), indent=3) # write to test_working_directory
2828

2929
do_file(Path(__file__).parent / "data" / "BouncingBall3D" / "test_results")
30-
do_file(Path(__file__).parent / "data" / "BouncingBall3D" / "base.js5")
31-
do_file(Path(__file__).parent / "data" / "Oscillator" / "forced.js5")
30+
# do_file(Path(__file__).parent / "data" / "BouncingBall3D" / "base.js5")
31+
# do_file(Path(__file__).parent / "data" / "Oscillator" / "forced.js5")
3232

3333

3434
def test_read_cases():

‎tests/test_results.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ def test_inspect():
5757
res = Results(file=file)
5858
cont = res.inspect()
5959
assert cont["bb.e"]["len"] == 1, "Not a scalar??"
60-
assert cont["bb.e"]["range"][1] == 0.01, "Not at time 0.01??"
60+
assert cont["bb.e"]["range"][1] == 0.0, "Not at time 0.0??"
6161
assert cont["bb.e"]["info"]["description"] == "Coefficient of restitution"
62-
assert list(cont.keys()) == ["bb.e", "bb.g", "bb.x", "bb.v", "bb.x_b[0]"]
63-
assert cont["bb.x"]["len"] == 300
64-
assert cont["bb.x"]["range"] == [0.01, 3.0]
62+
assert list(cont.keys()) == ["bb.g", "bb.e", "bb.x", "bb.v", "bb.x_b"]
63+
assert cont["bb.x"]["len"] == 301
64+
assert cont["bb.x"]["range"] == [0.0, 3.0]
6565
assert cont["bb.x"]["info"]["description"] == "3D Position of the ball in meters"
6666
assert cont["bb.x"]["info"]["refs"] == (0, 1, 2), "ValueReferences"
6767

‎tests/test_run_mobilecrane.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def test_read_cases():
4242
path = Path(Path(__file__).parent / "data" / "MobileCrane" / "MobileCrane.cases")
4343
assert path.exists(), "System structure file not found"
4444
js5 = json5_read(path)
45-
# for e in json5.js_py:
46-
# print(f"{e}: {json5.js_py[e]}")
45+
# for e in js5:
46+
# print(f"{e}: {js5[e]}")
4747
assert json5_path(js5, "$.base.spec.df_dt", typ=list) == [0.0, 0.0, 0.0]
48-
# json5_write( json5.js_py, "MobileCrane.js5")
48+
# json5_write(js5, "MobileCrane.js5")
4949
assert json5_path(js5, "$.dynamic.spec.db_dt", typ=float) == 0.785498
5050

5151

@@ -164,15 +164,17 @@ def initial_settings():
164164
"static",
165165
"dynamic",
166166
]
167-
assert list(json5_path(js5, "$.header", dict).keys()) == [
167+
header = json5_path(js5=js5, path="$.header", typ=dict)
168+
assert header is not None, "Header not found in js5"
169+
assert list(header.keys()) == [
168170
"name",
169171
"description",
170172
"modelFile",
171173
"simulator",
172174
"logLevel",
173175
"timeUnit",
174176
"variables",
175-
], f"Found: {list(json5_path(js5, '$.header', dict).keys())}"
177+
], f"Found: {list(header.keys())}"
176178
cases = Cases(path)
177179
print("INFO", cases.info())
178180
static = cases.case_by_name("static")

‎tests/test_run_simpletable.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_run_time_table_base_case():
3030
Path(__file__).parent / "data/TimeTable/OspSystemStructure.xml",
3131
Path(__file__).parent / "data/BouncingBall0/OspSystemStructure.xml",
3232
Path(__file__).parent / "data/BouncingBall3D/OspSystemStructure.xml",
33-
Path(__file__).parent / "data/Oscillator/ForcedOscillator.xml",
33+
Path(__file__).parent / "data/Oscillator/OspSystemStructure.xml",
3434
Path(__file__).parent / "data/MobileCrane/OspSystemStructure.xml",
3535
],
3636
)

0 commit comments

Comments
 (0)