From: <ian...@us...> - 2003-05-07 05:23:23
|
Update of /cvsroot/webware-sandbox/Sandbox/ianbicking/FormEncode In directory sc8-pr-cvs1:/tmp/cvs-serv30358 Modified Files: HTMLView.py test.py testdiff.py Log Message: * Fixed repeating fields * Fixed testing Index: HTMLView.py =================================================================== RCS file: /cvsroot/webware-sandbox/Sandbox/ianbicking/FormEncode/HTMLView.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** HTMLView.py 7 May 2003 04:59:47 -0000 1.2 --- HTMLView.py 7 May 2003 05:23:20 -0000 1.3 *************** *** 117,120 **** --- 117,121 ---- defaultList = self.makeRepeatList(default, repetitions) optionList = self.makeRepeatList(options, repetitions) + prefix = state.namePrefix result = [] *************** *** 122,128 **** # @@: Should set some state instance variables for # the repetition result.append(self.formFieldUnrepeating( ! name, validator, defaultList[i], optionList[i], state)) return '\n'.join(result) --- 123,131 ---- # @@: Should set some state instance variables for # the repetition + state.namePrefix = '%s%s-%i.' % (prefix, name, i) result.append(self.formFieldUnrepeating( ! None, validator, defaultList[i], optionList[i], state)) + state.namePrefix = prefix return '\n'.join(result) Index: test.py =================================================================== RCS file: /cvsroot/webware-sandbox/Sandbox/ianbicking/FormEncode/test.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test.py 7 May 2003 04:59:47 -0000 1.4 --- test.py 7 May 2003 05:23:20 -0000 1.5 *************** *** 9,12 **** --- 9,13 ---- import pyRXP from SimpleHTMLGen import html + import testdiff ######################################## *************** *** 130,163 **** render = HTMLView.Form(schema=self.schema, action='form').html( default, options, Validator.State()) ! if isinstance(self.dest, str): ! print self.dest ! dest = self.parseXMLFragment(self.dest) ! else: ! dest = self.dest ! render = self.parseXMLFragment(render) ! if render != dest: ! raise self.failureException, \ ! ('%r, %r ->\n%s\n!= --------------------\n%s' ! % (default, options, render, dest)) ! ! def parseXMLFragment(self, s): ! s = '<result>%s</result>' % s ! return map(self.trimXML, pyRXP.Parser().parse(s)[2]) ! ! def trimXML(self, x): ! if isinstance(x, str): ! return x ! rest = [self.trimXML(e) for e in x[2] or []] ! print rest ! return (x[0], x[1] or {}, rest) ! ! def compareXML(self, source, dest, result=None): ! if result is None: ! result = [] ! ! ! ! ! class Test: --- 131,136 ---- render = HTMLView.Form(schema=self.schema, action='form').html( default, options, Validator.State()) ! error = testdiff.htmlcompareError(render, self.dest) ! assert not error, error class Test: *************** *** 356,373 **** html.input.text(name="lname", value=""), html.br, ! html.input.text(name="phone-1.number", value=""), html.br, ! html.select(name="phone-1.type", c=[html.option("home", value="home"), html.option("work", value="work")]), html.br, ! html.input.text(name="phone-2.number", value=""), html.br, ! html.select(name="phone-2.type", c=[html.option("home", value="home"), html.option("work", value="work")]), html.br])), ] - --- 329,345 ---- html.input.text(name="lname", value=""), html.br, ! html.input.text(name="phone-0.number", value=""), html.br, ! html.select(name="phone-0.type", c=[html.option("home", value="home"), html.option("work", value="work")]), html.br, ! html.input.text(name="phone-1.number", value=""), html.br, ! html.select(name="phone-1.type", c=[html.option("home", value="home"), html.option("work", value="work")]), html.br])), ] Index: testdiff.py =================================================================== RCS file: /cvsroot/webware-sandbox/Sandbox/ianbicking/FormEncode/testdiff.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** testdiff.py 7 May 2003 04:59:47 -0000 1.1 --- testdiff.py 7 May 2003 05:23:20 -0000 1.2 *************** *** 1,4 **** --- 1,5 ---- from HTMLParser import HTMLParser import cgi, re + from cStringIO import StringIO class HTMLSimplifier(HTMLParser): *************** *** 27,31 **** for tag in self.tags: if tag[0] == 'text': ! result.append(('text', normalizeText(tag[1]), tag[2])) else: result.append(tag) --- 28,34 ---- for tag in self.tags: if tag[0] == 'text': ! text = normalizeText(tag[1]) ! if text: ! result.append(('text', text, tag[2])) else: result.append(tag) *************** *** 107,121 **** if dest[0] in ['comment', 'text']: return dest[1] == source[1] ! if dest[1].has_key('any'): return 1 ! for key, value in dest[1].items(): if key.startswith('any-'): ! if source[1].has_key(key[4:]): ! del source[1][key[4:]] ! del dest[1][key] elif value == '*': ! del dest[1][key] ! del source[1][key] ! return dest[1] == source[1] def cutString(s, pos, splitter=None): --- 110,128 ---- if dest[0] in ['comment', 'text']: return dest[1] == source[1] ! if dest[1] is None and source[1] is None: return 1 ! destd = dest[1].copy() ! sourced = source[1].copy() ! if destd.has_key('any'): ! return 1 ! for key, value in destd.items(): if key.startswith('any-'): ! if sourced.has_key(key[4:]): ! del sourced[key[4:]] ! del destd[key] elif value == '*': ! del destd[key] ! del sourced[key] ! return destd == sourced def cutString(s, pos, splitter=None): *************** *** 130,133 **** --- 137,163 ---- return before + splitter + after + def htmlcompareError(source, dest): + val = htmlcompare(source, dest) + if not val: + return None + msg, spos, dpos = val + out = StringIO() + out.write("Does not match: %s\n" % msg) + if spos: + out.write("Source(%i:%i):\n" % spos) + out.write(cutString(source, spos, '*****') + "\n") + else: + out.write('Source:\n') + out.write(source + "\n") + out.write('-' * 60 + "\n") + if dpos: + out.write('Dest(%i:%i):\n' % dpos) + out.write(cutString(dest, dpos, '*****') + "\n") + else: + out.write('Dest:\n') + out.write(dest + "\n") + return out.getvalue() + + if __name__ == '__main__': vals = [ *************** *** 146,166 **** ] for source, dest, match in vals: ! val = htmlcompare(source, dest) ! if val: ! msg, spos, dpos = val ! print "Does not match:", msg ! if spos: ! print "Source(%i:%i):" % spos ! print cutString(source, spos, '*****') ! print source ! else: ! print 'Source:' ! print '-' * 60 ! if dpos: ! print 'Dest(%i:%i):' % dpos ! print cutString(dest, dpos, '*****') ! else: ! print 'Dest:' ! print dest ! --- 176,180 ---- ] for source, dest, match in vals: ! val = htmlcompareError(source, dest) ! if val: print val |