code: def patch_file(filename, unexpected_successes, new_xfails, new_skips):
      with open(filename, "r") as f:
          text = f.readlines()
  
      new_text = []
  
      i = 0
      while True:
          line = text[i]
          if line.startswith("dynamo_expected_failures"):
              break
          new_text.append(line)
          i += 1
  
      def format(testcase):
          classname = testcase.attrib["classname"]
          name = testcase.attrib["name"]
          return f"{classname}.{name}"
  
      formatted_unexpected_successes = {
          f"{format(test)}" for test in unexpected_successes.values()
      }
      formatted_new_xfails = [
          f'    "{format(test)}",  # {test.attrib["file"]}\n'
          for test in new_xfails.values()
      ]
      formatted_new_skips = [
          f'    "{format(test)}",  # {test.attrib["file"]}\n'
          for test in new_skips.values()
      ]
  
      def in_unexpected_successes(line):
          splits = line.split('"')
          if len(splits) < 3:
              return None
          test_name = splits[1]
          if test_name in formatted_unexpected_successes:
              return test_name
          return None
  
      covered_unexpected_successes = set({})
  
      # dynamo_expected_failures
      while True:
          line = text[i]
          match = in_unexpected_successes(line)
          if match is not None:
              covered_unexpected_successes.add(match)
              i += 1
              continue
          if line == "}\n":
              new_text.extend(formatted_new_xfails)
              new_text.append(line)
              i += 1
              break
          new_text.append(line)
          i += 1
  
      leftover_unexpected_successes = (
          formatted_unexpected_successes - covered_unexpected_successes
      )
      if len(leftover_unexpected_successes) > 0:
          print(
              "WARNING: we were unable to remove these "
              f"{len(leftover_unexpected_successes)} expectedFailures:"
          )
          for stuff in leftover_unexpected_successes:
              print(stuff)
  
      # dynamo_skips
      while True:
          line = text[i]
          if line == "}\n":
              new_text.extend(formatted_new_skips)
              break
          if line == "dynamo_skips = {}\n":
              new_text.extend("dynamo_skips = {\n")
              new_text.extend(new_skips)
              new_text.extend("}\n")
              i += 1
              break
          new_text.append(line)
          i += 1
  
      for j in range(i, len(text)):
          new_text.append(text[j])
  
      with open(filename, "w") as f:
          f.writelines(new_text)
  
imports: import argparse
  from common import get_testcases, is_failure, is_unexpected_success, key, open_test_results
label_desc: Use image node_id 1 for calling a global function with example usage: patch_file(filename, unexpected_successes, new_xfails, new_skips) and returns: classname, str, name, None, None, test_name