[Checkins] SVN: z3c.pt.compat/trunk/s Preparing new release due to file missing from commit.

Malthe Borch mborch at gmail.com
Thu Oct 2 15:51:21 EDT 2008


Log message for revision 91675:
  Preparing new release due to file missing from commit.

Changed:
  U   z3c.pt.compat/trunk/setup.py
  A   z3c.pt.compat/trunk/src/z3c/pt/compat/testing.py

-=-
Modified: z3c.pt.compat/trunk/setup.py
===================================================================
--- z3c.pt.compat/trunk/setup.py	2008-10-02 19:48:47 UTC (rev 91674)
+++ z3c.pt.compat/trunk/setup.py	2008-10-02 19:51:21 UTC (rev 91675)
@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 import sys, os
 
-version = '0.2'
+version = '0.3'
 
 setup(name='z3c.pt.compat',
       version=version,

Added: z3c.pt.compat/trunk/src/z3c/pt/compat/testing.py
===================================================================
--- z3c.pt.compat/trunk/src/z3c/pt/compat/testing.py	                        (rev 0)
+++ z3c.pt.compat/trunk/src/z3c/pt/compat/testing.py	2008-10-02 19:51:21 UTC (rev 91675)
@@ -0,0 +1,59 @@
+import doctest
+
+import lxml.etree
+import lxml.doctestcompare
+
+import re
+
+class OutputChecker(lxml.doctestcompare.LHTMLOutputChecker):
+    """Doctest output checker which is better equippied to identify
+    HTML markup than the checker from the ``lxml.doctestcompare``
+    module. It also uses the text comparison function from the
+    built-in ``doctest`` module to allow the use of ellipsis."""
+    
+    _repr_re = re.compile(r'^<([A-Z]|[^>]+ (at|object) |[a-z]+ \'[A-Za-z0-9_.]+\'>)')
+    
+    def _looks_like_markup(self, s):
+        s = s.replace('<BLANKLINE>', '\n').strip()
+        return (s.startswith('<')
+                and not self._repr_re.search(s))
+
+    def text_compare(self, want, got, strip):
+        if want is None: want = ""
+        if got is None: got = ""
+        checker = doctest.OutputChecker()
+        return checker.check_output(
+            want, got, doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
+
+def render(view, xpath='.'):
+    method = getattr(view, 'render', None)
+    if method is None:
+        method = view.__call__
+
+    string = method()
+    if string == "":
+        return string
+
+    try:
+        root = lxml.etree.fromstring(string)
+    except lxml.etree.XMLSyntaxError:
+        root = lxml.html.fromstring(string)
+        
+    output = ""
+    for node in root.xpath(
+        xpath, namespaces={'xmlns': 'http://www.w3.org/1999/xhtml'}):
+        s = lxml.etree.tounicode(node, pretty_print=True)
+        s = s.replace(' xmlns="http://www.w3.org/1999/xhtml"', ' ')
+        output += s
+
+    if not output:
+        raise ValueError("No elements matched by %s." % repr(xpath))
+
+    # let's get rid of blank lines
+    output = output.replace('\n\n', '\n')
+
+    # self-closing tags are more readable with a space before the
+    # end-of-tag marker
+    output = output.replace('"/>', '" />')
+
+    return output



More information about the Checkins mailing list