[Zope3-checkins] CVS: zopeproducts/photo/tests - __init__.py:1.1
test_iimageresizeutility.py:1.1
test_imagemagickutility.py:1.1 test_photo.py:1.1
test_pilimageutility.py:1.1 test_size.py:1.1
Bjorn Tillenius
bjorn at codeworks.lt
Fri Aug 15 09:11:03 EDT 2003
Update of /cvs-repository/zopeproducts/photo/tests
In directory cvs.zope.org:/tmp/cvs-serv25590/tests
Added Files:
__init__.py test_iimageresizeutility.py
test_imagemagickutility.py test_photo.py
test_pilimageutility.py test_size.py
Log Message:
First checkin of the photo product.
This is intended to be similar to the photo product in Zope 2. It's not
quite finished yet, though it's already usable. Read the README for more
information.
=== Added File zopeproducts/photo/tests/__init__.py ===
=== Added File zopeproducts/photo/tests/test_iimageresizeutility.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Unit tests for IImageResizeUtility
Use TestIImageResizeUtility as a base class if writing a test for a class
which implements IImageResizeUtility.
Define a function _makeImageResizer(self) which creates the
ImageResizeUtility object.
"""
import unittest
from zope.app.content.image import Image
from zope.app.content.tests.test_image import zptlogo
from zope.interface.verify import verifyObject
from zopeproducts.photo.interfaces import IImageResizeUtility
testImage = Image(zptlogo)
class TestIImageResizeUtility(unittest.TestCase):
def test_implementation(self):
im_resizer = self._makeImageResizer()
verifyObject(IImageResizeUtility, im_resizer)
def test_resizeDontKeepAspect(self):
im_resizer = self._makeImageResizer()
image = im_resizer.resize(testImage, (30, 40), False)
self.assertEqual(image.getImageSize(), (30, 40))
image = im_resizer.resize(testImage, (40, 30), False)
self.assertEqual(image.getImageSize(), (40, 30))
def test_resizeKeepAspect(self):
im_resizer = self._makeImageResizer()
image = im_resizer.resize(testImage, (30, 40), True)
self.assertEqual(image.getImageSize(), (30, 30))
image = im_resizer.resize(testImage, (40, 30), True)
self.assertEqual(image.getImageSize(), (30, 30))
def test_suite():
return unittest.TestSuite() # Deliberately empty
=== Added File zopeproducts/photo/tests/test_imagemagickutility.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Unit tests for ImageMagickUtility
$Id: test_imagemagickutility.py,v 1.1 2003/08/15 12:10:56 BjornT Exp $
"""
import unittest
from zope.interface.verify import verifyObject
from zopeproducts.photo.utilities import ImageMagickUtility
from zopeproducts.photo.interfaces import IImageMagickUtility
from zopeproducts.photo.tests.test_iimageresizeutility import \
TestIImageResizeUtility
class TestImageMagickUtility(TestIImageResizeUtility):
def _makeImageResizer(self):
return ImageMagickUtility()
def test_implementation(self):
utility = ImageMagickUtility()
verifyObject(IImageMagickUtility, utility)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestImageMagickUtility))
return suite
if __name__ == '__main__':
unittest.main()
=== Added File zopeproducts/photo/tests/test_photo.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Unit tests for the Photo class
$Id: test_photo.py,v 1.1 2003/08/15 12:10:56 BjornT Exp $
"""
import unittest
from zope.app.container.sample import SampleContainer
from zope.app.container.tests.test_icontainer import BaseTestIContainer
from zope.app.container.tests.test_icontainer import DefaultTestData
from zope.app.content.tests.test_image import zptlogo
from zope.app.content.image import Image
from zope.app.interfaces.dublincore import ICMFDublinCore
from zope.component.adapter import provideAdapter
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.interface import implements
from zope.interface.verify import verifyObject
from zope.app import zapi
from zopeproducts.photo.interfaces import IPhoto, IPhotoContainer
from zopeproducts.photo.interfaces import IImageResizeUtility
from zopeproducts.photo import Photo, defaultImageResizer
small_image = Image(zptlogo)
class ImageResizeStub:
implements(IImageResizeUtility)
def resize(self, image, size, keep_aspect=True):
return small_image
class PhotoContainer(SampleContainer):
implements(IPhotoContainer)
currentDisplayId = 'small'
resizeUtility = defaultImageResizer
class DublinCoreStub:
def __call__(self, photo):
return self
title = ''
description = ''
dublinCoreStub = DublinCoreStub()
class TestPhoto(PlacefulSetup, BaseTestIContainer, unittest.TestCase):
def setUp(self):
PlacefulSetup.setUp(self)
provideAdapter(IPhoto, ICMFDublinCore, dublinCoreStub)
us = zapi.getService(self, 'Utilities')
us.provideUtility(IImageResizeUtility, ImageResizeStub(),
defaultImageResizer)
def makeTestObject(self):
return Photo()
def getUnknownKey(self):
return 'm'
def getBadKeyTypes(self):
return [None, ['foo'], 1, '\xf3abc']
def makeTestData(self):
return DefaultTestData()
def _makeContextPhotoInsidePc(self):
# Makes a photo inside a PhotoContainer and context wraps it
self.createRootFolder()
pc = PhotoContainer()
ph = zapi.ContextWrapper(Photo(), pc)
pc.setObject('a', ph)
pc = zapi.ContextWrapper(pc, self.rootFolder)
self.rootFolder.setObject('pc', pc)
photo = zapi.traverseName(pc, 'a')
return photo
def test_interface(self):
photo = self._makeContextPhotoInsidePc()
verifyObject(IPhoto, photo)
def test_title(self):
photo = Photo()
self.assertEqual(u'', photo.title)
photo.title = u'A Title'
self.assertEqual(u'A Title', photo.title)
def test_data(self):
photo = Photo()
self.assertEqual(photo.data, '')
photo.data = zptlogo
self.assertEqual(photo.data, zptlogo)
def test_currentDisplayId(self):
photo = self._makeContextPhotoInsidePc()
photo.useParentOptions = False
photo.currentDisplayId = 'original'
self.assertEqual(photo.currentDisplayId, 'original')
photo.currentDisplayId = 'not a display id'
self.assertEqual(photo.currentDisplayId, 'original')
photo.useParentOptions = True
self.assertEqual(photo.currentDisplayId, 'small')
def test_description(self):
photo = Photo()
self.assertEqual(u'', photo.description)
photo.description = u'A Description'
self.assertEqual(u'A Description', photo.description)
def test_getDisplayIds(self):
photo = Photo()
self.assert_('thumbnail' in photo.getDisplayIds())
photo = Photo()
photo.data = zptlogo
self.assert_('original' in photo.getDisplayIds())
def test_getImage(self):
photo = self._makeContextPhotoInsidePc()
photo.data = zptlogo
org = photo.getImage('original')
self.assertEqual(org.data, zptlogo)
self.assertEqual(photo.getImage('not a display id'), None)
im = photo.getImage('small')
self.assertEqual(small_image.getImageSize(), im.getImageSize())
def test_getDisplaySize(self):
photo = Photo()
photo.data = zptlogo
im = Image(zptlogo)
self.assertEqual(photo.getDisplaySize('original'), im.getImageSize())
self.assertEqual(photo.getDisplaySize('not a display id'), None)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestPhoto))
return suite
if __name__ == '__main__':
unittest.main()
=== Added File zopeproducts/photo/tests/test_pilimageutility.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Unit tests for PILImageUtility
$Id: test_pilimageutility.py,v 1.1 2003/08/15 12:10:56 BjornT Exp $
"""
import unittest
from zope.interface.verify import verifyObject
from zopeproducts.photo.utilities import PILImageUtility
from zopeproducts.photo.interfaces import IPILImageUtility
from zopeproducts.photo.tests.test_iimageresizeutility import \
TestIImageResizeUtility
class TestPILImageUtility(TestIImageResizeUtility):
def _makeImageResizer(self):
return PILImageUtility()
def test_implementation(self):
utility = PILImageUtility()
verifyObject(IPILImageUtility, utility)
def test_getNewSizeKeepAspect(self):
util = PILImageUtility()
self.assertEqual(util._getNewSize((10, 10), (25, 50), 1),
(25, 25))
self.assertEqual(util._getNewSize((10, 10), (50, 25), 1),
(25, 25))
self.assertEqual(util._getNewSize((50, 50), (25, 50), 1),
(25, 25))
self.assertEqual(util._getNewSize((50, 50), (50, 25), 1),
(25, 25))
def test_getNewSizeDontKeepAspect(self):
util = PILImageUtility()
self.assertEqual(util._getNewSize((10, 10), (25, 50), 0),
(25, 50))
self.assertEqual(util._getNewSize((10, 10), (50, 25), 0),
(50, 25))
self.assertEqual(util._getNewSize((50, 50), (25, 50), 0),
(25, 50))
self.assertEqual(util._getNewSize((50, 50), (50, 25), 0),
(50, 25))
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestPILImageUtility))
return suite
if __name__ == '__main__':
unittest.main()
=== Added File zopeproducts/photo/tests/test_size.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Unit tests for PhotoSized
$Id: test_size.py,v 1.1 2003/08/15 12:10:56 BjornT Exp $
"""
import unittest
from zope.app.content.tests.test_image import zptlogo
from zopeproducts.photo import Photo, PhotoSized
class TestPhotoSized(unittest.TestCase):
def test_sizeForSorting(self):
size = PhotoSized(Photo())
self.assertEqual(size.sizeForSorting(), ('byte', 0))
photo = Photo()
photo.data = zptlogo
size = PhotoSized(photo)
self.assertEqual(size.sizeForSorting(),
('byte', photo.getImage('original').getSize()))
def test_sizeForDisplay(self):
size = PhotoSized(Photo())
self.assertEqual(size.sizeForDisplay(), "")
photo = Photo()
photo.data = zptlogo
x, y = photo.getImage('original').getImageSize()
imsize = photo.getImage('original').getSize()
size = PhotoSized(photo)
self.assertEqual(size.sizeForDisplay(),
'${size} ${unit} ${x}x${y}')
self.assertEqual(size.sizeForDisplay().mapping,
{'size': imsize, 'unit': 'bytes',
'x': x, 'y': y})
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestPhotoSized))
return suite
if __name__ == '__main__':
unittest.main()
More information about the Zope3-Checkins
mailing list