-
-
Notifications
You must be signed in to change notification settings - Fork 650
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Raise warning on oudated methods call
- Loading branch information
Showing
4 changed files
with
149 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved | ||
from typing import Any, Optional | ||
from unittest.mock import MagicMock, Mock | ||
|
||
from omegaconf import DictConfig | ||
from pytest import mark, raises, warns | ||
|
||
from hydra import TaskFunction | ||
from hydra.core.config_loader import ConfigLoader | ||
from hydra.core.plugins import Plugins | ||
from hydra.core.utils import _get_callbacks_for_run_job | ||
from hydra.plugins.sweeper import Sweeper | ||
from hydra.test_utils.test_utils import chdir_hydra_root | ||
from hydra.types import HydraContext | ||
|
||
chdir_hydra_root() | ||
|
||
plugins = Plugins.instance() | ||
|
||
|
||
@mark.parametrize( | ||
"config_loader, hydra_context, expected", | ||
[ | ||
(None, None, AssertionError), | ||
(Mock(ConfigLoader), None, UserWarning()), | ||
(None, Mock(HydraContext), None), | ||
], | ||
) | ||
def test_setup_plugin( | ||
config_loader: Optional[ConfigLoader], | ||
hydra_context: Optional[HydraContext], | ||
expected: Any, | ||
) -> None: | ||
plugin = Mock(spec=Sweeper) | ||
plugin.setup = MagicMock() | ||
config = Mock(spec=DictConfig) | ||
task_function = Mock(spec=TaskFunction) | ||
msg = ( | ||
"\n" | ||
"\tPlugin's setup method has changed in Hydra 1.1.\n" | ||
"\tSupport for the old style will be removed in Hydra 1.2.\n" | ||
) | ||
if expected is None: | ||
plugins._setup_plugin( | ||
plugin, config, task_function, config_loader, hydra_context | ||
) | ||
plugin.setup.assert_called_with( | ||
config=config, hydra_context=hydra_context, task_function=task_function | ||
) | ||
elif isinstance(expected, UserWarning): | ||
with warns(expected_warning=UserWarning, match=msg): | ||
plugins._setup_plugin( | ||
plugin, config, task_function, config_loader, hydra_context | ||
) | ||
plugin.setup.assert_called_with( | ||
config=config, config_loader=config_loader, task_function=task_function | ||
) | ||
else: | ||
with raises(expected): | ||
plugins._setup_plugin( | ||
plugin, config, task_function, config_loader, hydra_context | ||
) | ||
plugin.setup.assert_not_called() | ||
|
||
|
||
def test_run_job() -> None: | ||
hydra_context = None | ||
msg = ( | ||
"\n" | ||
"\trun_job's signature has changed in Hydra 1.1.\n" | ||
"\tSupport for the old style will be removed in Hydra 1.2.\n" | ||
) | ||
with warns(expected_warning=UserWarning, match=msg): | ||
_get_callbacks_for_run_job(hydra_context) |