Added test case for existing experiment.

This commit is contained in:
NRJ 2020-10-01 03:05:04 +03:00
parent 9b7b1d5e26
commit 9f3ba2e37b
1 changed files with 39 additions and 31 deletions

View File

@ -7,9 +7,9 @@ from pytorch_lightning.loggers import NeptuneLogger
from tests.base import EvalModelTemplate from tests.base import EvalModelTemplate
@patch('pytorch_lightning.loggers.neptune.neptune') @patch("pytorch_lightning.loggers.neptune.neptune")
def test_neptune_online(neptune): def test_neptune_online(neptune):
logger = NeptuneLogger(api_key='test', project_name='project') logger = NeptuneLogger(api_key="test", project_name="project")
created_experiment = neptune.Session.with_default_backend().get_project().create_experiment() created_experiment = neptune.Session.with_default_backend().get_project().create_experiment()
@ -21,7 +21,20 @@ def test_neptune_online(neptune):
assert logger.version == created_experiment.id assert logger.version == created_experiment.id
@patch('pytorch_lightning.loggers.neptune.neptune') @patch("pytorch_lightning.loggers.neptune.neptune")
def test_neptune_existing_experiment(neptune):
logger = NeptuneLogger(experiment_id="TEST-123")
neptune.Session.with_default_backend().get_project().get_experiments.assert_called_once_with(id="TEST-123")
experiment = logger.experiment
assert logger.experiment_name == experiment.get_system_properties()["name"]
assert logger.params == experiment.get_parameters()
assert logger.properties == experiment.get_properties()
assert logger.tags == experiment.get_tags()
@patch("pytorch_lightning.loggers.neptune.neptune")
def test_neptune_offline(neptune): def test_neptune_offline(neptune):
logger = NeptuneLogger(offline_mode=True) logger = NeptuneLogger(offline_mode=True)
@ -29,48 +42,48 @@ def test_neptune_offline(neptune):
assert logger.experiment == neptune.Session().get_project().create_experiment() assert logger.experiment == neptune.Session().get_project().create_experiment()
@patch('pytorch_lightning.loggers.neptune.neptune') @patch("pytorch_lightning.loggers.neptune.neptune")
def test_neptune_additional_methods(neptune): def test_neptune_additional_methods(neptune):
logger = NeptuneLogger(api_key='test', project_name='project') logger = NeptuneLogger(api_key="test", project_name="project")
created_experiment = neptune.Session.with_default_backend().get_project().create_experiment() created_experiment = neptune.Session.with_default_backend().get_project().create_experiment()
logger.log_metric('test', torch.ones(1)) logger.log_metric("test", torch.ones(1))
created_experiment.log_metric.assert_called_once_with('test', torch.ones(1)) created_experiment.log_metric.assert_called_once_with("test", torch.ones(1))
created_experiment.log_metric.reset_mock() created_experiment.log_metric.reset_mock()
logger.log_metric('test', 1.0) logger.log_metric("test", 1.0)
created_experiment.log_metric.assert_called_once_with('test', 1.0) created_experiment.log_metric.assert_called_once_with("test", 1.0)
created_experiment.log_metric.reset_mock() created_experiment.log_metric.reset_mock()
logger.log_metric('test', 1.0, step=2) logger.log_metric("test", 1.0, step=2)
created_experiment.log_metric.assert_called_once_with('test', x=2, y=1.0) created_experiment.log_metric.assert_called_once_with("test", x=2, y=1.0)
created_experiment.log_metric.reset_mock() created_experiment.log_metric.reset_mock()
logger.log_text('test', 'text') logger.log_text("test", "text")
created_experiment.log_metric.assert_called_once_with('test', 'text') created_experiment.log_metric.assert_called_once_with("test", "text")
created_experiment.log_metric.reset_mock() created_experiment.log_metric.reset_mock()
logger.log_image('test', 'image file') logger.log_image("test", "image file")
created_experiment.log_image.assert_called_once_with('test', 'image file') created_experiment.log_image.assert_called_once_with("test", "image file")
created_experiment.log_image.reset_mock() created_experiment.log_image.reset_mock()
logger.log_image('test', 'image file', step=2) logger.log_image("test", "image file", step=2)
created_experiment.log_image.assert_called_once_with('test', x=2, y='image file') created_experiment.log_image.assert_called_once_with("test", x=2, y="image file")
created_experiment.log_image.reset_mock() created_experiment.log_image.reset_mock()
logger.log_artifact('file') logger.log_artifact("file")
created_experiment.log_artifact.assert_called_once_with('file', None) created_experiment.log_artifact.assert_called_once_with("file", None)
logger.set_property('property', 10) logger.set_property("property", 10)
created_experiment.set_property.assert_called_once_with('property', 10) created_experiment.set_property.assert_called_once_with("property", 10)
logger.append_tags('one tag') logger.append_tags("one tag")
created_experiment.append_tags.assert_called_once_with('one tag') created_experiment.append_tags.assert_called_once_with("one tag")
created_experiment.append_tags.reset_mock() created_experiment.append_tags.reset_mock()
logger.append_tags(['two', 'tags']) logger.append_tags(["two", "tags"])
created_experiment.append_tags.assert_called_once_with('two', 'tags') created_experiment.append_tags.assert_called_once_with("two", "tags")
def test_neptune_leave_open_experiment_after_fit(tmpdir): def test_neptune_leave_open_experiment_after_fit(tmpdir):
@ -79,12 +92,7 @@ def test_neptune_leave_open_experiment_after_fit(tmpdir):
def _run_training(logger): def _run_training(logger):
logger._experiment = MagicMock() logger._experiment = MagicMock()
trainer = Trainer( trainer = Trainer(default_root_dir=tmpdir, max_epochs=1, limit_train_batches=0.05, logger=logger,)
default_root_dir=tmpdir,
max_epochs=1,
limit_train_batches=0.05,
logger=logger,
)
trainer.fit(model) trainer.fit(model)
return logger return logger