Allow Python 2 to accept an exception as read_data

This commit is contained in:
Erik Johnson 2018-06-17 13:58:29 -05:00
parent 543385fd02
commit 836fde9a30
No known key found for this signature in database
GPG key ID: 5E5583C437808F3F

View file

@ -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 = {}