test deprecation warnings (#1470)
* check deprecation warnings * extend warning test * try * unimport modules * update
This commit is contained in:
parent
edb8d7a23c
commit
7989ca844c
|
@ -9,4 +9,3 @@ rank_zero_warn("`logging` package has been renamed to `loggers` since v0.7.0"
|
|||
" The deprecated package name will be removed in v0.9.0.", DeprecationWarning)
|
||||
|
||||
from pytorch_lightning.loggers import * # noqa: F403
|
||||
from pytorch_lightning.loggers import base, tensorboard # noqa: F403
|
||||
|
|
|
@ -312,7 +312,7 @@ class TrainerEvaluationLoopMixin(ABC):
|
|||
if self.is_overriden('test_end', model=model):
|
||||
# TODO: remove in v1.0.0
|
||||
eval_results = model.test_end(outputs)
|
||||
rank_zero_warn('Method `test_end` was deprecated in 0.7.0 and will be removed 1.0.0.'
|
||||
rank_zero_warn('Method `test_end` was deprecated in v0.7 and will be removed v1.0.'
|
||||
' Use `test_epoch_end` instead.', DeprecationWarning)
|
||||
|
||||
elif self.is_overriden('test_epoch_end', model=model):
|
||||
|
@ -322,7 +322,7 @@ class TrainerEvaluationLoopMixin(ABC):
|
|||
if self.is_overriden('validation_end', model=model):
|
||||
# TODO: remove in v1.0.0
|
||||
eval_results = model.validation_end(outputs)
|
||||
rank_zero_warn('Method `validation_end` was deprecated in 0.7.0 and will be removed 1.0.0.'
|
||||
rank_zero_warn('Method `validation_end` was deprecated in v0.7 and will be removed v1.0.'
|
||||
' Use `validation_epoch_end` instead.', DeprecationWarning)
|
||||
|
||||
elif self.is_overriden('validation_epoch_end', model=model):
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from functools import wraps
|
||||
|
||||
import pytest
|
||||
|
||||
import torch.multiprocessing as mp
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
"""Test deprecated functionality which will be removed in vX.Y.Z"""
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from pytorch_lightning import Trainer
|
||||
|
||||
|
@ -6,25 +9,57 @@ import tests.base.utils as tutils
|
|||
from tests.base import TestModelBase, LightTrainDataloader, LightEmptyTestStep
|
||||
|
||||
|
||||
def _soft_unimport_module(str_module):
|
||||
# once the module is imported e.g with parsing with pytest it lives in memory
|
||||
if str_module in sys.modules:
|
||||
del sys.modules[str_module]
|
||||
|
||||
|
||||
def test_tbd_remove_in_v0_8_0_module_imports():
|
||||
from pytorch_lightning.logging.comet_logger import CometLogger # noqa: F811
|
||||
from pytorch_lightning.logging.mlflow_logger import MLFlowLogger # noqa: F811
|
||||
from pytorch_lightning.logging.test_tube_logger import TestTubeLogger # noqa: F811
|
||||
_soft_unimport_module("pytorch_lightning.logging.comet_logger")
|
||||
with pytest.deprecated_call(match='v0.8.0'):
|
||||
from pytorch_lightning.logging.comet_logger import CometLogger # noqa: F811
|
||||
_soft_unimport_module("pytorch_lightning.logging.mlflow_logger")
|
||||
with pytest.deprecated_call(match='v0.8.0'):
|
||||
from pytorch_lightning.logging.mlflow_logger import MLFlowLogger # noqa: F811
|
||||
_soft_unimport_module("pytorch_lightning.logging.test_tube_logger")
|
||||
with pytest.deprecated_call(match='v0.8.0'):
|
||||
from pytorch_lightning.logging.test_tube_logger import TestTubeLogger # noqa: F811
|
||||
|
||||
from pytorch_lightning.pt_overrides.override_data_parallel import ( # noqa: F811
|
||||
LightningDataParallel, LightningDistributedDataParallel)
|
||||
from pytorch_lightning.overrides.override_data_parallel import ( # noqa: F811
|
||||
LightningDataParallel, LightningDistributedDataParallel)
|
||||
_soft_unimport_module("pytorch_lightning.pt_overrides.override_data_parallel")
|
||||
with pytest.deprecated_call(match='v0.8.0'):
|
||||
from pytorch_lightning.pt_overrides.override_data_parallel import ( # noqa: F811
|
||||
LightningDataParallel, LightningDistributedDataParallel)
|
||||
_soft_unimport_module("pytorch_lightning.overrides.override_data_parallel")
|
||||
with pytest.deprecated_call(match='v0.8.0'):
|
||||
from pytorch_lightning.overrides.override_data_parallel import ( # noqa: F811
|
||||
LightningDataParallel, LightningDistributedDataParallel)
|
||||
|
||||
from pytorch_lightning.core.model_saving import ModelIO # noqa: F811
|
||||
from pytorch_lightning.core.root_module import LightningModule # noqa: F811
|
||||
_soft_unimport_module("pytorch_lightning.core.model_saving")
|
||||
with pytest.deprecated_call(match='v0.8.0'):
|
||||
from pytorch_lightning.core.model_saving import ModelIO # noqa: F811
|
||||
_soft_unimport_module("pytorch_lightning.core.root_module")
|
||||
with pytest.deprecated_call(match='v0.8.0'):
|
||||
from pytorch_lightning.core.root_module import LightningModule # noqa: F811
|
||||
|
||||
from pytorch_lightning.root_module.decorators import data_loader # noqa: F811
|
||||
from pytorch_lightning.root_module.grads import GradInformation # noqa: F811
|
||||
from pytorch_lightning.root_module.hooks import ModelHooks # noqa: F811
|
||||
from pytorch_lightning.root_module.memory import ModelSummary # noqa: F811
|
||||
from pytorch_lightning.root_module.model_saving import ModelIO # noqa: F811
|
||||
from pytorch_lightning.root_module.root_module import LightningModule # noqa: F811
|
||||
_soft_unimport_module("pytorch_lightning.root_module.decorators")
|
||||
with pytest.deprecated_call(match='v0.8.0'):
|
||||
from pytorch_lightning.root_module.decorators import data_loader # noqa: F811
|
||||
_soft_unimport_module("pytorch_lightning.root_module.grads")
|
||||
with pytest.deprecated_call(match='v0.8.0'):
|
||||
from pytorch_lightning.root_module.grads import GradInformation # noqa: F811
|
||||
_soft_unimport_module("pytorch_lightning.root_module.hooks")
|
||||
with pytest.deprecated_call(match='v0.8.0'):
|
||||
from pytorch_lightning.root_module.hooks import ModelHooks # noqa: F811
|
||||
_soft_unimport_module("pytorch_lightning.root_module.memory")
|
||||
with pytest.deprecated_call(match='v0.8.0'):
|
||||
from pytorch_lightning.root_module.memory import ModelSummary # noqa: F811
|
||||
_soft_unimport_module("pytorch_lightning.root_module.model_saving")
|
||||
with pytest.deprecated_call(match='v0.8.0'):
|
||||
from pytorch_lightning.root_module.model_saving import ModelIO # noqa: F811
|
||||
_soft_unimport_module("pytorch_lightning.root_module.root_module")
|
||||
with pytest.deprecated_call(match='v0.8.0'):
|
||||
from pytorch_lightning.root_module.root_module import LightningModule # noqa: F811
|
||||
|
||||
|
||||
def test_tbd_remove_in_v0_8_0_trainer():
|
||||
|
@ -43,6 +78,8 @@ def test_tbd_remove_in_v0_8_0_trainer():
|
|||
|
||||
for attr_old in mapping_old_new:
|
||||
attr_new = mapping_old_new[attr_old]
|
||||
with pytest.deprecated_call(match='v0.8.0'):
|
||||
_ = getattr(trainer, attr_old)
|
||||
assert kwargs[attr_old] == getattr(trainer, attr_old), \
|
||||
'Missing deprecated attribute "%s"' % attr_old
|
||||
assert kwargs[attr_old] == getattr(trainer, attr_new), \
|
||||
|
@ -51,23 +88,36 @@ def test_tbd_remove_in_v0_8_0_trainer():
|
|||
|
||||
def test_tbd_remove_in_v0_9_0_trainer():
|
||||
# test show_progress_bar set by progress_bar_refresh_rate
|
||||
trainer = Trainer(progress_bar_refresh_rate=0, show_progress_bar=True)
|
||||
with pytest.deprecated_call(match='v0.9.0'):
|
||||
trainer = Trainer(progress_bar_refresh_rate=0, show_progress_bar=True)
|
||||
assert not getattr(trainer, 'show_progress_bar')
|
||||
|
||||
trainer = Trainer(progress_bar_refresh_rate=50, show_progress_bar=False)
|
||||
with pytest.deprecated_call(match='v0.9.0'):
|
||||
trainer = Trainer(progress_bar_refresh_rate=50, show_progress_bar=False)
|
||||
assert getattr(trainer, 'show_progress_bar')
|
||||
|
||||
|
||||
def test_tbd_remove_in_v0_9_0_module_imports():
|
||||
from pytorch_lightning.core.decorators import data_loader # noqa: F811
|
||||
_soft_unimport_module("pytorch_lightning.core.decorators")
|
||||
with pytest.deprecated_call(match='v0.9.0'):
|
||||
from pytorch_lightning.core.decorators import data_loader # noqa: F811
|
||||
data_loader(print)
|
||||
|
||||
from pytorch_lightning.logging.comet import CometLogger # noqa: F402
|
||||
from pytorch_lightning.logging.mlflow import MLFlowLogger # noqa: F402
|
||||
from pytorch_lightning.logging.neptune import NeptuneLogger # noqa: F402
|
||||
from pytorch_lightning.logging.test_tube import TestTubeLogger # noqa: F402
|
||||
from pytorch_lightning.logging.wandb import WandbLogger # noqa: F402
|
||||
|
||||
from pytorch_lightning.profiler import SimpleProfiler, AdvancedProfiler # noqa: F402
|
||||
_soft_unimport_module("pytorch_lightning.logging.comet")
|
||||
with pytest.deprecated_call(match='v0.9.0'):
|
||||
from pytorch_lightning.logging.comet import CometLogger # noqa: F402
|
||||
_soft_unimport_module("pytorch_lightning.logging.mlflow")
|
||||
with pytest.deprecated_call(match='v0.9.0'):
|
||||
from pytorch_lightning.logging.mlflow import MLFlowLogger # noqa: F402
|
||||
_soft_unimport_module("pytorch_lightning.logging.neptune")
|
||||
with pytest.deprecated_call(match='v0.9.0'):
|
||||
from pytorch_lightning.logging.neptune import NeptuneLogger # noqa: F402
|
||||
_soft_unimport_module("pytorch_lightning.logging.test_tube")
|
||||
with pytest.deprecated_call(match='v0.9.0'):
|
||||
from pytorch_lightning.logging.test_tube import TestTubeLogger # noqa: F402
|
||||
_soft_unimport_module("pytorch_lightning.logging.wandb")
|
||||
with pytest.deprecated_call(match='v0.9.0'):
|
||||
from pytorch_lightning.logging.wandb import WandbLogger # noqa: F402
|
||||
|
||||
|
||||
class ModelVer0_6(LightTrainDataloader, LightEmptyTestStep, TestModelBase):
|
||||
|
@ -113,22 +163,26 @@ def test_tbd_remove_in_v1_0_0_model_hooks():
|
|||
|
||||
model = ModelVer0_6(hparams)
|
||||
|
||||
trainer = Trainer(logger=False)
|
||||
trainer.test(model)
|
||||
with pytest.deprecated_call(match='v1.0'):
|
||||
trainer = Trainer(logger=False)
|
||||
trainer.test(model)
|
||||
assert trainer.callback_metrics == {'test_loss': 0.6}
|
||||
|
||||
trainer = Trainer(logger=False)
|
||||
# TODO: why `dataloder` is required if it is not used
|
||||
result = trainer._evaluate(model, dataloaders=[[None]], max_batches=1)
|
||||
with pytest.deprecated_call(match='v1.0'):
|
||||
trainer = Trainer(logger=False)
|
||||
# TODO: why `dataloder` is required if it is not used
|
||||
result = trainer._evaluate(model, dataloaders=[[None]], max_batches=1)
|
||||
assert result == {'val_loss': 0.6}
|
||||
|
||||
model = ModelVer0_7(hparams)
|
||||
|
||||
trainer = Trainer(logger=False)
|
||||
trainer.test(model)
|
||||
with pytest.deprecated_call(match='v1.0'):
|
||||
trainer = Trainer(logger=False)
|
||||
trainer.test(model)
|
||||
assert trainer.callback_metrics == {'test_loss': 0.7}
|
||||
|
||||
trainer = Trainer(logger=False)
|
||||
# TODO: why `dataloder` is required if it is not used
|
||||
result = trainer._evaluate(model, dataloaders=[[None]], max_batches=1)
|
||||
with pytest.deprecated_call(match='v1.0'):
|
||||
trainer = Trainer(logger=False)
|
||||
# TODO: why `dataloder` is required if it is not used
|
||||
result = trainer._evaluate(model, dataloaders=[[None]], max_batches=1)
|
||||
assert result == {'val_loss': 0.7}
|
||||
|
|
Loading…
Reference in New Issue