[Lxml-checkins] r44048 - in lxml/branch/html/src/lxml: . html
ianb at codespeak.net
ianb at codespeak.net
Wed Jun 6 10:08:24 CEST 2007
Author: ianb
Date: Wed Jun 6 10:08:23 2007
New Revision: 44048
Modified:
lxml/branch/html/src/lxml/doctestcompare.py
lxml/branch/html/src/lxml/html/usedoctest.py
lxml/branch/html/src/lxml/usedoctest.py
Log:
show comments properly. Remove the usedoctest modules after they are used, so they can be usefully reimported later.
Modified: lxml/branch/html/src/lxml/doctestcompare.py
==============================================================================
--- lxml/branch/html/src/lxml/doctestcompare.py (original)
+++ lxml/branch/html/src/lxml/doctestcompare.py Wed Jun 6 10:08:23 2007
@@ -228,6 +228,9 @@
def format_tag(self, el):
attrs = []
+ if isinstance(el, etree.CommentBase):
+ # FIXME: probably PIs should be handled specially too?
+ return '<!--'
for name, value in sorted(el.attrib.items()):
attrs.append('%s="%s"' % (name, self.format_text(value, False)))
if not attrs:
@@ -235,6 +238,9 @@
return '<%s %s>' % (el.tag, ' '.join(attrs))
def format_end_tag(self, el):
+ if isinstance(el, etree.CommentBase):
+ # FIXME: probably PIs should be handled specially too?
+ return '-->'
return '</%s>' % el.tag
def collect_diff(self, want, got, html, indent):
@@ -333,7 +339,7 @@
else:
doctest.OutputChecker = LXMLOutputChecker
-def temp_install(html=False):
+def temp_install(html=False, del_module=None):
"""
Use this *inside* a doctest to enable this checker for this
doctest only.
@@ -364,16 +370,19 @@
# in check_output that we care about:
doctest.etree = etree
_RestoreChecker(dt_self, old_checker, checker,
- check_func, checker.check_output.im_func)
+ check_func, checker.check_output.im_func,
+ del_module)
class _RestoreChecker(object):
- def __init__(self, dt_self, old_checker, new_checker, check_func, clone_func):
+ def __init__(self, dt_self, old_checker, new_checker, check_func, clone_func,
+ del_module):
self.dt_self = dt_self
self.checker = old_checker
self.checker._temp_call_super_check_output = self.call_super
self.checker._temp_override_self = new_checker
self.check_func = check_func
self.clone_func = clone_func
+ self.del_module = del_module
self.install_clone()
self.install_dt_self()
def install_clone(self):
@@ -387,12 +396,22 @@
self.dt_self._DocTestRunner__record_outcome = self
def uninstall_dt_self(self):
self.dt_self._DocTestRunner__record_outcome = self.prev_func
+ def uninstall_module(self):
+ if self.del_module:
+ import sys
+ del sys.modules[self.del_module]
+ if '.' in self.del_module:
+ package, module = self.del_module.rsplit('.', 1)
+ package_mod = sys.modules[package]
+ delattr(package_mod, module)
def __call__(self, *args, **kw):
self.uninstall_clone()
self.uninstall_dt_self()
del self.checker._temp_override_self
del self.checker._temp_call_super_check_output
- return self.prev_func(*args, **kw)
+ result = self.prev_func(*args, **kw)
+ self.uninstall_module()
+ return result
def call_super(self, *args, **kw):
self.uninstall_clone()
try:
Modified: lxml/branch/html/src/lxml/html/usedoctest.py
==============================================================================
--- lxml/branch/html/src/lxml/html/usedoctest.py (original)
+++ lxml/branch/html/src/lxml/html/usedoctest.py Wed Jun 6 10:08:23 2007
@@ -1,3 +1,3 @@
from lxml import doctestcompare
-doctestcompare.temp_install(html=True)
+doctestcompare.temp_install(html=True, del_module=__name__)
Modified: lxml/branch/html/src/lxml/usedoctest.py
==============================================================================
--- lxml/branch/html/src/lxml/usedoctest.py (original)
+++ lxml/branch/html/src/lxml/usedoctest.py Wed Jun 6 10:08:23 2007
@@ -1,3 +1,3 @@
from lxml import doctestcompare
-doctestcompare.temp_install()
+doctestcompare.temp_install(del_module=__name__)
More information about the lxml-checkins
mailing list