# HG changeset patch # User Sylvain Thénault # Date 1297423067 -3600 # Node ID 8e59c2cdcc99c1b49c84f0fde614ce18946c8d6d # Parent 75a232b2e4776d8637556cd8dc10cb31d8dfe290# Parent a8fbcf9b65729ec0ee1d13d4aea8a82690cdca31 backport stable diff -r 75a232b2e477 -r 8e59c2cdcc99 MANIFEST.in --- a/MANIFEST.in Thu Feb 10 17:17:54 2011 +0100 +++ b/MANIFEST.in Fri Feb 11 12:17:47 2011 +0100 @@ -21,7 +21,7 @@ recursive-include entities/test/data bootstrap_cubes *.py recursive-include sobjects/test/data bootstrap_cubes *.py recursive-include hooks/test/data bootstrap_cubes *.py -recursive-include server/test/data bootstrap_cubes *.py source* +recursive-include server/test/data bootstrap_cubes *.py source* *.conf *.ldif recursive-include devtools/test/data bootstrap_cubes *.py *.txt *.js recursive-include web/test/data bootstrap_cubes pouet.css *.py diff -r 75a232b2e477 -r 8e59c2cdcc99 devtools/htmlparser.py --- a/devtools/htmlparser.py Thu Feb 10 17:17:54 2011 +0100 +++ b/devtools/htmlparser.py Fri Feb 11 12:17:47 2011 +0100 @@ -127,20 +127,47 @@ self.input_tags = self.find_tag('input') self.title_tags = [self.h1_tags, self.h2_tags, self.h3_tags, self.h4_tags] + def iterstr(self, tag): + if self.default_ns is None: + return ".//%s" % tag + else: + return ".//{%s}%s" % (self.default_ns, tag) + def find_tag(self, tag, gettext=True): """return a list which contains text of all "tag" elements """ - if self.default_ns is None: - iterstr = ".//%s" % tag - else: - iterstr = ".//{%s}%s" % (self.default_ns, tag) + iterstr = self.iterstr(tag) if not gettext or tag in ('a', 'input'): - return [(elt.text, elt.attrib) for elt in self.etree.iterfind(iterstr)] - return [u''.join(elt.xpath('.//text()')) for elt in self.etree.iterfind(iterstr)] + return [(elt.text, elt.attrib) + for elt in self.etree.iterfind(iterstr)] + return [u''.join(elt.xpath('.//text()')) + for elt in self.etree.iterfind(iterstr)] def appears(self, text): """returns True if appears in the page""" return text in self.raw_text + def has_tag(self, tag, nboccurs=1, **attrs): + """returns True if tag with given attributes appears in the page + `nbtimes` (any if None) + """ + for elt in self.etree.iterfind(self.iterstr(tag)): + eltattrs = elt.attrib + for attr, value in attrs.iteritems(): + try: + if eltattrs[attr] != value: + break + except KeyError: + break + else: # all attributes match + if nboccurs is None: # no need to check number of occurences + return True + if not nboccurs: # too much occurences + return False + nboccurs -= 1 + if nboccurs == 0: # correct number of occurences + return True + return False # no matching tag/attrs + def __contains__(self, text): return text in self.source diff -r 75a232b2e477 -r 8e59c2cdcc99 devtools/testlib.py --- a/devtools/testlib.py Thu Feb 10 17:17:54 2011 +0100 +++ b/devtools/testlib.py Fri Feb 11 12:17:47 2011 +0100 @@ -664,13 +664,6 @@ # content validation ####################################################### - def assertDocTestFile(self, testfile): - # doctest returns tuple (failure_count, test_count) - result = self.shell().process_script(testfile) - if result[0] and result[1]: - raise self.failureException("doctest file '%s' failed" - % testfile) - # validators are used to validate (XML, DTD, whatever) view's content # validators availables are : # DTDValidator : validates XML + declared DTD @@ -755,25 +748,35 @@ raise AssertionError, msg, tcbk return self._check_html(output, view, template) + def get_validator(self, view=None, content_type=None, output=None): + if view is not None: + try: + return self.vid_validators[view.__regid__]() + except KeyError: + if content_type is None: + content_type = view.content_type + if content_type is None: + content_type = 'text/html' + if content_type in ('text/html', 'application/xhtml+xml'): + if output and output.startswith(' used in progress widget, unknown in html dtd output = re.sub('', '', output) @@ -816,6 +819,13 @@ msg += u'\nfor content:\n%s' % content raise AssertionError, msg, tcbk + def assertDocTestFile(self, testfile): + # doctest returns tuple (failure_count, test_count) + result = self.shell().process_script(testfile) + if result[0] and result[1]: + raise self.failureException("doctest file '%s' failed" + % testfile) + # deprecated ############################################################### @deprecated('[3.8] use self.execute(...).get_entity(0, 0)')