From eac75030cbc371793b24d54b8d32dbb0a77288a5 Mon Sep 17 00:00:00 2001 From: "J. Borovec" Date: Mon, 2 Mar 2020 20:20:38 +0100 Subject: [PATCH 1/2] fix tmpdir --- tests/trainer/test_trainer.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/trainer/test_trainer.py b/tests/trainer/test_trainer.py index 9788131c5500e..b28f4f8773c64 100644 --- a/tests/trainer/test_trainer.py +++ b/tests/trainer/test_trainer.py @@ -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() @@ -257,7 +257,7 @@ def mock_save_function(filepath): _ = LightningTestModel(hparams) # simulated losses - save_dir = tmp_path / "1" + save_dir = tmpdir / "1" save_dir.mkdir() losses = [10, 9, 2.8, 5, 2.5] @@ -285,7 +285,7 @@ def mock_save_function(filepath): 'epoch=0.ckpt'}: assert fname in file_lists - save_dir = tmp_path / "2" + save_dir = tmpdir / "2" save_dir.mkdir() # ----------------- @@ -304,7 +304,7 @@ 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 = tmpdir / "3" save_dir.mkdir() # ----------------- @@ -324,7 +324,7 @@ 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 = tmpdir / "4" save_dir.mkdir() # ----------------- @@ -350,7 +350,7 @@ def mock_save_function(filepath): 'other_file.ckpt'}: assert fname in file_lists - save_dir = tmp_path / "5" + save_dir = tmpdir / "5" save_dir.mkdir() # ----------------- @@ -371,7 +371,7 @@ 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 = tmpdir / "6" save_dir.mkdir() # ----------------- From 2cc5e7bab4a30b496921a2315ae202878a01c83c Mon Sep 17 00:00:00 2001 From: "J. Borovec" Date: Mon, 2 Mar 2020 22:11:21 +0100 Subject: [PATCH 2/2] just str path --- tests/trainer/test_trainer.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/trainer/test_trainer.py b/tests/trainer/test_trainer.py index b28f4f8773c64..bf9c60409e288 100644 --- a/tests/trainer/test_trainer.py +++ b/tests/trainer/test_trainer.py @@ -257,8 +257,8 @@ def mock_save_function(filepath): _ = LightningTestModel(hparams) # simulated losses - save_dir = tmpdir / "1" - save_dir.mkdir() + save_dir = os.path.join(tmpdir, '1') + os.mkdir(save_dir) losses = [10, 9, 2.8, 5, 2.5] # ----------------- @@ -285,8 +285,8 @@ def mock_save_function(filepath): 'epoch=0.ckpt'}: assert fname in file_lists - save_dir = tmpdir / "2" - save_dir.mkdir() + save_dir = os.path.join(tmpdir, '2') + os.mkdir(save_dir) # ----------------- # CASE K=0 (none) @@ -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 = tmpdir / "3" - save_dir.mkdir() + save_dir = os.path.join(tmpdir, '3') + os.mkdir(save_dir) # ----------------- # CASE K=1 (2.5, epoch 4) @@ -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 = tmpdir / "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) @@ -350,8 +350,8 @@ def mock_save_function(filepath): 'other_file.ckpt'}: assert fname in file_lists - save_dir = tmpdir / "5" - save_dir.mkdir() + save_dir = os.path.join(tmpdir, '5') + os.mkdir(save_dir) # ----------------- # CASE K=4 (save all 4 models) @@ -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 = tmpdir / "6" - save_dir.mkdir() + save_dir = os.path.join(tmpdir, '6') + os.mkdir(save_dir) # ----------------- # CASE K=3 (save the 2nd, 3rd, 4th model)