mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Allow Python 2 to accept an exception as read_data
This commit is contained in:
parent
543385fd02
commit
836fde9a30
1 changed files with 11 additions and 4 deletions
|
@ -238,10 +238,17 @@ def mock_open(read_data=''):
|
|||
if six.PY2:
|
||||
# .__class__() used here to preserve the dict class in the event that
|
||||
# an OrderedDict was used.
|
||||
read_data = read_data.__class__(
|
||||
[(x, salt.utils.stringutils.to_str(y))
|
||||
for x, y in six.iteritems(read_data)]
|
||||
)
|
||||
new_read_data = read_data.__class__()
|
||||
for key, val in six.iteritems(read_data):
|
||||
try:
|
||||
val = salt.utils.stringutils.to_str(val)
|
||||
except TypeError:
|
||||
if not isinstance(val, BaseException):
|
||||
raise
|
||||
new_read_data[key] = val
|
||||
|
||||
read_data = new_read_data
|
||||
del new_read_data
|
||||
|
||||
mock = MagicMock(name='open', spec=open)
|
||||
mock.handles = {}
|
||||
|
|
Loading…
Add table
Reference in a new issue