Exemple #1
0
    def output_difference(self, example, got, optionflags):
        want = example.want
        if not want.strip():
            return LHTMLOutputChecker.output_difference(
                self, example, got, optionflags)

        # Dang, this isn't as easy to override as we might wish
        original = want

        for transformer in self.transformers:
            want = transformer(want)
            got = transformer(got)

        # temporarily hack example with normalized want:
        example.want = want
        result = LHTMLOutputChecker.output_difference(self, example, got,
                                                      optionflags)
        example.want = original

        # repeat lines with a diff, otherwise it's wading through mud
        difflines = [l for l in result.splitlines() if '(got:' in l]

        if difflines:
            result += '\nLines with differences:\n' + '\n'.join(difflines)

        return result
Exemple #2
0
    def output_difference(self, example, got, optionflags):
        want = example.want
        if not want.strip():
            return LHTMLOutputChecker.output_difference(
                self, example, got, optionflags)

        # Dang, this isn't as easy to override as we might wish
        original = want

        for transformer in self.transformers:
            want = transformer(want)
            got = transformer(got)

        # temporarily hack example with normalized want:
        example.want = want
        result = LHTMLOutputChecker.output_difference(self, example, got,
                                                      optionflags)
        example.want = original

        return result
Exemple #3
0
class HTML(object):
    """
    A class wrapping HTML for better comparison and nicer
    error reporting.
    """
    def __init__(self, text):
        self.text = text
        self.example = doctest.Example('', self.text)
        self.checker = LHTMLOutputChecker()
        self.flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
        self.print_diff = True

    def compare(self, other, expect_eq):
        if isinstance(other, HTML):
            text = other.text
        else:
            text = other
        eq = self.checker.check_output(self.text, text, self.flags)
        if self.print_diff and eq != expect_eq:
            print self.checker.output_difference(self.example, text,
                                                 self.flags)
        # Only output diff once per HTML object.
        self.print_diff = False
        return eq

    def __eq__(self, other):
        return self.compare(other, True)

    def __ne__(self, other):
        return self.compare(other, False)

    def __str__(self):
        return str(self.text)

    def __unicode__(self):
        return unicode(self.text)
Exemple #4
0
 def runTest(self):
     self.parse()
     if self.ignore:
         # We've marked this test to be ignored.
         return
     kw = {}
     for name in self.options:
         if name.startswith('-'):
             kw[name[1:]] = False
         else:
             kw[name] = True
     if kw.get('clean', True):
         transformed = Cleaner(**kw).clean_html(self.input)
     else:
         transformed = self.input
     assert self.expect is not None, ("No expected output in %s" %
                                      self.filename)
     checker = LHTMLOutputChecker()
     if not checker.check_output(self.expect, transformed, 0):
         result = checker.output_difference(DummyInput(want=self.expect),
                                            transformed, 0)
         #result += '\noptions: %s %r' % (', '.join(self.options), kw)
         #result += repr(transformed)
         raise Exception("\n" + result)