本文整理汇总了Python中unittest.mock.Mock.crop方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.crop方法的具体用法?Python Mock.crop怎么用?Python Mock.crop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.crop方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_thumbnail
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import crop [as 别名]
def test_get_thumbnail():
instance = Mock()
cropped_value = Mock(url="crop.jpg")
thumbnail_value = Mock(url="thumb.jpg")
instance.crop = {"10x10": cropped_value}
instance.thumbnail = {"10x10": thumbnail_value}
cropped = get_thumbnail(instance, 10, method="crop")
assert cropped == cropped_value.url
thumb = get_thumbnail(instance, 10, method="thumbnail")
assert thumb == thumbnail_value.url
示例2: test_get_thumbnail_no_match_by_method
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import crop [as 别名]
def test_get_thumbnail_no_match_by_method():
instance = Mock()
cropped_value = Mock(url='crop.jpg')
instance.crop = {'1000x1000': cropped_value}
with pytest.warns(UserWarning) as record:
cropped = get_thumbnail(instance, 800, method='crop')
assert len(record) == 1
assert str(record[0].message) == \
'Thumbnail size crop__800x800 is not defined in settings' \
' and it won\'t be generated automatically'
assert cropped == static('images/placeholder1080x1080.png')
示例3: test_get_thumbnail_no_match_by_method
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import crop [as 别名]
def test_get_thumbnail_no_match_by_method():
instance = Mock()
cropped_value = Mock(url="crop.jpg")
instance.crop = {"1000x1000": cropped_value}
with pytest.warns(UserWarning) as record:
cropped = get_thumbnail(instance, 800, method="crop")
assert len(record) == 1
assert (
str(record[0].message)
== "Thumbnail size crop__800x800 is not defined in settings"
" and it won't be generated automatically"
)
assert cropped == static("images/placeholder1080x1080.png")
示例4: test_get_thumbnail_to_smaller
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import crop [as 别名]
def test_get_thumbnail_to_smaller():
instance = Mock()
cropped_value = Mock(url="crop.jpg")
instance.crop = {"100x100": cropped_value}
cropped = get_thumbnail(instance, 400, method="crop")
assert cropped == cropped_value.url
示例5: test_get_thumbnail_no_match_by_method
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import crop [as 别名]
def test_get_thumbnail_no_match_by_method():
instance = Mock()
cropped_value = Mock(url='crop.jpg')
instance.crop = {'1000x1000': cropped_value}
cropped = get_thumbnail(instance, 800, method='crop')
assert cropped == static('images/placeholder1080x1080.png')