def test_model_checkpoint_with_non_string_input(tmp_path, save_top_k: int):
    """Test that dirpath=None in checkpoint callback is valid and that ckpt_path is set correctly."""
    model = LogInTwoMethods()

    checkpoint = ModelCheckpoint(monitor="early_stop_on", dirpath=None, filename="{epoch}", save_top_k=save_top_k)
    max_epochs = 2
    trainer = Trainer(
        default_root_dir=tmp_path, callbacks=[checkpoint], overfit_batches=0.20, max_epochs=max_epochs, logger=False
    )
    trainer.fit(model)
    assert checkpoint.dirpath == str(tmp_path / "checkpoints")

    if save_top_k == -1:
        ckpt_files = os.listdir(checkpoint.dirpath)
        expected_ckpt_files = [f"epoch={i}.ckpt" for i in range(max_epochs)]
        assert len(ckpt_files) == len(expected_ckpt_files) == max_epochs
        assert set(ckpt_files) == set(expected_ckpt_files)
Test that dirpath=None in checkpoint callback is valid and that ckpt_path is set correctly.
tests/tests_pytorch/checkpointing/test_model_checkpoint.py