[Zope3-checkins] CVS: Zope3/src/zope/app/content/tests - test_image.py:1.3

Steve Alexander steve@cat-box.net
Fri, 27 Dec 2002 14:19:40 -0500


Update of /cvs-repository/Zope3/src/zope/app/content/tests
In directory cvs.zope.org:/tmp/cvs-serv14961/src/zope/app/content/tests

Modified Files:
	test_image.py 
Log Message:
implemented a useful ISized adapter for images, which gives you the
size in bytes, and the width and height, and sorts on size in bytes.


=== Zope3/src/zope/app/content/tests/test_image.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/content/tests/test_image.py:1.2	Wed Dec 25 09:12:48 2002
+++ Zope3/src/zope/app/content/tests/test_image.py	Fri Dec 27 14:19:09 2002
@@ -19,7 +19,7 @@
 import unittest
 from zope.interface.verify import verifyClass
 
-class Test(unittest.TestCase):
+class TestImage(unittest.TestCase):
 
     def _makeImage(self, *args, **kw):
         from zope.app.content.image import Image
@@ -59,8 +59,46 @@
         self.failUnless(IImage.isImplementedByInstancesOf(Image))
         self.failUnless(verifyClass(IImage, Image))
 
+
+class DummyImage:
+
+    def __init__(self, width, height, bytes):
+        self.width = width
+        self.height = height
+        self.bytes = bytes
+
+    def getSize(self):
+        return self.bytes
+
+    def getImageSize(self):
+        return self.width, self.height
+
+
+class TestSized(unittest.TestCase):
+
+    def testInterface(self):
+        from zope.app.interfaces.size import ISized
+        from zope.app.content.image import ImageSized
+        self.failUnless(ISized.isImplementedByInstancesOf(ImageSized))
+        self.failUnless(verifyClass(ISized, ImageSized))
+
+    def test_zeroSized(self):
+        from zope.app.content.image import ImageSized
+        s = ImageSized(DummyImage(0, 0, 0))
+        self.assertEqual(s.sizeForSorting(), ('byte', 0))
+        self.assertEqual(s.sizeForDisplay(), u'0 KB 0x0')
+
+
+    def test_arbitrarySize(self):
+        from zope.app.content.image import ImageSized
+        s = ImageSized(DummyImage(34, 56, 78))
+        self.assertEqual(s.sizeForSorting(), ('byte', 78))
+        self.assertEqual(s.sizeForDisplay(), u'1 KB 34x56')
+
 def test_suite():
-    return unittest.makeSuite(Test)
+    return unittest.TestSuite((unittest.makeSuite(TestImage),
+                               unittest.makeSuite(TestSized)
+                             ))
 
 if __name__=='__main__':
     unittest.TextTestRunner().run(test_suite())