Skip to content

Commit

Permalink
Merge pull request #1 from jedwards4b/fix_walltime_check
Browse files Browse the repository at this point in the history
add this check in record_cmd
  • Loading branch information
jasonb5 authored Jun 18, 2021
2 parents 3b3f2b6 + 0b37b4e commit e07ea73
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scripts/lib/CIME/case/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def __init__(self, case_root=None, read_only=True, record=False):

if case_root is None:
case_root = os.getcwd()
if not (in_doctest() or in_unit_test()):
print("i am {}".format(isinstance(case,'Mock')))
expect(not os.path.isdir(case_root) or os.path.isfile(os.path.join(case_root,"env_case.xml")), "Directory {} does not appear to be a valid case directory".format(case_root))

self._caseroot = case_root
logger.debug("Initializing Case.")
self._read_only_mode = True
Expand Down Expand Up @@ -1666,6 +1670,8 @@ def record_cmd(self, cmd=None, init=False):

# Ensure program path is absolute
cmd[0] = re.sub("^./", "{}/scripts/".format(cimeroot), cmd[0])
elif not (in_doctest() or in_unit_test()):
expect(caseroot and os.path.isdir(caseroot) and os.path.isfile(os.path.join(caseroot,"env_case.xml")), "Directory {} does not appear to be a valid case directory".format(caseroot))

cmd = " ".join(cmd)

Expand Down Expand Up @@ -1805,3 +1811,28 @@ def preview_run(self, write, job):
write(" MPIRUN (job={}):".format(job_id))
write (" {}".format(self.get_resolved_value(overrides["mpirun"])))
write("")

def in_doctest():
"""
Determined by observation
"""
if '_pytest.doctest' in sys.modules:
return True
##
if hasattr(sys.modules['__main__'], '_SpoofOut'):
return True
##
if sys.modules['__main__'].__dict__.get('__file__', '').endswith('/pytest'):
return True
##
return False

import inspect

def in_unit_test():
current_stack = inspect.stack()
for stack_frame in current_stack:
for program_line in stack_frame[4]: # This element of the stack frame contains
if "unittest" in program_line: # some contextual program lines
return True
return False

0 comments on commit e07ea73

Please sign in to comment.