-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use getattr_static in spy instead of __getattributes__ (#224)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
- Loading branch information
1 parent
2de3e9a
commit 379b623
Showing
3 changed files
with
74 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from typing import Union | ||
|
||
_mock_module = None | ||
|
||
|
||
def get_mock_module(config): | ||
""" | ||
Import and return the actual "mock" module. By default this is | ||
"unittest.mock", but the user can force to always use "mock" using | ||
the mock_use_standalone_module ini option. | ||
""" | ||
global _mock_module | ||
if _mock_module is None: | ||
use_standalone_module = parse_ini_boolean( | ||
config.getini("mock_use_standalone_module") | ||
) | ||
if use_standalone_module: | ||
import mock | ||
|
||
_mock_module = mock | ||
else: | ||
import unittest.mock | ||
|
||
_mock_module = unittest.mock | ||
|
||
return _mock_module | ||
|
||
|
||
def parse_ini_boolean(value: Union[bool, str]) -> bool: | ||
if isinstance(value, bool): | ||
return value | ||
if value.lower() == "true": | ||
return True | ||
if value.lower() == "false": | ||
return False | ||
raise ValueError("unknown string for bool: %r" % value) |
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