docstr: Tests that the default behavior keeps just the last 2 checkpoints.
docstr_tok: ["Tests","that","the","default","behavior","keeps","just","the","last","2","checkpoints","."]
code: def test_default(self):
      """
      Tests that the default behavior keeps just the last 2 checkpoints.
      """
      default_num_to_keep = 2
      num_epochs = 5
      target = [
          (e, 0)
          for e in range(num_epochs - default_num_to_keep, num_epochs)
      ]
  
      checkpointer = Checkpointer(serialization_dir=self.TEST_DIR)
      for epochs_completed in range(num_epochs):
          for batches_completed in [0, 5, 10]:
              state = {
                  "epochs_completed": epochs_completed,
                  "batches_in_epoch_completed": batches_completed,
              }
              checkpointer.maybe_save_checkpoint(
                  FakeTrainer(model_state=state, training_state=state),
                  epochs_completed,
                  batches_completed,
              )
      models, training = self.retrieve_and_delete_saved()
      assert models == training == target
  
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 2 for calling the TestCheckpointer obj's underlying member method code with example usage: obj.test_default() without return types