本文整理汇总了Python中mock.MagicMock.__enter__方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.__enter__方法的具体用法?Python MagicMock.__enter__怎么用?Python MagicMock.__enter__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.__enter__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rotate_image
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __enter__ [as 别名]
def test_rotate_image(self):
mock_img = Mock()
mock_img.__enter__().height = 200
mock_img.__enter__().width = 800
autorotate.wand.image.Image = Mock(return_value=mock_img)
autorotate.rotate_image('foo.jpg', 90)
assert mock_img.__enter__().rotate.call_args_list == [call(90)]
assert mock_img.__enter__().save.call_args_list == [
call(filename='foo.jpg')]
示例2: test_rotate_image
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __enter__ [as 别名]
def test_rotate_image(self):
mock_img = Mock()
mock_img.__enter__().height = 200
mock_img.__enter__().width = 800
autorotate.wand.image.Image = Mock(return_value=mock_img)
with patch('spreadsplug.autorotate.subprocess.check_output'):
autorotate.rotate_image('foo.jpg', 90)
assert mock_img.__enter__().rotate.call_args_list == [call(90)]
assert mock_img.__enter__().save.call_args_list == [
call(filename='foo.jpg')]
示例3: test_upload_o0
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __enter__ [as 别名]
def test_upload_o0(self):
m_rfh = MagicMock()
self.ftp._client.open.return_value = m_rfh
fobj = Mock()
fobj.read.side_effect = (b"bar", b"baz", b"")
self.ftp._upload("foo", fobj)
self.ftp._client.open.assert_called_once()
m_rfh.__enter__().write.assert_any_call(b"bar")
m_rfh.__enter__().write.assert_any_call(b"baz")
示例4: test_process_inverse
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __enter__ [as 别名]
def test_process_inverse(self):
test_files = [self.path / 'raw' / '000.jpg']
map(lambda x: x.touch(), test_files)
mock_pool = Mock()
autorotate.futures.ProcessPoolExecutor = Mock(return_value=mock_pool)
self.config['autorotate']['rotate_odd'] = 90
self.config['autorotate']['rotate_even'] = -90
plug = autorotate.AutoRotatePlugin(self.config)
with patch('spreadsplug.autorotate._get_exif_orientation') as geo:
geo.return_value = 6
plug.process(self.path)
mock_pool.__enter__().submit.assert_called_with(
autorotate.rotate_image, test_files[0], rotation=-90
)
示例5: test_load_template_source_second_source_path
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __enter__ [as 别名]
def test_load_template_source_second_source_path(self, open_mock):
file_mock = MagicMock()
file_mock.__enter__().read.return_value = "file_content"
open_mock.side_effect = (IOError(errno.ENOENT, 'No such file or directory'), file_mock)
loader = TemplateLoader(Mock())
self.assertEqual(loader.load_template_source("a.html"), ('file_content', '/fs/wirecloud/defaulttheme/templates/a.html'))
示例6: run_test
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __enter__ [as 别名]
def run_test(self, mock_field_map, mock_build_sql_query,
mock_ext_output, mock_projection):
mock_field_map.return_value = [u'id_cfpb', u'name']
mock_build_sql_query.return_value = 'SELECT blah blah'
mock_cursor_attrs = {'execute.return_value': True}
mock_cursor = MagicMock(**mock_cursor_attrs)
mock_cursor_enter_return = MagicMock(
return_value=["row1", "row2", "row3"], **mock_cursor_attrs)
mock_cursor_enter_return.__iter__.return_value = [
'row1', 'row2', 'row3']
mock_cursor.__enter__ = Mock(return_value=mock_cursor_enter_return)
mock_connect_attrs = {'cursor.return_value': mock_cursor}
mock_connect = Mock(**mock_connect_attrs)
mock_extractor_attrs = {'connect.return_value': mock_connect}
mock_extractor = Mock(table="table", **mock_extractor_attrs)
mock_ext_output.return_value = mock_extractor
mock_projection.return_value = "1"
format = Format("mapping_file", "docs_file", "table",
sql_filter="WHERE id_cfpb is not NULL", marker_table=True)
format.run()
mock_field_map.assert_called_once()
assert_equal(mock_projection.call_count, 3)
mock_projection.assert_has_calls([
mock.call(mock_field_map.return_value, "row1"),
mock.call(mock_field_map.return_value, "row2"),
mock.call(mock_field_map.return_value, "row3")
])
示例7: setUp
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __enter__ [as 别名]
def setUp(self):
self.mock_kv_store()
Settings.GANESHA_CLUSTERS_RADOS_POOL_NAMESPACE = "ganesha/ns"
self.temp_store = {
'export-1': GaneshaConfTest.RObject("export-1", self.export_1),
'conf-nodea': GaneshaConfTest.RObject("conf-nodea", self.conf_nodea),
'export-2': GaneshaConfTest.RObject("export-2", self.export_2),
'conf-nodeb': GaneshaConfTest.RObject("conf-nodeb", self.conf_nodeb)
}
self.io_mock = MagicMock()
self.io_mock.list_objects.side_effect = self._ioctx_list_objects_mock
self.io_mock.write_full.side_effect = self._ioctx_write_full_mock
self.io_mock.remove_object.side_effect = self._ioctx_remove_mock
ioctx_mock = MagicMock()
ioctx_mock.__enter__ = Mock(return_value=(self.io_mock))
ioctx_mock.__exit__ = Mock(return_value=None)
mgr.rados = MagicMock()
mgr.rados.open_ioctx.return_value = ioctx_mock
mgr.remote.return_value = False, None
ganesha.CephX = MagicMock()
ganesha.CephX.list_clients.return_value = ['ganesha']
ganesha.CephX.get_client_key.return_value = 'ganesha'
ganesha.CephFS = MagicMock()
示例8: test_process
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __enter__ [as 别名]
def test_process(self):
test_files = [self.path / 'raw' / x
for x in ('000.jpg', '001.jpg', '002.jpg')]
map(lambda x: x.touch(), test_files)
mock_pool = Mock()
autorotate.futures.ProcessPoolExecutor = Mock(return_value=mock_pool)
with patch('spreadsplug.autorotate._get_exif_orientation') as geo:
geo.side_effect = (6, 8, -1)
plug = autorotate.AutoRotatePlugin(self.config)
plug.process(self.path)
assert geo.call_count == 3
mock_pool.__enter__().submit.assert_has_calls([
call(autorotate.rotate_image, test_files[0], rotation=90),
call(autorotate.rotate_image, test_files[1], rotation=-90)
])
示例9: setUp
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __enter__ [as 别名]
def setUp(self):
account_mgr.get_cursor = MagicMock()
cur = MagicMock()
account_mgr.get_cursor.return_value = cur
self.cur = cur.__enter__()
account_mgr.get_api = MagicMock()
self.api = MagicMock()
account_mgr.get_api.return_value = self.api
示例10: test_ls_o0
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __enter__ [as 别名]
def test_ls_o0(self):
m_rfh = MagicMock()
m_rfh.__enter__().readdir.return_value = [
("whatever", b"bar"), ("again", b".baz"), ("toto", b".")]
self.ftp._client.opendir = MagicMock(return_value=m_rfh)
res = self.ftp._ls("foo")
self.ftp._client.opendir.assert_called_once_with("foo")
self.assertEqual(res, ["bar", ".baz"])
示例11: _gracefulCreateTableMock
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __enter__ [as 别名]
def _gracefulCreateTableMock(definition):
""" Mock for DynamoDBService._gracefulCreateTable
"""
batchTableMock = MagicMock(spec_set=BatchTable, put_item=Mock(spec_set=BatchTable.put_item))
batchTableMock.__enter__ = Mock(return_value=batchTableMock)
batchTableMock.__exit__ = Mock(return_value=False)
return Mock(
spec_set=DynamoTableTemplate,
table_name=definition.tableName,
batch_write=MagicMock(spec_set="boto.dynamodb2.table.batch_write", return_value=batchTableMock),
)
示例12: test_download_o0
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __enter__ [as 别名]
def test_download_o0(self):
m_rfh = MagicMock()
m_rfh.__enter__().__iter__.return_value = iter(
[(3, b"bar"), (3, b"baz"), (0, b"")])
self.ftp._client.open.return_value = m_rfh
fobj = Mock()
self.ftp._download("foo", fobj)
self.ftp._client.open.assert_called_once_with("foo", 0, 0)
fobj.write.assert_any_call(b"bar")
fobj.write.assert_any_call(b"baz")
fobj.write.assert_any_call(b"")
示例13: setUp
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __enter__ [as 别名]
def setUp(self):
account_mgr.get_cursor = MagicMock()
cur = MagicMock()
account_mgr.get_cursor.return_value = cur
self.cur = cur.__enter__()
account_mgr.get_api = MagicMock()
self.api = MagicMock()
account_mgr.get_api.return_value = self.api
self.user = {
'avatar_id': sentinel.avatar_id,
'email': sentinel.email,
}
self.api.get_user.return_value = self.user
self.time = datetime.now() + timedelta(hours=1)
示例14: test_process_inverse
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __enter__ [as 别名]
def test_process_inverse(self, listdir):
listdir.return_value = ['foo.jpg']
mock_exif = Mock()
mock_exif.exif.primary.Orientation = [6]
autorotate.os.listdir = listdir
autorotate.JpegFile = Mock()
autorotate.JpegFile.fromFile = Mock(return_value=mock_exif)
mock_pool = Mock()
autorotate.futures.ProcessPoolExecutor = Mock(return_value=mock_pool)
spreads.config['rotate_inverse'] = False
plug = autorotate.AutoRotatePlugin(spreads.config)
plug.process('/tmp/foobar')
assert mock_pool.__enter__().submit.call_args_list == [
call(autorotate.rotate_image, '/tmp/foobar/raw/foo.jpg',
rotation=90)
]
示例15: test_save_configuration
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __enter__ [as 别名]
def test_save_configuration(self):
"""
Does it have the configuration save a copy of itself?
"""
configadapter = MagicMock()
rvrconfiguration = RVRConfiguration(configadapter)
self.tester._configuration = rvrconfiguration
open_mock = mock_open()
opened_file = MagicMock()
open_mock.return_value = opened_file
print __name__
self.tester._result_location = 'apple_jack'
with patch('__builtin__.open', open_mock, create=True):
filename = 'outyor.ini'
self.tester.save_configuration(filename=filename)
open_mock.assert_called_with('apple_jack/outyor.ini', 'w')
configadapter.write.assert_called_with(opened_file.__enter__())
return