本文整理汇总了Python中unittest.mock.Mock.size方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.size方法的具体用法?Python Mock.size怎么用?Python Mock.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.size方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_crop_and_resize_image
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import size [as 别名]
def test_crop_and_resize_image(self, inst_with_dimensions, context,
registry, monkeypatch):
import io
from PIL import Image
from substanced.file import File
from adhocracy_core.sheets import asset
from adhocracy_core.interfaces import Dimensions
file = Mock(spec=File)
file.blob = Mock()
file.blob.open.return_value = io.BytesIO(b'dummy blob')
file.mimetype = 'image/png'
mock_retrieve_asset_file = Mock(spec=asset.retrieve_asset_file,
return_value=file)
monkeypatch.setattr(asset, 'retrieve_asset_file',
mock_retrieve_asset_file)
mock_image = Mock()
mock_image.size = (840, 700)
mock_crop_image = Mock()
mock_image.crop.return_value = mock_crop_image
mock_open = Mock(spec=Image.open, return_value=mock_image)
monkeypatch.setattr(Image, 'open', mock_open)
dimensions = Dimensions(width=200, height=100)
result = inst_with_dimensions._crop_and_resize_image(context, registry)
assert file.blob.open.called
assert mock_image.crop.called
assert mock_crop_image.resize.called
assert mock_crop_image.resize.call_args[0] == (dimensions,
Image.ANTIALIAS)
assert result == inst_with_dimensions.file
assert result.mimetype == file.mimetype
示例2: test_crop_if_needed_crop_width
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import size [as 别名]
def test_crop_if_needed_crop_width(self, inst_with_dimensions):
mock_image = Mock()
mock_image.size = (1000, 400)
crop_result = Mock()
mock_image.crop.return_value = crop_result
assert inst_with_dimensions._crop_if_needed(mock_image) == crop_result
assert mock_image.crop.called
assert mock_image.crop.call_args[0][0] == (100, 0, 900, 400)
示例3: test_crop_if_needed_crop_height
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import size [as 别名]
def test_crop_if_needed_crop_height(self, inst_with_dimensions):
mock_image = Mock()
mock_image.size = (840, 700)
crop_result = Mock()
mock_image.crop.return_value = crop_result
assert inst_with_dimensions._crop_if_needed(mock_image) == crop_result
assert mock_image.crop.called
assert mock_image.crop.call_args[0][0] == (0, 140, 840, 560)
示例4: test_validate_size
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import size [as 别名]
def test_validate_size(self, mock_open, dimensions, valid):
mock_img = Mock()
mock_img.size = dimensions
mock_open.return_value = mock_img
template = Template(key='abc',
name="The ABC Meme",
link="example.com")
assert valid is template.validate_size()
示例5: test_neq_other_type
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import size [as 别名]
def test_neq_other_type(self):
"""Test 'not equals' operator when comparing with an object of a
different type.
"""
this = self._make_instance('replica_1', 1234)
other = Mock()
other.name = 'replica_1'
other.size = 1234
self.assertTrue(this != other)
示例6: mock_images
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import size [as 别名]
def mock_images(img):
image = Mock()
image.mode = 'P'
image.size = (1024, 2048)
image.convert = Mock(return_value=image)
img.open = MagicMock(return_value=image)
img.new = MagicMock(return_value=image)
img.size = Mock(return_value=4096)
img.exists = Mock(return_value=True)
return image
示例7: with_various_dimenions
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import size [as 别名]
def with_various_dimenions(mock_open, template, dimensions, valid):
mock_img = Mock()
mock_img.size = dimensions
mock_open.return_value = mock_img
expect(template.validate_size()) == valid
示例8: test_functional
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import size [as 别名]
def test_functional(self, PredictService, flask_app):
model = Mock()
model.threshold = 0.3
model.size = 10
# needed as hasattr would evaluate to True otherwise
del model.threshold2
del model.size2
model.predict.return_value = np.array(['class1'])
service = PredictService(
mapping=[
('sepal length', 'float'),
('sepal width', 'float'),
('petal length', 'float'),
('petal width', 'float'),
('color', 'str'),
('age', 'int'),
('active', 'bool'),
('austrian', 'bool'),
],
params=[
('threshold', 'float'), # default will be overwritten
('size', 'int'), # not provided, default value kept
('threshold2', 'float'), # will be used, no default value
('size2', 'int'), # not provided, no default value
])
with flask_app.test_request_context():
with patch('palladium.util.get_config') as get_config:
get_config.return_value = {
'service_metadata': {
'service_name': 'iris',
'service_version': '0.1'
}
}
request = Mock(
args=dict([
('sepal length', '5.2'),
('sepal width', '3.5'),
('petal length', '1.5'),
('petal width', '0.2'),
('color', 'purple'),
('age', '1'),
('active', 'True'),
('austrian', 'False'),
('threshold', '0.7'),
('threshold2', '0.8'),
]),
method='GET',
)
resp = service(model, request)
assert (model.predict.call_args[0][0] ==
np.array([[5.2, 3.5, 1.5, 0.2,
'purple', 1, True, False]], dtype='object')).all()
assert model.predict.call_args[1]['threshold'] == 0.7
assert model.predict.call_args[1]['size'] == 10
assert model.predict.call_args[1]['threshold2'] == 0.8
assert 'size2' not in model.predict.call_args[1]
assert resp.status_code == 200
expected_resp_data = {
"metadata": {
"status": "OK",
"error_code": 0,
"service_name": "iris",
"service_version": "0.1",
},
"result": "class1"
}
assert json.loads(resp.get_data(as_text=True)) == expected_resp_data
示例9: _givenS3Object
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import size [as 别名]
def _givenS3Object(self, last_modified = datetime.datetime(2016, 1, 1, 0, 0, 0), size = 1500, storage_class = "Standard"):
s3_object = Mock()
s3_object.last_modified = last_modified
s3_object.size = size
s3_object.storage_class = storage_class
return s3_object
示例10: test_validate_size
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import size [as 别名]
def test_validate_size(self, mock_open, template, dimensions, valid):
mock_img = Mock()
mock_img.size = dimensions
mock_open.return_value = mock_img
assert valid is template.validate_size()
示例11: with_various_dimenions
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import size [as 别名]
def with_various_dimenions(mock_open, template, dimensions, valid):
mock_img = Mock()
mock_img.size = dimensions
mock_open.return_value = mock_img
assert valid is template.validate_size()
示例12: test_run
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import size [as 别名]
def test_run(self, *args):
"""Test lvm format populator."""
get_device_by_uuid = args[0]
devicetree = DeviceTree()
data = dict()
device = Mock()
device.parents = []
device.size = Size("10g")
devicetree._add_device(device)
# pylint: disable=attribute-defined-outside-init
self._pvs = blockdev.lvm.pvs
self._vgs = blockdev.lvm.vgs
self._lvs = blockdev.lvm.lvs
blockdev.lvm.pvs = Mock(return_value=[])
blockdev.lvm.vgs = Mock(return_value=[])
blockdev.lvm.lvs = Mock(return_value=[])
self.addCleanup(self._clean_up)
# base case: pv format with no vg
with patch("blivet.udev.device_get_format", return_value=self.udev_type):
helper = self.helper_class(devicetree, data, device)
helper.run()
self.assertEqual(device.format.type,
self.blivet_type,
msg="Wrong format type after FormatPopulator.run on %s" % self.udev_type)
# pv belongs to a valid vg which is already in the tree (no lvs)
pv_info = Mock()
pv_info.vg_name = "testvgname"
pv_info.vg_uuid = sentinel.vg_uuid
pv_info.pe_start = 0
pv_info.pv_free = 0
device.path = sentinel.pv_path
vg_device = Mock()
vg_device.parents = []
vg_device.lvs = []
get_device_by_uuid.return_value = vg_device
with patch("blivet.static_data.lvm_info.PVsInfo.cache", new_callable=PropertyMock) as mock_pvs_cache:
mock_pvs_cache.return_value = {sentinel.pv_path: pv_info}
with patch("blivet.udev.device_get_format", return_value=self.udev_type):
helper = self.helper_class(devicetree, data, device)
self.assertFalse(device in vg_device.parents)
helper.run()
self.assertEqual(device.format.type,
self.blivet_type,
msg="Wrong format type after FormatPopulator.run on %s" % self.udev_type)
self.assertEqual(get_device_by_uuid.call_count, 3)
get_device_by_uuid.assert_called_with(pv_info.vg_uuid, incomplete=True)
self.assertTrue(device in vg_device.parents)
get_device_by_uuid.reset_mock()
get_device_by_uuid.return_value = None
# pv belongs to a valid vg which is not in the tree (no lvs, either)
pv_info.vg_size = "10g"
pv_info.vg_free = 0
pv_info.vg_extent_size = "4m"
pv_info.vg_extent_count = 2500
pv_info.vg_free_count = 0
pv_info.vg_pv_count = 1
with patch("blivet.static_data.lvm_info.PVsInfo.cache", new_callable=PropertyMock) as mock_pvs_cache:
mock_pvs_cache.return_value = {sentinel.pv_path: pv_info}
with patch("blivet.udev.device_get_format", return_value=self.udev_type):
helper = self.helper_class(devicetree, data, device)
helper.run()
self.assertEqual(device.format.type,
self.blivet_type,
msg="Wrong format type after FormatPopulator.run on %s" % self.udev_type)
self.assertEqual(get_device_by_uuid.call_count, 2)
get_device_by_uuid.assert_called_with(pv_info.vg_uuid, incomplete=True)
vg_device = devicetree.get_device_by_name(pv_info.vg_name)
self.assertTrue(vg_device is not None)
devicetree._remove_device(vg_device)
get_device_by_uuid.reset_mock()
# pv belongs to a valid vg not in the tree with two lvs
lv1 = Mock()
lv1.vg_name = pv_info.vg_name
lv1.lv_name = "testlv1"
lv1.uuid = sentinel.lv1_uuid
lv1.attr = "-wi-ao----"
lv1.size = "2g"
lv1.segtype = "linear"
lv1_name = "%s-%s" % (pv_info.vg_name, lv1.lv_name)
lv2 = Mock()
lv2.vg_name = pv_info.vg_name
lv2.lv_name = "testlv2"
lv2.uuid = sentinel.lv2_uuid
lv2.attr = "-wi-ao----"
#.........这里部分代码省略.........
示例13: test_crop_if_needed_no_cropping_needed_due_to_rounding
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import size [as 别名]
def test_crop_if_needed_no_cropping_needed_due_to_rounding(
self, inst_with_dimensions):
mock_image = Mock()
mock_image.size = (999, 500)
assert inst_with_dimensions._crop_if_needed(mock_image) == mock_image
assert not mock_image.crop.called
示例14: test_crop_if_needed_no_cropping_needed
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import size [as 别名]
def test_crop_if_needed_no_cropping_needed(self, inst_with_dimensions):
mock_image = Mock()
mock_image.size = (800, 400)
assert inst_with_dimensions._crop_if_needed(mock_image) == mock_image
assert not mock_image.crop.called