Skip to content

Commit

Permalink
Add test for dakota parent/child portal relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
rosswhitfield committed Sep 1, 2022
1 parent 1037dbe commit 7af3fa8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
39 changes: 39 additions & 0 deletions tests/dakota/test_dakota.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
import glob
import sys
import json
import pytest
from ipsframework import ips_dakota_dynamic

Expand Down Expand Up @@ -48,6 +49,44 @@ def test_dakota(tmpdir):

assert float(X) == pytest.approx(0.5, rel=1e-4)

# Check PARENT CHILD relationship
# Get parent PORTAL_RUNID
json_files = glob.glob(str(tmpdir.join("DAKOTA_Gaussian_TEST_1").join("simulation_log").join("*.json")))
assert len(json_files) == 1

with open(json_files[0], 'r') as json_file:
lines = json_file.readlines()

lines = [json.loads(line.strip()) for line in lines]
assert len(lines) == 9

# get portal_runid event
portal_runid = lines[0]['portal_runid']
sim_name, host, user, _ = portal_runid.rsplit('_', maxsplit=3)
assert sim_name == "DAKOTA_Gaussian_TEST_1"
assert host == "workstation"
assert user == "user"

# Check child run
json_files = glob.glob(str(tmpdir.join("DAKOTA_Gaussian_TEST_1").join("simulation_*_0000").join("simulation_log").join("*.json")))
assert len(json_files) == 1
with open(json_files[0], 'r') as json_file:
lines = json_file.readlines()

lines = [json.loads(line.strip()) for line in lines]
assert len(lines) == 8
child_portal_runid = lines[0]['portal_runid']
assert child_portal_runid != portal_runid

sim_name, host, user, _ = child_portal_runid.rsplit('_', maxsplit=3)
assert sim_name.startswith("DAKOTA_Gaussian_TEST_1")
assert len(sim_name) > len("DAKOTA_Gaussian_TEST_1")
assert host == "workstation"
assert user == "user"

parent_portal_runid = lines[0]['parent_portal_runid']
assert parent_portal_runid == portal_runid


@mock.patch('ipsframework.ips_dakota_dynamic.DakotaDynamic')
def test_dakota_main(MockDakotaDynamic):
Expand Down
3 changes: 2 additions & 1 deletion tests/dakota/workstation.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
HOST = my_laptop
HOST = workstation
USER = user
MPIRUN = eval

#######################################
Expand Down

0 comments on commit 7af3fa8

Please sign in to comment.