[kupu-checkins] r46429 - in kupu/trunk/kupu/plone: . tests tests/output

duncan at codespeak.net duncan at codespeak.net
Mon Sep 10 09:37:37 CEST 2007


Author: duncan
Date: Mon Sep 10 09:37:36 2007
New Revision: 46429

Modified:
   kupu/trunk/kupu/plone/html2captioned.py
   kupu/trunk/kupu/plone/tests/output/linked.out
   kupu/trunk/kupu/plone/tests/output/notquoted.out
   kupu/trunk/kupu/plone/tests/output/simple.out
   kupu/trunk/kupu/plone/tests/test_html2captioned.py
Log:
Fixing some broken tests - still two broken :(

Modified: kupu/trunk/kupu/plone/html2captioned.py
==============================================================================
--- kupu/trunk/kupu/plone/html2captioned.py	(original)
+++ kupu/trunk/kupu/plone/html2captioned.py	Mon Sep 10 09:37:36 2007
@@ -37,6 +37,7 @@
 ATTR_VALUE = '=(?:"?)(?P<%s>(?<=")[^"]*|[^ \/>]*)'
 ATTR_CLASS = ATTR_VALUE % 'class'
 ATTR_WIDTH = ATTR_VALUE % 'width'
+ATTR_HEIGHT = ATTR_VALUE % 'height'
 ATTR_ALT = ATTR_VALUE % 'alt'
 
 ATTR_PATTERN = re.compile('''
@@ -45,9 +46,10 @@
      | src\s*=\s*"resolveuid/(?P<src>([^/"#? ]*))
      | width%s
      | alt%s
+     | height%s
      | .
      )*\>
-    )''' % (ATTR_CLASS, ATTR_WIDTH, ATTR_ALT), re.VERBOSE | re.IGNORECASE | re.DOTALL)
+    )''' % (ATTR_CLASS, ATTR_WIDTH, ATTR_ALT, ATTR_HEIGHT), re.VERBOSE | re.IGNORECASE | re.DOTALL)
 SRC_TAIL = re.compile(r'/([^" \/>]+)')
 
 CLASS_PATTERN = re.compile('\s*class\s*=\s*("[^"]*captioned[^"]*"|[^" \/>]+)')

Modified: kupu/trunk/kupu/plone/tests/output/linked.out
==============================================================================
--- kupu/trunk/kupu/plone/tests/output/linked.out	(original)
+++ kupu/trunk/kupu/plone/tests/output/linked.out	Mon Sep 10 09:37:36 2007
@@ -1,9 +1,9 @@
 <div>Simple text containing an embedded image</div>
-<div class="image-left captioned" style="width:120px;">
- <div style="width:120px;">
+<dl class="image-left captioned">
+ <dt>
   <a href="xyzzy" class="link"><img height="144" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]" width="120" alt="image 104ede98d4c7c8eaeaa3b984f7395979"/></a>
- </div>
- <div class="image-caption">
+ </dt>
+ <dd class="image-caption" style="width:120px">
   Test image caption
- </div>
+ </dd>
 </div>

Modified: kupu/trunk/kupu/plone/tests/output/notquoted.out
==============================================================================
--- kupu/trunk/kupu/plone/tests/output/notquoted.out	(original)
+++ kupu/trunk/kupu/plone/tests/output/notquoted.out	Mon Sep 10 09:37:36 2007
@@ -1,13 +1,13 @@
 <div>IE doesn't always quote attributes</div>
-<div class="image-left captioned" style="width:120px;">
-  <div style="width:120px;">
-    <img height=144 src="[url for 104ede98d4c7c8eaeaa3b984f7395979]" width=120 alt="image 104ede98d4c7c8eaeaa3b984f7395979"/>
-  </div>
-  <div class="image-caption">Test image caption</div>
-</div>
-<div class="captioned" style="width:120px;">
-  <div style="width:120px;">
-    <img height=144 src="[url for 104ede98d4c7c8eaeaa3b984f7395979]" width=120 alt="image 104ede98d4c7c8eaeaa3b984f7395979"/>
-  </div>
-  <div class="image-caption">Test image caption</div>
-</div>
+<dl class="image-left captioned">
+  <dt>
+    <img height="144" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]" width="120" alt="image 104ede98d4c7c8eaeaa3b984f7395979"/>
+  </dt>
+  <dd class="image-caption" style="width:120px">Test image caption</dd>
+</dl>
+<dl class="captioned">
+  <dt>
+    <img height="144" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]" width="120" alt="image 104ede98d4c7c8eaeaa3b984f7395979"/>
+  </dt>
+  <dd class="image-caption" style="width:120px">Test image caption</dd>
+</dl>

Modified: kupu/trunk/kupu/plone/tests/output/simple.out
==============================================================================
--- kupu/trunk/kupu/plone/tests/output/simple.out	(original)
+++ kupu/trunk/kupu/plone/tests/output/simple.out	Mon Sep 10 09:37:36 2007
@@ -1,16 +1,16 @@
 <div>Simple text containing an embedded image</div>
-<div class="image-left captioned" style="width:120px;">
-  <div style="width:120px;"><img height="144" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]" width="120" alt="image 104ede98d4c7c8eaeaa3b984f7395979"/>
-  </div>
-  <div class="image-caption">Test image caption</div>
-</div>
-<div class="image-left captioned" style="width:20px;">
-  <div style="width:20px;"><img height="144" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]/image_thumb" alt="image 104ede98d4c7c8eaeaa3b984f7395979"/>
-  </div>
-  <div class="image-caption">Test image caption</div>
-</div>
-<div class="image-left captioned" style="width:600px;">
-  <div style="width:600px;"><img height="144" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]" alt="image 104ede98d4c7c8eaeaa3b984f7395979"/>
-  </div>
-  <div class="image-caption">Test image caption</div>
-</div>
+<dl class="image-left captioned">
+  <dt><img height="144" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]" width="120" alt="image 104ede98d4c7c8eaeaa3b984f7395979"/>
+  </dt>
+  <dd class="image-caption" style="width:120px">Test image caption</dd>
+</dl>
+<dl class="image-left captioned">
+  <dt><img height="144" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]/image_thumb" width="20" alt="image 104ede98d4c7c8eaeaa3b984f7395979"/>
+  </dt>
+  <dd class="image-caption" style="width:20px">Test image caption</dd>
+</dl>
+<dl class="image-left captioned">
+  <dt><img height="144" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]" width="600" alt="image 104ede98d4c7c8eaeaa3b984f7395979"/>
+  </dt>
+  <dd class="image-caption" style="width:600px">Test image caption</dd>
+</dl>

Modified: kupu/trunk/kupu/plone/tests/test_html2captioned.py
==============================================================================
--- kupu/trunk/kupu/plone/tests/test_html2captioned.py	(original)
+++ kupu/trunk/kupu/plone/tests/test_html2captioned.py	Mon Sep 10 09:37:36 2007
@@ -8,6 +8,7 @@
 
 from Products.PortalTransforms.tests.test_transforms import *
 from Products.PortalTransforms.tests.utils import normalize_html
+from Products.kupu import kupu_globals
 
 PREFIX = abspath(dirname(__file__))
 
@@ -26,14 +27,11 @@
 ('Products.kupu.plone.html2captioned', "linked.in", "linked.out", normalize_html, 0),
     )
 
-class MockSubImage:
-    def getWidth(self):
-        return 20
-
 class MockImage:
     def __init__(self, uid, description):
         self.uid, self.description = uid, description
-        self.image_thumb = MockSubImage()
+        if not uid.startswith('SUB:'):
+            self.image_thumb = MockSubImage(self)
 
     def Title(self):
         return 'image '+self.uid
@@ -45,6 +43,22 @@
         return '[url for %s]' % self.uid
     def getWidth(self):
         return 600
+    def tag(self, height="", width="", **kw):
+        src = self.absolute_url_path()
+        alt = self.Title()
+        if not width:
+            width = self.getWidth()
+        return '<img height="%s" src="%s" width="%s" alt="%s"/>' % (height, src, width, alt)
+
+class MockSubImage(MockImage):
+    def __init__(self, parent):
+        self.uid = parent.uid
+        self.description = parent.description
+
+    def getWidth(self):
+        return 20
+    def absolute_url_path(self):
+        return '[url for %s]' % self.uid+'/image_thumb'
 
 class MockCatalogTool:
     def lookupObject(self, uid):
@@ -59,11 +73,43 @@
 class MockArchetypeTool:
     reference_catalog = MockCatalogTool()
 
+def mockPageTemplate(self, **kw):
+    """Acquisition isn't set up correctly for us to use a real PageTemplateFile,
+    so for the test we just use string formatting.
+    """
+    caption = kw.get('caption', '!caption!')
+    image = kw.get('image', None)
+    fullimage = kw.get('fullimage', None)
+    Class=kw['class']
+    width = kw['width']
+    owidth = fullimage.getWidth()
+    if width is None:
+        kw['width'] = width = image.getWidth()
+    href = fullimage.absolute_url_path()
+    tag = image.tag(**kw)
+
+    #if width==owidth:
+    TEMPLATE = '''<dl class="%(Class)s">
+    <dt>%(tag)s</dt>
+    <dd class="image-caption" style="width:%(width)spx">%(caption)s</dd>
+    </dl>'''
+    #else:
+    #    TEMPLATE = '''<dl class="%(Class)s">
+    #    <dt><a rel="lightbox" href="%(href)s">%(tag)s</a></dt>
+    #    <dd class="image-caption" style="width:%(width)spx">%(caption)s</dd>
+    #    </dl>'''
+        
+    return TEMPLATE % dict(
+        caption=caption, Class=Class, href=href, width=width, tag=tag)
+
 class MockPortal:
     # Mock portal class: just enough to let me think I can lookup a
     # Description for an image from its UID.
     archetype_tool = MockArchetypeTool()
 
+    # Also now needs access to the captioning template
+    kupu_captioned_image = mockPageTemplate
+
 class TransformTest(TestCase):
     portal = MockPortal()
     


More information about the kupu-checkins mailing list