def runTest(self):
from pyparsing import makeHTMLTags, Word, withAttribute, withClass, nums<EOL>data = """<STR_LIT>"""<EOL>tagStart, tagEnd = makeHTMLTags("<STR_LIT:a>")<EOL>expr = tagStart + Word(nums)("<STR_LIT:value>") + tagEnd<EOL>expected = ([['<STR_LIT:a>', ['<STR_LIT:b>', '<STR_LIT:x>'], False, '<STR_LIT:2>', '<STR_LIT>'],<EOL>['<STR_LIT:a>', ['<STR_LIT:b>', '<STR_LIT:x>'], False, '<STR_LIT:3>', '<STR_LIT>']],<EOL>[['<STR_LIT:a>', ['<STR_LIT:b>', '<STR_LIT:x>'], False, '<STR_LIT:2>', '<STR_LIT>'],<EOL>['<STR_LIT:a>', ['<STR_LIT:b>', '<STR_LIT:x>'], False, '<STR_LIT:3>', '<STR_LIT>']],<EOL>[['<STR_LIT:a>', ['<STR_LIT:class>', '<STR_LIT>'], False, '<STR_LIT>', '<STR_LIT>']],<EOL>)<EOL>for attrib, exp in zip([<EOL>withAttribute(b="<STR_LIT:x>"),<EOL>withAttribute(("<STR_LIT:b>","<STR_LIT:x>")),<EOL>withClass("<STR_LIT>"),<EOL>], expected):<EOL><INDENT>tagStart.setParseAction(attrib)<EOL>result = expr.searchString(data)<EOL>print_(result.dump())<EOL>self.assertEqual(result.asList(), exp, "<STR_LIT>" % (expected, result.asList()))<EOL><DEDENT>
This unit test checks withAttribute in these ways:

* Argument forms as keywords and tuples
* Selecting matching tags by attribute
* Case-insensitive attribute matching
* Correctly matching tags having the attribute, and rejecting tags not having the attribute

(Unit test written by voigts as part of the Google Highly Open Participation Contest)