docstr: Helper function for the tests below. Finds the weight and training state files in
  self.TEST_DIR, parses their names for the epochs that were saved, deletes them,
  and returns the saved epochs as two lists of integers.
docstr_tok: ["Helper","function","for","the","tests","below",".","Finds","the","weight","and","training","state","files","in","self.TEST_DIR",",","parses","their","names","for","the","epochs","that","were","saved",",","deletes","them",",","and","returns","the","saved","epochs","as","two","lists","of","integers","."]
code: def retrieve_and_delete_saved(self, shard: Optional[int] = None):
      """
      Helper function for the tests below. Finds the weight and training state files in
      self.TEST_DIR, parses their names for the epochs that were saved, deletes them,
      and returns the saved epochs as two lists of integers.
      """
      serialization_files = os.listdir(self.TEST_DIR)
  
      model_checkpoints = [
          x for x in serialization_files if "model_state_" in x
      ]
      if shard is not None:
          model_checkpoints = [
              x
              for x in model_checkpoints
              if x.endswith(f"_w{shard}.th")
          ]
      found_model_states = [
          Checkpointer._parse_model_state_path(x)
          for x in model_checkpoints
      ]
      for f in model_checkpoints:
          os.remove(os.path.join(self.TEST_DIR, f))
  
      training_checkpoints = [
          x for x in serialization_files if "training_state_" in x
      ]
      if shard is not None:
          training_checkpoints = [
              x
              for x in training_checkpoints
              if x.endswith(f"_w{shard}.th")
          ]
      found_training_states = [
          Checkpointer._parse_training_state_path(x)
          for x in training_checkpoints
      ]
      for f in training_checkpoints:
          os.remove(os.path.join(self.TEST_DIR, f))
      return sorted(found_model_states), sorted(found_training_states)
  
file_path: allennlp/tests/training/checkpointer_test.py
imports: import os
  import time
  from typing import Optional
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.common.params import Params
  from allennlp.training import Checkpointer, Trainer
  from allennlp.training.trainer import TrainerCheckpoint
label_desc: Use image node_id 1 for calling the TestCheckpointer obj's underlying member method code with example usage: obj.retrieve_and_delete_saved(shard) and returns: sorted,  sorted