Skip to content

Commit

Permalink
Make the prereq test more flexible and correct
Browse files Browse the repository at this point in the history
  • Loading branch information
mfdeakin-sandia committed Oct 24, 2017
1 parent bc9d950 commit 2411c97
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions scripts/tests/scripts_regression_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from six import assertRaisesRegex
import six

import collections

from CIME.utils import run_cmd, run_cmd_no_fail, get_lids, get_current_commit
import update_acme_tests
import CIME.test_scheduler, CIME.wait_for_tests
Expand All @@ -24,10 +26,6 @@
from CIME.code_checker import check_code, get_all_checkable_files
from CIME.test_status import *

from CIME.case_setup import case_setup
from CIME.case_submit import submit
import CIME.build as build

SCRIPT_DIR = CIME.utils.get_scripts_root()
TOOLS_DIR = os.path.join(SCRIPT_DIR,"Tools")
TEST_COMPILER = None
Expand Down Expand Up @@ -1412,18 +1410,32 @@ def test_cime_case_prereq(self):
with Case(testdir, read_only=False) as case:
job_name = "case.run"
prereq_name = 'prereq_test'
batch_cmd = case.submit_jobs(prereq=prereq_name, job=job_name, skip_pnl=True, dry_run=True)[0][1].split()
jobid_ident = 'jobid'
dep_str = case.get_env('batch').get_value('depend_string', subgroup=None)[:-len(jobid_ident)]
found_dep_str = False
for arg in batch_cmd:
if dep_str in arg:
found_dep_str = True
dep_id_pos = arg.find(dep_str) + len(dep_str)
dep_id = arg[dep_id_pos:]
break
self.assertTrue(found_dep_str, "Dependency not added to batch command")
self.assertTrue(prereq_name in dep_id, "Dependencies added, but not the user specified one")
batch_commands = case.submit_jobs(prereq=prereq_name, job=job_name, skip_pnl=True, dry_run=True)
self.assertTrue(isinstance(batch_commands, collections.Sequence), "case.submit_jobs did not return a sequence for a dry run")
self.assertTrue(len(batch_commands) > 0, "case.submit_jobs did not return any job submission string")
# The first element in the internal sequence should just be the job name
# The second one (batch_cmd_index) should be the actual batch submission command
batch_cmd_index = 1
# The prerequisite should be applied to all jobs, though we're only expecting one
for batch_cmd in batch_commands:
self.assertTrue(isinstance(batch_cmd, collections.Sequence), "case.submit_jobs did not return a sequence of sequences")
self.assertTrue(len(batch_cmd) > batch_cmd_index, "case.submit_jobs returned internal sequences with length <= {}".format(batch_cmd_index))
self.assertTrue(isinstance(batch_cmd[1], str), "case.submit_jobs returned internal sequences without the batch command string as the second parameter: {}".format(batch_cmd[1]))
batch_cmd_args = batch_cmd[1]

jobid_ident = 'jobid'
dep_str_fmt = case.get_env('batch').get_value('depend_string', subgroup=None)
self.assertTrue(jobid_ident in dep_str_fmt, "dependency string doesn't include the jobid identifier {}".format(jobid_ident))
dep_str = dep_str_fmt[:-len(jobid_ident)]

while dep_str in batch_cmd_args:
dep_id_pos = batch_cmd_args.find(dep_str) + len(dep_str)
batch_cmd_args = batch_cmd_args[dep_id_pos:]
prereq_substr = batch_cmd_args[:len(prereq_name)]
if prereq_substr == prereq_name:
break

self.assertTrue(prereq_name in prereq_substr, "Dependencies added, but not the user specified one")

###########################################################################
def test_cime_case_build_threaded_1(self):
Expand Down

0 comments on commit 2411c97

Please sign in to comment.