[Zope3-checkins] CVS: Zope3/src/zope/tal/tests - test_htmltalparser.py:1.1.2.3
Fred L. Drake, Jr.
fred@zope.com
Tue, 24 Dec 2002 10:30:26 -0500
Update of /cvs-repository/Zope3/src/zope/tal/tests
In directory cvs.zope.org:/tmp/cvs-serv28747
Modified Files:
Tag: NameGeddon-branch
test_htmltalparser.py
Log Message:
- TestCaseBase._get_check(): removed unused method
- test methods are now named "test_*"
=== Zope3/src/zope/tal/tests/test_htmltalparser.py 1.1.2.2 => 1.1.2.3 ===
--- Zope3/src/zope/tal/tests/test_htmltalparser.py:1.1.2.2 Mon Dec 23 15:38:28 2002
+++ Zope3/src/zope/tal/tests/test_htmltalparser.py Tue Dec 24 10:30:26 2002
@@ -19,7 +19,7 @@
import unittest
from zope.tal import htmltalparser
-from zope.tal.taldefs import TAL_VERSION, TALError, METALError
+from zope.tal import taldefs
from zope.tal.tests import utils
@@ -27,7 +27,7 @@
prologue = ""
epilogue = ""
- initial_program = [('version', TAL_VERSION), ('mode', 'html')]
+ initial_program = [('version', taldefs.TAL_VERSION), ('mode', 'html')]
final_program = []
def _merge(self, p1, p2):
@@ -53,14 +53,7 @@
"Macros:\n" + pprint.pformat(got_macros)
+ "\nExpected:\n" + pprint.pformat(macros))
- def _get_check(self, source, program=[], macros={}):
- parser = htmltalparser.HTMLTALParser()
- parser.parseString(source)
- got_program, got_macros = parser.getCode()
- pprint.pprint(got_program)
- pprint.pprint(got_macros)
-
- def _should_error(self, source, exc=TALError):
+ def _should_error(self, source, exc=taldefs.TALError):
def parse(self=self, source=source):
parser = htmltalparser.HTMLTALParser()
parser.parseString(self.prologue + source + self.epilogue)
@@ -77,13 +70,13 @@
class HTMLTALParserTestCases(TestCaseBase):
- def check_code_simple_identity(self):
+ def test_code_simple_identity(self):
self._run_check("""<html a='b' b="c" c=d><title>My Title</html>""", [
rawtext('<html a="b" b="c" c="d">'
'<title>My Title</title></html>'),
])
- def check_code_implied_list_closings(self):
+ def test_code_implied_list_closings(self):
self._run_check("""<ul><li><p><p><li></ul>""", [
rawtext('<ul><li><p></p><p></p></li><li></li></ul>'),
])
@@ -92,7 +85,7 @@
'<dd><ol><li></li><li></li></ol></dd></dl>'),
])
- def check_code_implied_table_closings(self):
+ def test_code_implied_table_closings(self):
self._run_check("""<p>text <table><tr><th>head\t<tr><td>cell\t"""
"""<table><tr><td>cell \n \t \n<tr>""", [
rawtext('<p>text</p> <table><tr><th>head</th>'
@@ -105,12 +98,12 @@
' </table></td></tr></table>'),
])
- def check_code_bad_nesting(self):
+ def test_code_bad_nesting(self):
def check(self=self):
self._run_check("<a><b></a></b>", [])
self.assertRaises(htmltalparser.NestingError, check)
- def check_code_attr_syntax(self):
+ def test_code_attr_syntax(self):
output = [
rawtext('<a b="v" c="v" d="v" e></a>'),
]
@@ -119,7 +112,7 @@
self._run_check("""<a\nb\n=\n'v'\nc\n=\n"v"\nd\n=\nv\ne>""", output)
self._run_check("""<a\tb\t=\t'v'\tc\t=\t"v"\td\t=\tv\te>""", output)
- def check_code_attr_values(self):
+ def test_code_attr_values(self):
self._run_check(
"""<a b='xxx\n\txxx' c="yyy\t\nyyy" d='\txyz\n'>""", [
rawtext('<a b="xxx\n\txxx" c="yyy\t\nyyy" d="\txyz\n"></a>')])
@@ -127,7 +120,7 @@
rawtext('<a b="" c=""></a>'),
])
- def check_code_attr_entity_replacement(self):
+ def test_code_attr_entity_replacement(self):
# we expect entities *not* to be replaced by HTLMParser!
self._run_check("""<a b='&><"''>""", [
rawtext('<a b="&><"\'"></a>'),
@@ -142,17 +135,17 @@
rawtext('<a b="<"></a>'),
])
- def check_code_attr_funky_names(self):
+ def test_code_attr_funky_names(self):
self._run_check("""<a a.b='v' c:d=v e-f=v>""", [
rawtext('<a a.b="v" c:d="v" e-f="v"></a>'),
])
- def check_code_pcdata_entityref(self):
+ def test_code_pcdata_entityref(self):
self._run_check(""" """, [
rawtext(' '),
])
- def check_code_short_endtags(self):
+ def test_code_short_endtags(self):
self._run_check("""<html><img/></html>""", [
rawtext('<html><img /></html>'),
])
@@ -160,10 +153,10 @@
class METALGeneratorTestCases(TestCaseBase):
- def check_null(self):
+ def test_null(self):
self._run_check("", [])
- def check_define_macro(self):
+ def test_define_macro(self):
macro = self.initial_program + [
('startTag', ('p', [('metal:define-macro', 'M', 'metal')])),
rawtext('booh</p>'),
@@ -175,7 +168,7 @@
macros = {'M': macro}
self._run_check('<p metal:define-macro="M">booh</p>', program, macros)
- def check_use_macro(self):
+ def test_use_macro(self):
self._run_check('<p metal:use-macro="M">booh</p>', [
('setPosition', (1, 0)),
('useMacro',
@@ -184,7 +177,7 @@
rawtext('booh</p>')])),
])
- def check_define_slot(self):
+ def test_define_slot(self):
macro = self.initial_program + [
('startTag', ('p', [('metal:define-macro', 'M', 'metal')])),
rawtext('foo'),
@@ -201,7 +194,7 @@
'<span metal:define-slot="S">spam</span>bar</p>',
program, macros)
- def check_fill_slot(self):
+ def test_fill_slot(self):
self._run_check('<p metal:use-macro="M">foo'
'<span metal:fill-slot="S">spam</span>bar</p>', [
('setPosition', (1, 0)),
@@ -222,10 +215,10 @@
class TALGeneratorTestCases(TestCaseBase):
- def check_null(self):
+ def test_null(self):
self._run_check("", [])
- def check_define_1(self):
+ def test_define_1(self):
self._run_check("<p tal:define='xyzzy string:spam'></p>", [
('setPosition', (1, 0)),
('beginScope', {'tal:define': 'xyzzy string:spam'}),
@@ -235,7 +228,7 @@
rawtext('</p>'),
])
- def check_define_2(self):
+ def test_define_2(self):
self._run_check("<p tal:define='local xyzzy string:spam'></p>", [
('setPosition', (1, 0)),
('beginScope', {'tal:define': 'local xyzzy string:spam'}),
@@ -246,7 +239,7 @@
rawtext('</p>'),
])
- def check_define_3(self):
+ def test_define_3(self):
self._run_check("<p tal:define='global xyzzy string:spam'></p>", [
('setPosition', (1, 0)),
('beginScope', {'tal:define': 'global xyzzy string:spam'}),
@@ -257,7 +250,7 @@
rawtext('</p>'),
])
- def check_define_4(self):
+ def test_define_4(self):
self._run_check("<p tal:define='x string:spam; y x'></p>", [
('setPosition', (1, 0)),
('beginScope', {'tal:define': 'x string:spam; y x'}),
@@ -268,7 +261,7 @@
rawtext('</p>'),
])
- def check_define_5(self):
+ def test_define_5(self):
self._run_check("<p tal:define='x string:;;;;; y x'></p>", [
('setPosition', (1, 0)),
('beginScope', {'tal:define': 'x string:;;;;; y x'}),
@@ -279,7 +272,7 @@
rawtext('</p>'),
])
- def check_define_6(self):
+ def test_define_6(self):
self._run_check(
"<p tal:define='x string:spam; global y x; local z y'></p>", [
('setPosition', (1, 0)),
@@ -294,7 +287,7 @@
rawtext('</p>'),
])
- def check_condition(self):
+ def test_condition(self):
self._run_check(
"<p><span tal:condition='python:1'><b>foo</b></span></p>", [
rawtext('<p>'),
@@ -307,7 +300,7 @@
rawtext('</p>'),
])
- def check_content_1(self):
+ def test_content_1(self):
self._run_check("<p tal:content='string:foo'>bar</p>", [
('setPosition', (1, 0)),
('beginScope', {'tal:content': 'string:foo'}),
@@ -317,7 +310,7 @@
rawtext('</p>'),
])
- def check_content_2(self):
+ def test_content_2(self):
self._run_check("<p tal:content='text string:foo'>bar</p>", [
('setPosition', (1, 0)),
('beginScope', {'tal:content': 'text string:foo'}),
@@ -327,7 +320,7 @@
rawtext('</p>'),
])
- def check_content_3(self):
+ def test_content_3(self):
self._run_check("<p tal:content='structure string:<br>'>bar</p>", [
('setPosition', (1, 0)),
('beginScope', {'tal:content': 'structure string:<br>'}),
@@ -339,7 +332,7 @@
rawtext('</p>'),
])
- def check_replace_1(self):
+ def test_replace_1(self):
self._run_check("<p tal:replace='string:foo'>bar</p>", [
('setPosition', (1, 0)),
('beginScope', {'tal:replace': 'string:foo'}),
@@ -349,7 +342,7 @@
('endScope', ()),
])
- def check_replace_2(self):
+ def test_replace_2(self):
self._run_check("<p tal:replace='text string:foo'>bar</p>", [
('setPosition', (1, 0)),
('beginScope', {'tal:replace': 'text string:foo'}),
@@ -360,7 +353,7 @@
('endScope', ()),
])
- def check_replace_3(self):
+ def test_replace_3(self):
self._run_check("<p tal:replace='structure string:<br>'>bar</p>", [
('setPosition', (1, 0)),
('beginScope', {'tal:replace': 'structure string:<br>'}),
@@ -371,7 +364,7 @@
('endScope', ()),
])
- def check_repeat(self):
+ def test_repeat(self):
self._run_check("<p tal:repeat='x python:(1,2,3)'>"
"<span tal:replace='x'>dummy</span></p>", [
('setPosition', (1, 0)),
@@ -389,7 +382,7 @@
('endScope', ()),
])
- def check_attributes_1(self):
+ def test_attributes_1(self):
self._run_check("<a href='foo' name='bar' tal:attributes="
"'href string:http://www.zope.org; x string:y'>"
"link</a>", [
@@ -407,7 +400,7 @@
rawtext('link</a>'),
])
- def check_attributes_2(self):
+ def test_attributes_2(self):
self._run_check("<p tal:replace='structure string:<img>' "
"tal:attributes='src string:foo.png'>duh</p>", [
('setPosition', (1, 0)),
@@ -425,7 +418,7 @@
('endScope', ()),
])
- def check_on_error_1(self):
+ def test_on_error_1(self):
self._run_check("<p tal:on-error='string:error' "
"tal:content='notHere'>okay</p>", [
('setPosition', (1, 0)),
@@ -445,7 +438,7 @@
('endScope', ()),
])
- def check_on_error_2(self):
+ def test_on_error_2(self):
self._run_check("<p tal:on-error='string:error' "
"tal:replace='notHere'>okay</p>", [
('setPosition', (1, 0)),
@@ -465,20 +458,20 @@
('endScope', ()),
])
- def check_dup_attr(self):
+ def test_dup_attr(self):
self._should_error("<img tal:condition='x' tal:condition='x'>")
self._should_error("<img metal:define-macro='x' "
- "metal:define-macro='x'>", METALError)
+ "metal:define-macro='x'>", taldefs.METALError)
- def check_tal_errors(self):
+ def test_tal_errors(self):
self._should_error("<p tal:define='x' />")
self._should_error("<p tal:repeat='x' />")
self._should_error("<p tal:foobar='x' />")
self._should_error("<p tal:replace='x' tal:content='x' />")
self._should_error("<p tal:replace='x'>")
- def check_metal_errors(self):
- exc = METALError
+ def test_metal_errors(self):
+ exc = taldefs.METALError
self._should_error(2*"<p metal:define-macro='x'>xxx</p>", exc)
self._should_error("<html metal:use-macro='x'>" +
2*"<p metal:fill-slot='y' />" + "</html>", exc)
@@ -489,7 +482,7 @@
# I18N test cases
#
- def check_i18n_attributes(self):
+ def test_i18n_attributes(self):
self._run_check("<img alt='foo' i18n:attributes='alt'>", [
('setPosition', (1, 0)),
('beginScope', {'alt': 'foo', 'i18n:attributes': 'alt'}),
@@ -499,7 +492,7 @@
('endScope', ()),
])
- def check_i18n_translate(self):
+ def test_i18n_translate(self):
# input/test19.html
self._run_check('''\
<span i18n:translate="">Replace this</span>
@@ -524,7 +517,7 @@
('endScope', ()),
('rawtextColumn', ('</span>\n', 0))])
- def check_i18n_translate_with_nested_tal(self):
+ def test_i18n_translate_with_nested_tal(self):
self._run_check('''\
<span i18n:translate="">replaceable <p tal:replace="str:here">content</p></span>
''', [
@@ -545,7 +538,7 @@
('rawtextColumn', ('</span>\n', 0))
])
- def check_i18n_name(self):
+ def test_i18n_name(self):
# input/test21.html
self._run_check('''\
<span i18n:translate="">
@@ -590,7 +583,7 @@
('rawtextColumn', ('</span>\n', 0))
])
- def check_i18n_name_implicit_value(self):
+ def test_i18n_name_implicit_value(self):
# input/test22.html
self._run_check('''\
<span i18n:translate="">
@@ -618,7 +611,7 @@
('rawtextColumn', ('</span>\n', 0))
])
- def check_i18n_context_domain(self):
+ def test_i18n_context_domain(self):
self._run_check("<span i18n:domain='mydomain'/>", [
('setPosition', (1, 0)),
('beginI18nContext', {'domain': 'mydomain',
@@ -629,7 +622,7 @@
('endI18nContext', ()),
])
- def check_i18n_context_source(self):
+ def test_i18n_context_source(self):
self._run_check("<span i18n:source='en'/>", [
('setPosition', (1, 0)),
('beginI18nContext', {'source': 'en',
@@ -640,7 +633,7 @@
('endI18nContext', ()),
])
- def check_i18n_context_source_target(self):
+ def test_i18n_context_source_target(self):
self._run_check("<span i18n:source='en' i18n:target='ru'/>", [
('setPosition', (1, 0)),
('beginI18nContext', {'source': 'en', 'target': 'ru',
@@ -652,7 +645,7 @@
('endI18nContext', ()),
])
- def check_i18n_context_in_define_slot(self):
+ def test_i18n_context_in_define_slot(self):
text = ("<div metal:use-macro='M' i18n:domain='mydomain'>"
"<div metal:fill-slot='S'>spam</div>"
"</div>")
@@ -679,7 +672,7 @@
('endI18nContext', ())])),
])
- def check_i18n_data(self):
+ def test_i18n_data(self):
# input/test23.html
self._run_check('''\
<span i18n:data="here/currentTime"
@@ -698,7 +691,7 @@
('rawtextColumn', ('</span>\n', 0))
])
- def check_i18n_data_with_name(self):
+ def test_i18n_data_with_name(self):
# input/test29.html
self._run_check('''\
At the tone the time will be
@@ -727,7 +720,7 @@
('rawtextColumn', ('... beep!\n', 0))
])
- def check_i18n_explicit_msgid_with_name(self):
+ def test_i18n_explicit_msgid_with_name(self):
# input/test26.html
self._run_check('''\
<span i18n:translate="jobnum">
@@ -759,7 +752,7 @@
('rawtextColumn', ('</span>\n', 0))
])
- def check_i18n_name_around_tal_content(self):
+ def test_i18n_name_around_tal_content(self):
# input/test28.html
self._run_check('''\
<p i18n:translate="verify">Your contact email address is recorded as
@@ -804,7 +797,7 @@
('rawtextColumn', ('</p>\n', 0))
])
- def check_i18n_name_with_tal_content(self):
+ def test_i18n_name_with_tal_content(self):
# input/test27.html
self._run_check('''\
<p i18n:translate="verify">Your contact email address is recorded as
@@ -846,10 +839,9 @@
def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(HTMLTALParserTestCases, "check_"))
- suite.addTest(unittest.makeSuite(METALGeneratorTestCases, "check_"))
- suite.addTest(unittest.makeSuite(TALGeneratorTestCases, "check_"))
+ suite = unittest.makeSuite(HTMLTALParserTestCases)
+ suite.addTest(unittest.makeSuite(METALGeneratorTestCases))
+ suite.addTest(unittest.makeSuite(TALGeneratorTestCases))
return suite