本文整理汇总了Python中mock.mock.MagicMock.read方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.read方法的具体用法?Python MagicMock.read怎么用?Python MagicMock.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_action_create_encoding
# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import read [as 别名]
def test_action_create_encoding(self, isdir_mock, exists_mock, open_mock, get_content_mock ,ensure_mock):
isdir_mock.side_effect = [False, True]
exists_mock.return_value = True
content_mock = MagicMock()
old_content_mock = MagicMock()
get_content_mock.return_value = content_mock
new_file = MagicMock()
open_mock.return_value = new_file
enter_file_mock = MagicMock()
enter_file_mock.read = MagicMock(return_value=old_content_mock)
new_file.__enter__ = MagicMock(return_value=enter_file_mock)
with Environment('/') as env:
File('/directory/file',
action='create',
mode=0777,
content='file-content',
encoding = "UTF-8"
)
open_mock.assert_called_with('/directory/file', 'wb')
content_mock.encode.assert_called_with('UTF-8')
old_content_mock.decode.assert_called_with('UTF-8')