prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  ERR test does not always report failures correctly
  The ERR test runs four separate jobs, if one of these jobs completes but the next fails to launch, the test reports PASS.   To reproduce this problem its enough to edit the jobid_pattern field in config batch so that the dependency is incorrect - this causes the first job to exit and the second to fail to launch.   But the TestStatus file indicates all PASS. 
  
  </issue>
  <code>
  [start of utils/python/CIME/case_submit.py]
  1 #!/usr/bin/env python
  2 
  3 """
  4 case.submit - Submit a cesm workflow to the queueing system or run it
  5 if there is no queueing system.  A cesm workflow may include multiple
  6 jobs.
  7 """
  8 import socket
  9 from CIME.XML.standard_module_setup import *
  10 from CIME.utils                     import expect, append_status
  11 from CIME.preview_namelists         import create_namelists
  12 from CIME.check_lockedfiles         import check_lockedfiles
  13 from CIME.check_input_data          import check_all_input_data
  14 from CIME.case_cmpgen_namelists     import case_cmpgen_namelists
  15 
  16 logger = logging.getLogger(__name__)
  17 
  18 def submit(case, job=None, resubmit=False, no_batch=False):
  19     caseroot = case.get_value("CASEROOT")
  20 
  21     if job is None:
  22         if case.get_value("TEST"):
  23             job = "case.test"
  24         else:
  25             job = "case.run"
  26 
  27     if resubmit:
  28         resub = case.get_value("RESUBMIT")
  29         logger.info("Submitting job '%s', resubmit=%d" % (job, resub))
  30         case.set_value("RESUBMIT",resub-1)
  31         if case.get_value("RESUBMIT_SETS_CONTINUE_RUN"):
  32             case.set_value("CONTINUE_RUN", True)
  33     else:
  34         if job in ("case.test","case.run"):
  35             check_case(case, caseroot)
  36             check_DA_settings(case)
  37             if case.get_value("MACH") == "mira":
  38                 with open(".original_host","w") as fd:
  39                     fd.write( socket.gethostname())
  40 
  41     # if case.submit is called with the no_batch flag then we assume that this
  42     # flag will stay in effect for the duration of the RESUBMITs
  43     env_batch = case.get_env("batch")
  44     if not resubmit:
  45         case.set_value("IS_FIRST_RUN", True)
  46         if no_batch:
  47             batch_system = "none"
  48         else:
  49             batch_system = env_batch.get_batch_system_type()
  50         case.set_value("BATCH_SYSTEM", batch_system)
  51     else:
  52         if env_batch.get_batch_system_type() == "none":
  53             no_batch = True
  54 
  55         # This is a resubmission, do not reinitialize test values
  56         case.set_value("IS_FIRST_RUN", False)
  57 
  58     #Load Modules
  59     case.load_env()
  60 
  61     case.set_value("RUN_WITH_SUBMIT",True)
  62     case.flush()
  63 
  64     logger.warn("submit_jobs %s"%job)
  65     job_ids = case.submit_jobs(no_batch=no_batch, job=job)
  66     msg = "Submitted jobs %s"%job_ids
  67     append_status(msg, caseroot=caseroot, sfile="CaseStatus")
  68 
  69 def check_case(case, caseroot):
  70     check_lockedfiles(caseroot)
  71     create_namelists(case) # Must be called before check_all_input_data
  72     logger.info("Checking that inputdata is available as part of case submission")
  73     check_all_input_data(case)
  74     # Now that we have baselines, do baseline operations
  75     if case.get_value("TEST"):
  76         case_cmpgen_namelists(case)
  77 
  78     expect(case.get_value("BUILD_COMPLETE"), "Build complete is "
  79            "not True please rebuild the model by calling case.build")
  80     logger.info("Check case OK")
  81 
  82 def check_DA_settings(case):
  83     if case.get_value("DATA_ASSIMILATION"):
  84         script = case.get_value("DATA_ASSIMILATION_SCRIPT")
  85         cycles = case.get_value("DATA_ASSIMILATION_CYCLES")
  86         logger.info("Data Assimilation enabled using script %s with %d cycles"%(script,cycles))
  87 
  88
  [end of utils/python/CIME/case_submit.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/utils/python/CIME/case_submit.py b/utils/python/CIME/case_submit.py
  --- a/utils/python/CIME/case_submit.py
  +++ b/utils/python/CIME/case_submit.py
  @@ -12,10 +12,11 @@
   from CIME.check_lockedfiles         import check_lockedfiles
   from CIME.check_input_data          import check_all_input_data
   from CIME.case_cmpgen_namelists     import case_cmpgen_namelists
  +from CIME.test_status               import *
   
   logger = logging.getLogger(__name__)
   
  -def submit(case, job=None, resubmit=False, no_batch=False):
  +def _submit(case, job=None, resubmit=False, no_batch=False):
       caseroot = case.get_value("CASEROOT")
   
       if job is None:
  @@ -61,11 +62,27 @@
       case.set_value("RUN_WITH_SUBMIT",True)
       case.flush()
   
  -    logger.warn("submit_jobs %s"%job)
  +    logger.warn("submit_jobs %s" % job)
       job_ids = case.submit_jobs(no_batch=no_batch, job=job)
  -    msg = "Submitted jobs %s"%job_ids
  +    msg = "Submitted jobs %s" % job_ids
       append_status(msg, caseroot=caseroot, sfile="CaseStatus")
   
  +def submit(case, job=None, resubmit=False, no_batch=False):
  +    try:
  +        _submit(case, job=job, resubmit=resubmit, no_batch=no_batch)
  +    except:
  +        # If something failed in the batch system, make sure to mark
  +        # the test as failed if we are running a test.
  +        if case.get_value("TEST"):
  +            caseroot = case.get_value("CASEROOT")
  +            casebaseid = case.get_value("CASEBASEID")
  +            with TestStatus(test_dir=caseroot, test_name=casebaseid, lock=True) as ts:
  +                ts.set_status(RUN_PHASE, TEST_FAIL_STATUS, comments="batch system failure")
  +
  +            append_status("Batch submission failed, TestStatus file changed to read-only", caseroot=caseroot, sfile="TestStatus.log")
  +
  +        raise
  +
   def check_case(case, caseroot):
       check_lockedfiles(caseroot)
       create_namelists(case) # Must be called before check_all_input_data
  
verification_info: {"golden_diff": "diff --git a/utils/python/CIME/case_submit.py b/utils/python/CIME/case_submit.py\n--- a/utils/python/CIME/case_submit.py\n+++ b/utils/python/CIME/case_submit.py\n@@ -12,10 +12,11 @@\n from CIME.check_lockedfiles         import check_lockedfiles\n from CIME.check_input_data          import check_all_input_data\n from CIME.case_cmpgen_namelists     import case_cmpgen_namelists\n+from CIME.test_status               import *\n \n logger = logging.getLogger(__name__)\n \n-def submit(case, job=None, resubmit=False, no_batch=False):\n+def _submit(case, job=None, resubmit=False, no_batch=False):\n     caseroot = case.get_value(\"CASEROOT\")\n \n     if job is None:\n@@ -61,11 +62,27 @@\n     case.set_value(\"RUN_WITH_SUBMIT\",True)\n     case.flush()\n \n-    logger.warn(\"submit_jobs %s\"%job)\n+    logger.warn(\"submit_jobs %s\" % job)\n     job_ids = case.submit_jobs(no_batch=no_batch, job=job)\n-    msg = \"Submitted jobs %s\"%job_ids\n+    msg = \"Submitted jobs %s\" % job_ids\n     append_status(msg, caseroot=caseroot, sfile=\"CaseStatus\")\n \n+def submit(case, job=None, resubmit=False, no_batch=False):\n+    try:\n+        _submit(case, job=job, resubmit=resubmit, no_batch=no_batch)\n+    except:\n+        # If something failed in the batch system, make sure to mark\n+        # the test as failed if we are running a test.\n+        if case.get_value(\"TEST\"):\n+            caseroot = case.get_value(\"CASEROOT\")\n+            casebaseid = case.get_value(\"CASEBASEID\")\n+            with TestStatus(test_dir=caseroot, test_name=casebaseid, lock=True) as ts:\n+                ts.set_status(RUN_PHASE, TEST_FAIL_STATUS, comments=\"batch system failure\")\n+\n+            append_status(\"Batch submission failed, TestStatus file changed to read-only\", caseroot=caseroot, sfile=\"TestStatus.log\")\n+\n+        raise\n+\n def check_case(case, caseroot):\n     check_lockedfiles(caseroot)\n     create_namelists(case) # Must be called before check_all_input_data\n", "issue": "ERR test does not always report failures correctly\nThe ERR test runs four separate jobs, if one of these jobs completes but the next fails to launch, the test reports PASS.   To reproduce this problem its enough to edit the jobid_pattern field in config batch so that the dependency is incorrect - this causes the first job to exit and the second to fail to launch.   But the TestStatus file indicates all PASS. \n", "before_files": [{"content": "#!/usr/bin/env python\n\n\"\"\"\ncase.submit - Submit a cesm workflow to the queueing system or run it\nif there is no queueing system.  A cesm workflow may include multiple\njobs.\n\"\"\"\nimport socket\nfrom CIME.XML.standard_module_setup import *\nfrom CIME.utils                     import expect, append_status\nfrom CIME.preview_namelists         import create_namelists\nfrom CIME.check_lockedfiles         import check_lockedfiles\nfrom CIME.check_input_data          import check_all_input_data\nfrom CIME.case_cmpgen_namelists     import case_cmpgen_namelists\n\nlogger = logging.getLogger(__name__)\n\ndef submit(case, job=None, resubmit=False, no_batch=False):\n    caseroot = case.get_value(\"CASEROOT\")\n\n    if job is None:\n        if case.get_value(\"TEST\"):\n            job = \"case.test\"\n        else:\n            job = \"case.run\"\n\n    if resubmit:\n        resub = case.get_value(\"RESUBMIT\")\n        logger.info(\"Submitting job '%s', resubmit=%d\" % (job, resub))\n        case.set_value(\"RESUBMIT\",resub-1)\n        if case.get_value(\"RESUBMIT_SETS_CONTINUE_RUN\"):\n            case.set_value(\"CONTINUE_RUN\", True)\n    else:\n        if job in (\"case.test\",\"case.run\"):\n            check_case(case, caseroot)\n            check_DA_settings(case)\n            if case.get_value(\"MACH\") == \"mira\":\n                with open(\".original_host\",\"w\") as fd:\n                    fd.write( socket.gethostname())\n\n    # if case.submit is called with the no_batch flag then we assume that this\n    # flag will stay in effect for the duration of the RESUBMITs\n    env_batch = case.get_env(\"batch\")\n    if not resubmit:\n        case.set_value(\"IS_FIRST_RUN\", True)\n        if no_batch:\n            batch_system = \"none\"\n        else:\n            batch_system = env_batch.get_batch_system_type()\n        case.set_value(\"BATCH_SYSTEM\", batch_system)\n    else:\n        if env_batch.get_batch_system_type() == \"none\":\n            no_batch = True\n\n        # This is a resubmission, do not reinitialize test values\n        case.set_value(\"IS_FIRST_RUN\", False)\n\n    #Load Modules\n    case.load_env()\n\n    case.set_value(\"RUN_WITH_SUBMIT\",True)\n    case.flush()\n\n    logger.warn(\"submit_jobs %s\"%job)\n    job_ids = case.submit_jobs(no_batch=no_batch, job=job)\n    msg = \"Submitted jobs %s\"%job_ids\n    append_status(msg, caseroot=caseroot, sfile=\"CaseStatus\")\n\ndef check_case(case, caseroot):\n    check_lockedfiles(caseroot)\n    create_namelists(case) # Must be called before check_all_input_data\n    logger.info(\"Checking that inputdata is available as part of case submission\")\n    check_all_input_data(case)\n    # Now that we have baselines, do baseline operations\n    if case.get_value(\"TEST\"):\n        case_cmpgen_namelists(case)\n\n    expect(case.get_value(\"BUILD_COMPLETE\"), \"Build complete is \"\n           \"not True please rebuild the model by calling case.build\")\n    logger.info(\"Check case OK\")\n\ndef check_DA_settings(case):\n    if case.get_value(\"DATA_ASSIMILATION\"):\n        script = case.get_value(\"DATA_ASSIMILATION_SCRIPT\")\n        cycles = case.get_value(\"DATA_ASSIMILATION_CYCLES\")\n        logger.info(\"Data Assimilation enabled using script %s with %d cycles\"%(script,cycles))\n\n", "path": "utils/python/CIME/case_submit.py"}]}