Skip to content

Commit

Permalink
Merge pull request #4661 from jedwards4b/fix/pfunit_path
Browse files Browse the repository at this point in the history
fixes detection of pfunit_path by making sure it exists
  • Loading branch information
jedwards4b authored Aug 12, 2024
2 parents 9894678 + 7ad1003 commit 6aa0d7f
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions CIME/tests/test_sys_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import shutil
import sys
import re

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

for macro_to_check in macros_to_check:
if os.path.exists(macro_to_check):
macro_text = open(macro_to_check, "r").read()
if "PFUNIT_PATH" in macro_text:
return True
with open(macro_to_check, "r") as f:
while True:
line = f.readline().strip()
if not line:
break
if "PFUNIT_PATH" in line:
path = line.split(" ")[1][1:-2]
m = env_ref_re.match(path)
if m:
env_var = m.groups()[0]
env_var_exists = env_var in os.environ
if env_var_exists:
path = path.replace(
"$ENV{" + env_var + "}", os.environ[env_var]
)
if os.path.exists(path):
return True

return False

Expand Down

0 comments on commit 6aa0d7f

Please sign in to comment.