Track call args/kwargs in MockFH

This allows for them to be verified in tests
This commit is contained in:
Erik Johnson 2018-06-17 22:33:35 -05:00
parent 335591ca90
commit f5823252bb
No known key found for this signature in database
GPG Key ID: 5E5583C437808F3F

View File

@ -95,8 +95,10 @@ if NO_MOCK is False:
class MockFH(object):
def __init__(self, filename, read_data):
def __init__(self, filename, read_data, *args, **kwargs):
self.filename = filename
self.call_args = (filename,) + args
self.call_kwargs = kwargs
self.empty_string = b'' if isinstance(read_data, six.binary_type) else ''
self.read_data = self._iterate_read_data(read_data)
self.read = Mock(side_effect=self._read)
@ -316,7 +318,7 @@ class MockOpen(object):
# Contents were not an exception, so proceed with creating the
# mocked filehandle.
pass
ret = MockFH(name, file_contents)
ret = MockFH(name, file_contents, *args, **kwargs)
self.filehandles.setdefault(name, []).append(ret)
return ret
except KeyError: