本文整理匯總了Python中catsnap.image_truck.ImageTruck.new_from_file方法的典型用法代碼示例。如果您正苦於以下問題:Python ImageTruck.new_from_file方法的具體用法?Python ImageTruck.new_from_file怎麽用?Python ImageTruck.new_from_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類catsnap.image_truck.ImageTruck
的用法示例。
在下文中一共展示了ImageTruck.new_from_file方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: file_type_test
# 需要導入模塊: from catsnap.image_truck import ImageTruck [as 別名]
# 或者: from catsnap.image_truck.ImageTruck import new_from_file [as 別名]
def file_type_test(self,
bucket_method,
test_file,
content_type,
resized_size):
bucket = Mock()
bucket_method.return_value = bucket
new_key = Mock()
bucket.new_key.return_value = new_key
image_handler = ImageHandler(filename=test_file)
truck = ImageTruck.new_from_file(test_file)
session = Client().session()
image = ImageTable(filename='badcafe')
session.add(image)
session.flush()
after_upload = Mock()
ResizeImage._resize_image(image,
image_handler,
truck,
'thumbnail',
after_upload)
new_key.set_metadata.assert_called_with('Content-Type', content_type)
resized_contents = new_key.set_contents_from_string.call_args[0][0]
image_handler = ImageHandler(blob=resized_contents)
eq_(image_handler.size, resized_size)
after_upload.assert_called_once_with('thumbnail')
示例2: test_new_from_file
# 需要導入模塊: from catsnap.image_truck import ImageTruck [as 別名]
# 或者: from catsnap.image_truck.ImageTruck import new_from_file [as 別名]
def test_new_from_file(self, subprocess):
subprocess.check_output.return_value = \
'space-centurion.png: PNG image data, 1280 x 800, ' \
'8-bit/color RGB, non-interlaced'
(_, image) = tempfile.mkstemp()
with open(image, 'w') as image_file:
image_file.write('here are some contents')
truck = ImageTruck.new_from_file(image)
eq_(truck.content_type, "image/png")
eq_(truck.contents, 'here are some contents')
eq_(truck.source_url, None)
subprocess.check_output.assert_called_with(['file', image])
示例3: test_new_from_file__raises_well_for_non_image_files
# 需要導入模塊: from catsnap.image_truck import ImageTruck [as 別名]
# 或者: from catsnap.image_truck.ImageTruck import new_from_file [as 別名]
def test_new_from_file__raises_well_for_non_image_files(self):
try:
truck = ImageTruck.new_from_file(__file__)
except Exception, e:
eq_(e.message, "'%s' doesn't seem to be an image file" % __file__)
eq_(type(e), TypeError)