|
3 | 3 | import shutil
|
4 | 4 | import glob
|
5 | 5 | import sys
|
| 6 | +import json |
6 | 7 | import pytest
|
7 | 8 | from ipsframework import ips_dakota_dynamic
|
8 | 9 |
|
@@ -48,6 +49,44 @@ def test_dakota(tmpdir):
|
48 | 49 |
|
49 | 50 | assert float(X) == pytest.approx(0.5, rel=1e-4)
|
50 | 51 |
|
| 52 | + # Check PARENT CHILD relationship |
| 53 | + # Get parent PORTAL_RUNID |
| 54 | + json_files = glob.glob(str(tmpdir.join("DAKOTA_Gaussian_TEST_1").join("simulation_log").join("*.json"))) |
| 55 | + assert len(json_files) == 1 |
| 56 | + |
| 57 | + with open(json_files[0], 'r') as json_file: |
| 58 | + lines = json_file.readlines() |
| 59 | + |
| 60 | + lines = [json.loads(line.strip()) for line in lines] |
| 61 | + assert len(lines) == 9 |
| 62 | + |
| 63 | + # get portal_runid event |
| 64 | + portal_runid = lines[0]['portal_runid'] |
| 65 | + sim_name, host, user, _ = portal_runid.rsplit('_', maxsplit=3) |
| 66 | + assert sim_name == "DAKOTA_Gaussian_TEST_1" |
| 67 | + assert host == "workstation" |
| 68 | + assert user == "user" |
| 69 | + |
| 70 | + # Check child run |
| 71 | + json_files = glob.glob(str(tmpdir.join("DAKOTA_Gaussian_TEST_1").join("simulation_*_0000").join("simulation_log").join("*.json"))) |
| 72 | + assert len(json_files) == 1 |
| 73 | + with open(json_files[0], 'r') as json_file: |
| 74 | + lines = json_file.readlines() |
| 75 | + |
| 76 | + lines = [json.loads(line.strip()) for line in lines] |
| 77 | + assert len(lines) == 8 |
| 78 | + child_portal_runid = lines[0]['portal_runid'] |
| 79 | + assert child_portal_runid != portal_runid |
| 80 | + |
| 81 | + sim_name, host, user, _ = child_portal_runid.rsplit('_', maxsplit=3) |
| 82 | + assert sim_name.startswith("DAKOTA_Gaussian_TEST_1") |
| 83 | + assert len(sim_name) > len("DAKOTA_Gaussian_TEST_1") |
| 84 | + assert host == "workstation" |
| 85 | + assert user == "user" |
| 86 | + |
| 87 | + parent_portal_runid = lines[0]['parent_portal_runid'] |
| 88 | + assert parent_portal_runid == portal_runid |
| 89 | + |
51 | 90 |
|
52 | 91 | @mock.patch('ipsframework.ips_dakota_dynamic.DakotaDynamic')
|
53 | 92 | def test_dakota_main(MockDakotaDynamic):
|
|
0 commit comments