Skip to content

Commit 6aa0d7f

Browse files
authored
Merge pull request #4661 from jedwards4b/fix/pfunit_path
fixes detection of pfunit_path by making sure it exists
2 parents 9894678 + 7ad1003 commit 6aa0d7f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

CIME/tests/test_sys_unittest.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import shutil
55
import sys
6+
import re
67

78
from CIME import utils
89
from CIME.tests import base
@@ -46,12 +47,27 @@ def _has_unit_test_support(self):
4647
),
4748
os.path.join(cmake_machine_macros_dir, "{}.cmake".format(self._machine)),
4849
]
50+
env_ref_re = re.compile(r"\$ENV\{(\w+)\}")
4951

5052
for macro_to_check in macros_to_check:
5153
if os.path.exists(macro_to_check):
52-
macro_text = open(macro_to_check, "r").read()
53-
if "PFUNIT_PATH" in macro_text:
54-
return True
54+
with open(macro_to_check, "r") as f:
55+
while True:
56+
line = f.readline().strip()
57+
if not line:
58+
break
59+
if "PFUNIT_PATH" in line:
60+
path = line.split(" ")[1][1:-2]
61+
m = env_ref_re.match(path)
62+
if m:
63+
env_var = m.groups()[0]
64+
env_var_exists = env_var in os.environ
65+
if env_var_exists:
66+
path = path.replace(
67+
"$ENV{" + env_var + "}", os.environ[env_var]
68+
)
69+
if os.path.exists(path):
70+
return True
5571

5672
return False
5773

0 commit comments

Comments
 (0)