Operate on a copy of the read_data

This keeps us from mangling it if it contains lists, which we would be
popping items off of. We don't want to pop items from the list that was
passed in.
This commit is contained in:
Erik Johnson 2018-06-18 14:45:40 -05:00
parent 71eeae1240
commit 38df912fa6
No known key found for this signature in database
GPG key ID: 5E5583C437808F3F

View file

@ -16,6 +16,7 @@
from __future__ import absolute_import
import collections
import copy
import errno
import fnmatch
import sys
@ -331,6 +332,10 @@ class MockOpen(object):
objects, representing the individual times that a given file was opened.
'''
def __init__(self, read_data=''):
# If the read_data contains lists, we will be popping it. So, don't
# modify the original value passed.
read_data = copy.copy(read_data)
# Normalize read_data, Python 2 filehandles should never produce unicode
# types on read.
if not isinstance(read_data, dict):