def test_image_transform_without_border(self, add_border, add_drop_shadow): """Make sure the right functions are called to transform the image.""" image = Image.open(imageutils.get_icon_filename(['unknown'], 48)) image.load() add_border.return_value = image add_drop_shadow.return_value = image self.datagrid_model.image_max_size = 123 self.datagrid_model.image_draw_border = False self.datagrid_model.image_load_on_thread = False with contextlib.nested( mock.patch('datagrid_gtk3.utils.imageutils.Image.open'), mock.patch.object(image, 'thumbnail')) as (open_, thumbnail): open_.return_value = image self.assertIsInstance( self._transform('image', 'file:///xxx'), GdkPixbuf.Pixbuf) thumbnail.assert_called_once_with((123, 123), Image.BICUBIC) open_.assert_called_once_with('/xxx') # This is because of a PIL issue. See # datagrid_gtk3.utils.transformations.image_transform for more # details self.assertEqual(add_border.call_count, 1) self.assertEqual(add_drop_shadow.call_count, 0)
def test_image_transform_without_border(self, add_border, add_drop_shadow): """Make sure the right functions are called to transform the image.""" image = Image.open(imageutils.get_icon_filename(['unknown'], 48)) image.load() add_border.return_value = image add_drop_shadow.return_value = image self.datagrid_model.image_max_size = 123 self.datagrid_model.image_draw_border = False self.datagrid_model.image_load_on_thread = False with contextlib.nested( mock.patch('datagrid_gtk3.utils.imageutils.Image.open'), mock.patch.object(image, 'thumbnail')) as (open_, thumbnail): open_.return_value = image self.assertIsInstance(self._transform('image', 'file:///xxx'), GdkPixbuf.Pixbuf) thumbnail.assert_called_once_with((123, 123), Image.BICUBIC) open_.assert_called_once_with('/xxx') # This is because of a PIL issue. See # datagrid_gtk3.utils.transformations.image_transform for more # details self.assertEqual(add_border.call_count, 1) self.assertEqual(add_drop_shadow.call_count, 0)
def test_image_transform_with_border(self): """Make sure the right functions are called to transform the image.""" image = Image.open(imageutils.get_icon_filename(['image'], 48)) image.load() _add_border_func = imageutils.add_border def _add_border(*args, **kwargs): _add_border_func(*args, **kwargs) return image _add_drop_shadow_func = imageutils.add_drop_shadow def _add_drop_shadow(*args, **kwargs): _add_drop_shadow_func(*args, **kwargs) return image cm = imageutils.ImageCacheManager.get_default() self.datagrid_model.image_draw_border = True self.datagrid_model.image_load_on_thread = False self.datagrid_model.image_max_size = 123 with contextlib.nested( mock.patch('datagrid_gtk3.utils.imageutils.add_drop_shadow'), mock.patch('datagrid_gtk3.utils.imageutils.add_border'), mock.patch('datagrid_gtk3.utils.imageutils.Image.open'), mock.patch.object(image, 'thumbnail')) as (add_drop_shadow, add_border, open_, thumbnail): add_border.side_effect = _add_border add_drop_shadow.side_effect = _add_drop_shadow open_.return_value = image self.assertIsInstance(self._transform('image', 'file:///xxx'), GdkPixbuf.Pixbuf) thumbnail.assert_called_once_with((123, 123), Image.BICUBIC) open_.assert_called_once_with('/xxx') add_border.assert_called_once_with( image, border_size=cm.IMAGE_BORDER_SIZE) add_drop_shadow.assert_called_once_with( image, border_size=cm.IMAGE_BORDER_SIZE, offset=(cm.IMAGE_SHADOW_OFFSET, cm.IMAGE_SHADOW_OFFSET))
def test_image_transform_with_border(self): """Make sure the right functions are called to transform the image.""" image = Image.open(imageutils.get_icon_filename(['image'], 48)) image.load() _add_border_func = imageutils.add_border def _add_border(*args, **kwargs): _add_border_func(*args, **kwargs) return image _add_drop_shadow_func = imageutils.add_drop_shadow def _add_drop_shadow(*args, **kwargs): _add_drop_shadow_func(*args, **kwargs) return image cm = imageutils.ImageCacheManager.get_default() self.datagrid_model.image_draw_border = True self.datagrid_model.image_load_on_thread = False self.datagrid_model.image_max_size = 123 with contextlib.nested( mock.patch('datagrid_gtk3.utils.imageutils.add_drop_shadow'), mock.patch('datagrid_gtk3.utils.imageutils.add_border'), mock.patch('datagrid_gtk3.utils.imageutils.Image.open'), mock.patch.object(image, 'thumbnail')) as ( add_drop_shadow, add_border, open_, thumbnail): add_border.side_effect = _add_border add_drop_shadow.side_effect = _add_drop_shadow open_.return_value = image self.assertIsInstance( self._transform('image', 'file:///xxx'), GdkPixbuf.Pixbuf) thumbnail.assert_called_once_with((123, 123), Image.BICUBIC) open_.assert_called_once_with('/xxx') add_border.assert_called_once_with( image, border_size=cm.IMAGE_BORDER_SIZE) add_drop_shadow.assert_called_once_with( image, border_size=cm.IMAGE_BORDER_SIZE, offset=(cm.IMAGE_SHADOW_OFFSET, cm.IMAGE_SHADOW_OFFSET))
from contextlib import closing import sqlite3 import tempfile from datagrid_gtk3.utils.imageutils import get_icon_filename TEST_DATA = { 'people': { 'metadata': [('__id', 'INTEGER PRIMARY KEY'), ('first_name', 'TEXT'), ('last_name', 'TEXT'), ('age', 'INTEGER'), ('start_date', 'INTEGER'), ('image_path', 'TEXT')], 'data': [ (1, 'Dee', 'Timberlake', 30, 1286755200, 'file://' + get_icon_filename(['image'], 48)), (2, 'Steve', 'Austin', 35, 1318291200, 'file://' + get_icon_filename(['calendar'], 48)), (3, 'Oscar', 'Goldman', 50, 1349913600, None), (4, 'Monica', 'Goldman', 40, 1344953660, None), ] }, 'files': { 'metadata': [ ('__id', 'TEXT PRIMARY KEY'), ('__parent', 'TEXT'), ('filename', 'TEXT'), ('flatname', 'TEXT'), ('children_len', 'INTEGER'), ], 'data': [ # The structure here is: # file-0
from datagrid_gtk3.utils.imageutils import get_icon_filename TEST_DATA = { 'people': { 'metadata': [ ('__id', 'INTEGER PRIMARY KEY'), ('first_name', 'TEXT'), ('last_name', 'TEXT'), ('age', 'INTEGER'), ('start_date', 'INTEGER'), ('image_path', 'TEXT') ], 'data': [ (1, 'Dee', 'Timberlake', 30, 1286755200, 'file://' + get_icon_filename(['image'], 48)), (2, 'Steve', 'Austin', 35, 1318291200, 'file://' + get_icon_filename(['calendar'], 48)), (3, 'Oscar', 'Goldman', 50, 1349913600, None), (4, 'Monica', 'Goldman', 40, 1344953660, None), ] }, 'files': { 'metadata': [ ('__id', 'TEXT PRIMARY KEY'), ('__parent', 'TEXT'), ('filename', 'TEXT'), ('flatname', 'TEXT'), ('children_len', 'INTEGER'), ], 'data': [