Skip to content

Commit

Permalink
Updated package to z3c.pt 1.0b1 (now Chameleon-based).
Browse files Browse the repository at this point in the history
  • Loading branch information
malthe committed Oct 2, 2008
1 parent 8c2a2dc commit 76e9659
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 55 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -5,6 +5,9 @@ CHANGES
Version 2.0.0 (2008-??-??)
--------------------------

- Updated package to work with ``z3c.pt`` version 1.0b1 (which is
now based on the Chameleon template compiler). [malthe]

- Feature: Added support in the file upload widget's testing flavor to specify
'base64'-encoded strings in the hidden text area, so that binary data can be
uploaded as well.
Expand Down
8 changes: 4 additions & 4 deletions buildout.cfg
Expand Up @@ -9,8 +9,8 @@ lxml = 2.1.1
zope.app.locales = 3.4.5

[test-environment]
Z3C_PT_DEBUG = False
Z3C_PT_CACHE = False
CHAMELEON_DEBUG = False
CHAMELEON_CACHE = False

[test]
recipe = zc.recipe.testrunner
Expand Down Expand Up @@ -57,5 +57,5 @@ eggs =
defaults = ['-m', 'benchmark']

[benchmark-environment]
Z3C_PT_DEBUG = False
Z3C_PT_CACHE = True
CHAMELEON_DEBUG = False
CHAMELEON_CACHE = True
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -82,7 +82,7 @@ def read(*rnames):
'zope.testing',
'z3c.coverage',
'z3c.template',
'z3c.pt',
'z3c.pt >= 1.0b1',
'lxml',
],
adding = ['zope.app.container'],
Expand All @@ -104,7 +104,7 @@ def read(*rnames):
'zope.schema',
'zope.security',
'zope.traversing',
'z3c.pt.compat',
'z3c.pt.compat >= 0.3',
],
dependency_links = ['http://download.zope.org/distribution'],
zip_safe = False,
Expand Down
52 changes: 3 additions & 49 deletions src/z3c/form/testing.py
Expand Up @@ -40,6 +40,9 @@
from z3c.form.browser import radio, select, text, textarea
from z3c.form.browser import file as fileWidget

from z3c.pt.compat.testing import render
from z3c.pt.compat.testing import OutputChecker

import z3c.pt.compat

import lxml.html
Expand All @@ -65,26 +68,6 @@ def toFieldValue(self, value):

return super(TestingFileUploadDataConverter, self).toFieldValue(value)

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)

class TestRequest(TestRequest):
zope.interface.implements(interfaces.IFormLayer)

Expand Down Expand Up @@ -118,35 +101,6 @@ def checkPermission(self, permission, object):
return True
return False

def render(view, xpath='.'):
string = view.render()
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

def getPath(filename):
return os.path.join(os.path.dirname(browser.__file__), filename)

Expand Down

0 comments on commit 76e9659

Please sign in to comment.