-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #370 from lukaszb/feature/configure-default-ignore…
…-list Allow to configure default ignore list
- Loading branch information
Showing
7 changed files
with
174 additions
and
15 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
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,40 @@ | ||
|
||
|
||
DEFAULT_IGNORE_LIST = [ | ||
'nose.plugins', | ||
'six.moves', | ||
'django.utils.six.moves', | ||
'google.gax', | ||
'threading', | ||
'Queue', | ||
'selenium', | ||
'_pytest.terminal.', | ||
'_pytest.runner.', | ||
'gi', | ||
] | ||
|
||
|
||
class Settings: | ||
def __init__(self, default_ignore_list=None): | ||
self.default_ignore_list = default_ignore_list or DEFAULT_IGNORE_LIST[:] | ||
|
||
|
||
settings = Settings() | ||
|
||
|
||
class ConfigurationError(Exception): | ||
pass | ||
|
||
|
||
def configure(default_ignore_list=None, extend_ignore_list=None): | ||
if default_ignore_list is not None and extend_ignore_list is not None: | ||
raise ConfigurationError("Either default_ignore_list or extend_ignore_list might be given, not both") | ||
if default_ignore_list: | ||
settings.default_ignore_list = default_ignore_list | ||
if extend_ignore_list: | ||
settings.default_ignore_list = [*settings.default_ignore_list, *extend_ignore_list] | ||
|
||
|
||
def reset_config(): | ||
global settings | ||
settings = Settings() |
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,65 @@ | ||
from unittest import mock | ||
import freezegun | ||
import freezegun.config | ||
|
||
|
||
def setup_function(): | ||
freezegun.config.reset_config() | ||
|
||
|
||
def teardown_function(): | ||
freezegun.config.reset_config() | ||
|
||
|
||
def test_default_ignore_list_is_overridden(): | ||
freezegun.configure(default_ignore_list=['threading', 'tensorflow']) | ||
|
||
with mock.patch("freezegun.api._freeze_time.__init__", return_value=None) as _freeze_time_init_mock: | ||
|
||
freezegun.freeze_time("2020-10-06") | ||
|
||
expected_ignore_list = [ | ||
'threading', | ||
'tensorflow', | ||
] | ||
|
||
_freeze_time_init_mock.assert_called_once_with( | ||
time_to_freeze_str="2020-10-06", | ||
tz_offset=0, | ||
ignore=expected_ignore_list, | ||
tick=False, | ||
as_arg=False, | ||
as_kwarg='', | ||
auto_tick_seconds=0, | ||
) | ||
|
||
def test_extend_default_ignore_list(): | ||
freezegun.configure(extend_ignore_list=['tensorflow']) | ||
|
||
with mock.patch("freezegun.api._freeze_time.__init__", return_value=None) as _freeze_time_init_mock: | ||
|
||
freezegun.freeze_time("2020-10-06") | ||
|
||
expected_ignore_list = [ | ||
'nose.plugins', | ||
'six.moves', | ||
'django.utils.six.moves', | ||
'google.gax', | ||
'threading', | ||
'Queue', | ||
'selenium', | ||
'_pytest.terminal.', | ||
'_pytest.runner.', | ||
'gi', | ||
'tensorflow', | ||
] | ||
|
||
_freeze_time_init_mock.assert_called_once_with( | ||
time_to_freeze_str="2020-10-06", | ||
tz_offset=0, | ||
ignore=expected_ignore_list, | ||
tick=False, | ||
as_arg=False, | ||
as_kwarg='', | ||
auto_tick_seconds=0, | ||
) |
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