Repository: ESMCI/cime

Issue:
Fix --no-batch argument to create_test
the --no-batch argument to create_test does not appear to work on a machine with batch queues.



Discussion:

Resolving patch:
diff --git a/utils/python/CIME/case_setup.py b/utils/python/CIME/case_setup.py
--- a/utils/python/CIME/case_setup.py
+++ b/utils/python/CIME/case_setup.py
@@ -102,10 +102,6 @@ def case_setup(caseroot, clean=False, test_mode=False, reset=False):
 
     # Create batch script
     if reset or clean:
-#        if not os.path.exists("case.run"):
-#            logger.info("clean option has already been invoked ... skipping ")
-#            return
-
         # Clean batch script
 
         backup_dir = "PESetupHist/b.%s" % time.strftime("%y%m%d-%H%M%S")
@@ -230,7 +226,7 @@ def case_setup(caseroot, clean=False, test_mode=False, reset=False):
             batch_jobs = case.get_batch_jobs()
 
             batchmaker = None
-            for job,jparms in batch_jobs:
+            for job, jparms in batch_jobs:
                 if batchmaker is None:
                     batchmaker = get_batch_maker(job, case=case)
                 else:
@@ -242,14 +238,14 @@ def case_setup(caseroot, clean=False, test_mode=False, reset=False):
                     batchmaker.set_job(job)
 
                 input_batch_script  = os.path.join(case.get_value("MACHDIR"), jparms['template'])
-                if job == "case.test" and testcase is not None:
-                    logger.info("Writing %s script"%job)
+                if job == "case.test" and testcase is not None and not test_mode:
+                    logger.info("Writing %s script" % job)
                     testscript = os.path.join(cimeroot, "scripts", "Testing", "Testcases", "%s_script" % testcase)
                     # Short term fix to be removed when csh tests are removed
                     if not os.path.exists(testscript):
                         batchmaker.make_batch_script(input_batch_script, job)
                 elif job != "case.test":
-                    logger.info("Writing %s script"%job)
+                    logger.info("Writing %s script" % job)
                     batchmaker.make_batch_script(input_batch_script, job)
 
             # Make a copy of env_mach_pes.xml in order to be able


Test patch:
diff --git a/utils/python/CIME/SystemTests/system_tests_common.py b/utils/python/CIME/SystemTests/system_tests_common.py
--- a/utils/python/CIME/SystemTests/system_tests_common.py
+++ b/utils/python/CIME/SystemTests/system_tests_common.py
@@ -151,8 +151,6 @@ def _getlatestcpllog(self):
             cpllog = min(cpllogs, key=os.path.getctime)
         return cpllog
 
-
-
     def _compare(self):
         """
         check to see if there are history files to be compared, compare if they are there
diff --git a/utils/python/tests/scripts_regression_tests b/utils/python/tests/scripts_regression_tests
--- a/utils/python/tests/scripts_regression_tests
+++ b/utils/python/tests/scripts_regression_tests
@@ -350,7 +350,7 @@ class TestCreateTestCommon(unittest.TestCase):
         self._testroot          = MACHINE.get_value("CESMSCRATCHROOT")
         self._jenkins_root      = os.path.join(self._testroot, "jenkins")
         self._compiler          = MACHINE.get_default_compiler()
-        self._hasbatch          = MACHINE.has_batch_system()
+        self._hasbatch          = MACHINE.has_batch_system() and not NO_BATCH
         self._do_teardown       = True # Will never do teardown if test failed
         # wait_for_tests could blow away our dart config, need to back it up
         if (os.path.exists(DART_CONFIG)):
@@ -528,7 +528,7 @@ class E_TestSystemTest(TestCreateTestCommon):
     ###########################################################################
         tests = update_acme_tests.get_full_test_names(["acme_test_only"], self._machine, self._compiler)
         test_id="%s-%s" % (self._baseline_name, CIME.utils.get_utc_timestamp())
-        ct = SystemTest(tests, test_id=test_id)
+        ct = SystemTest(tests, test_id=test_id, no_batch=NO_BATCH)
 
         build_fail_test = [item for item in tests if "TESTBUILDFAIL" in item][0]
         run_fail_test   = [item for item in tests if "TESTRUNFAIL" in item][0]
@@ -555,6 +555,7 @@ class E_TestSystemTest(TestCreateTestCommon):
             elif (test_name == run_fail_test):
                 self.assertEqual(status[CIME.system_test.RUN_PHASE], wait_for_tests.TEST_FAIL_STATUS)
             elif (test_name == mem_fail_test):
+                self.assertTrue("memleak" in status, "memleak missing in %s for test %s" % (status, test_name))
                 self.assertEqual(status["memleak"], wait_for_tests.TEST_FAIL_STATUS)
                 self.assertEqual(status[CIME.system_test.RUN_PHASE], wait_for_tests.TEST_PASS_STATUS)
             else:
@@ -571,6 +572,8 @@ class TestJenkinsGenericJob(TestCreateTestCommon):
     ###########################################################################
     def simple_test(self, expect_works, extra_args):
     ###########################################################################
+        if NO_BATCH:
+            extra_args += " --no-batch"
         cmd = "%s/jenkins_generic_job %s" % (TOOLS_DIR, extra_args)
         stat, output, errput = run_cmd(cmd, ok_to_fail=True)
         if (expect_works):
@@ -785,7 +788,7 @@ class Z_FullSystemTest(TestCreateTestCommon):
         self.assertEqual(stat, 0,
                          msg="COMMAND SHOULD HAVE WORKED\ncreate_test output:\n%s\n\nerrput:\n%s\n\ncode: %d" % (output, errput, stat))
 
-        if (MACHINE.has_batch_system()):
+        if (self._hasbatch):
             stat, output, errput = run_cmd("%s/wait_for_tests *%s*/TestStatus" % (TOOLS_DIR, self._baseline_name),
                                            ok_to_fail=True, from_dir=self._testroot)
             self.assertEqual(stat, 0,