[Lxml-checkins] r43967 - lxml/branch/html/src/lxml

ianb at codespeak.net ianb at codespeak.net
Fri Jun 1 08:34:17 CEST 2007


Author: ianb
Date: Fri Jun  1 08:34:17 2007
New Revision: 43967

Modified:
   lxml/branch/html/src/lxml/doctestcompare.py
Log:
normalize whitespace before comparing text

Modified: lxml/branch/html/src/lxml/doctestcompare.py
==============================================================================
--- lxml/branch/html/src/lxml/doctestcompare.py	(original)
+++ lxml/branch/html/src/lxml/doctestcompare.py	Fri Jun  1 08:34:17 2007
@@ -45,8 +45,12 @@
     else:
         return v.strip()
 
+def norm_whitespace(v):
+    return _norm_whitespace_re.sub(' ', v)
+
 # We use this to distinguish repr()s from elements:
 _repr_re = re.compile(r'^<[^>]+ (at|object) ')
+_norm_whitespace_re = re.compile(r'[ \t\n][ \t\n]+')
 
 class LXMLOutputChecker(OutputChecker):
 
@@ -130,8 +134,8 @@
         want = want or ''
         got = got or ''
         if strip:
-            want = want.strip()
-            got = got.strip()
+            want = norm_whitespace(want).strip()
+            got = norm_whitespace(got).strip()
         want = '^%s$' % re.escape(want)
         want = want.replace(r'\.\.\.', '.*')
         if re.search(want, got):


More information about the lxml-checkins mailing list