class_docstr: Unit test for solver_utils. 
class_docstr_tok: ["Unit","test","for","solver_utils","."]
docstr: get model file according the specified model_load_type unittest
docstr_tok: ["get","model","file","according","the","specified","model_load_type","unittest"]
code: def test_get_model_file(self):
      """get model file according the specified model_load_type unittest"""
      model_load_dict = {
          "best": Path(self.model_path).joinpath("best_model.ckpt"),
          "specific": Path(self.model_path).joinpath(
              self.specified_model_file_name
          ),
          "latest": Path(self.model_path).joinpath(
              "model.00-1.00.ckpt"
          ),
      }
  
      # There is no model file in model_path
      mode_list = [utils.EVAL, utils.INFER]
      for cur_mode in mode_list:
          model_load_type_list = ["specific", "latest"]
          for cur_model_load_type in model_load_type_list:
              with self.assertRaises(AssertionError) as assert_err:
                  _, _ = solver_utils.get_model_file(
                      dir_name=self.model_path,
                      file_name_pattern=self.file_name_pattern,
                      mode=cur_mode,
                      model_load_type=cur_model_load_type,
                      specified_model_file_name=self.specified_model_file_name,
                  )
              the_exception = assert_err.exception
              self.assertEqual(
                  str(the_exception),
                  "{} END, since no model file is found".format(
                      cur_mode
                  ),
              )
  
          model_load_type_list = [None, "scratch", "best"]
          for cur_model_load_type in model_load_type_list:
              (
                  model_load_type,
                  model_file_name,
              ) = solver_utils.get_model_file(
                  dir_name=self.model_path,
                  file_name_pattern=self.file_name_pattern,
                  mode=cur_mode,
                  model_load_type=cur_model_load_type,
                  specified_model_file_name=self.specified_model_file_name,
              )
              self.assertEqual("best", model_load_type)
              self.assertEqual(model_load_dict["best"], model_file_name)
  
      cur_mode = utils.TRAIN
      model_load_type_list = [None, "scratch", "specific", "latest"]
      for cur_model_load_type in model_load_type_list:
          (
              model_load_type,
              model_file_name,
          ) = solver_utils.get_model_file(
              dir_name=self.model_path,
              file_name_pattern=self.file_name_pattern,
              mode=cur_mode,
              model_load_type=cur_model_load_type,
              specified_model_file_name=self.specified_model_file_name,
          )
          self.assertEqual(model_load_type, "scratch")
          self.assertIsNone(model_file_name)
  
      cur_model_load_type = "best"
      model_load_type, model_file_name = solver_utils.get_model_file(
          dir_name=self.model_path,
          file_name_pattern=self.file_name_pattern,
          mode=cur_mode,
          model_load_type=cur_model_load_type,
          specified_model_file_name=self.specified_model_file_name,
      )
      self.assertEqual(model_load_type, cur_model_load_type)
      self.assertEqual(
          model_file_name, model_load_dict[cur_model_load_type]
      )
      # create model files in model_path
      file_name_list = [
          "best_model.ckpt",
          "model.09-1.00.ckpt",
          "model.00-1.00.ckpt",
      ]
      for file_name in file_name_list:
          file_path = Path(self.model_path).joinpath(file_name)
          with open(
              file_path, "w", encoding="utf-8"
          ) as f:  # pylint: disable=invalid-name
              f.write("test ckpt file")
              time.sleep(1)
  
      all_mode_list = [utils.TRAIN, utils.EVAL, utils.INFER]
      for cur_mode in all_mode_list:
          for cur_model_load_type in model_load_dict:
              (
                  model_load_type,
                  model_file_name,
              ) = solver_utils.get_model_file(
                  dir_name=self.model_path,
                  file_name_pattern=self.file_name_pattern,
                  mode=cur_mode,
                  model_load_type=cur_model_load_type,
                  specified_model_file_name=self.specified_model_file_name,
              )
              self.assertEqual(cur_model_load_type, model_load_type)
              self.assertEqual(
                  model_load_dict[cur_model_load_type], model_file_name
              )
  
      model_load_type_list = ["scratch", None]
      mode_list = [utils.EVAL, utils.INFER]
      for cur_model_load_type in model_load_type_list:
          for cur_mode in mode_list:
              (
                  model_load_type,
                  model_file_name,
              ) = solver_utils.get_model_file(
                  dir_name=self.model_path,
                  file_name_pattern=self.file_name_pattern,
                  mode=cur_mode,
                  model_load_type=cur_model_load_type,
                  specified_model_file_name=self.specified_model_file_name,
              )
              self.assertEqual("best", model_load_type)
              self.assertEqual(
                  Path(self.model_path).joinpath("best_model.ckpt"),
                  model_file_name,
              )
  
      cur_mode = utils.TRAIN
      cur_model_load_type = "scratch"
      model_load_type, model_file_name = solver_utils.get_model_file(
          dir_name=self.model_path,
          file_name_pattern=self.file_name_pattern,
          mode=cur_mode,
          model_load_type=cur_model_load_type,
          specified_model_file_name=self.specified_model_file_name,
      )
      self.assertEqual(cur_model_load_type, model_load_type)
      self.assertIsNone(model_file_name)
  
      cur_model_load_type = None
      model_load_type, model_file_name = solver_utils.get_model_file(
          dir_name=self.model_path,
          file_name_pattern=self.file_name_pattern,
          mode=cur_mode,
          model_load_type=cur_model_load_type,
          specified_model_file_name=self.specified_model_file_name,
      )
      self.assertEqual("latest", model_load_type)
      self.assertEqual(
          Path(self.model_path).joinpath("model.00-1.00.ckpt"),
          model_file_name,
      )
  
file_path: delta/delta/utils/solver/utils/solver_utils_test.py
imports: import time
  from pathlib import Path
  import delta.compat
  from absl import logging
  from delta import utils
  from delta.utils.solver.utils import solver_utils
label_desc: Use image node_id 2 for calling the SolverUtilsTest obj's underlying member method code with example usage: obj.test_get_model_file() without return types