Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tmpdir #1012

Merged
merged 2 commits into from
Mar 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions tests/trainer/test_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def test_dp_output_reduce():
assert reduced['b']['c'] == out['b']['c']


def test_model_checkpoint_options(tmp_path):
def test_model_checkpoint_options(tmpdir):
"""Test ModelCheckpoint options."""
def mock_save_function(filepath):
open(filepath, 'a').close()
Expand All @@ -257,8 +257,8 @@ def mock_save_function(filepath):
_ = LightningTestModel(hparams)

# simulated losses
save_dir = tmp_path / "1"
save_dir.mkdir()
save_dir = os.path.join(tmpdir, '1')
os.mkdir(save_dir)
losses = [10, 9, 2.8, 5, 2.5]

# -----------------
Expand All @@ -285,8 +285,8 @@ def mock_save_function(filepath):
'epoch=0.ckpt'}:
assert fname in file_lists

save_dir = tmp_path / "2"
save_dir.mkdir()
save_dir = os.path.join(tmpdir, '2')
os.mkdir(save_dir)

# -----------------
# CASE K=0 (none)
Expand All @@ -304,8 +304,8 @@ def mock_save_function(filepath):

assert len(file_lists) == 0, "Should save 0 models when save_top_k=0"

save_dir = tmp_path / "3"
save_dir.mkdir()
save_dir = os.path.join(tmpdir, '3')
os.mkdir(save_dir)

# -----------------
# CASE K=1 (2.5, epoch 4)
Expand All @@ -324,8 +324,8 @@ def mock_save_function(filepath):
assert len(file_lists) == 1, "Should save 1 model when save_top_k=1"
assert 'test_prefix_epoch=4.ckpt' in file_lists

save_dir = tmp_path / "4"
save_dir.mkdir()
save_dir = os.path.join(tmpdir, '4')
os.mkdir(save_dir)

# -----------------
# CASE K=2 (2.5 epoch 4, 2.8 epoch 2)
Expand All @@ -350,8 +350,8 @@ def mock_save_function(filepath):
'other_file.ckpt'}:
assert fname in file_lists

save_dir = tmp_path / "5"
save_dir.mkdir()
save_dir = os.path.join(tmpdir, '5')
os.mkdir(save_dir)

# -----------------
# CASE K=4 (save all 4 models)
Expand All @@ -371,8 +371,8 @@ def mock_save_function(filepath):

assert len(file_lists) == 4, 'Should save all 4 models when save_top_k=4 within same epoch'

save_dir = tmp_path / "6"
save_dir.mkdir()
save_dir = os.path.join(tmpdir, '6')
os.mkdir(save_dir)

# -----------------
# CASE K=3 (save the 2nd, 3rd, 4th model)
Expand Down