Esempio n. 1
0
    def test(self):
        """Testing WikiFormatter"""
        formatter = self.formatter()
        v = unicode(formatter.generate(**self.generate_opts))
        v = v.replace('\r', '').replace(u'\u200b', '')  # FIXME: keep ZWSP
        v = strip_line_ws(v, leading=False)
        try:
            self.assertEqual(self.correct, v)
        except AssertionError as e:
            msg = to_unicode(e)
            match = re.match(r"u?'(.*)' != u?'(.*)'", msg)
            if match:
                g1 = ["%s\n" % x for x in match.group(1).split(r'\n')]
                g2 = ["%s\n" % x for x in match.group(2).split(r'\n')]
                expected = ''.join(g1)
                actual = ''.join(g2)
                wiki = repr(self.input).replace(r'\n', '\n')
                diff = ''.join(
                    list(difflib.unified_diff(g1, g2, 'expected', 'actual')))

                # Tip: sometimes, 'expected' and 'actual' differ only by
                #      whitespace, so it can be useful to visualize them, e.g.
                # expected = expected.replace(' ', '.')
                # actual = actual.replace(' ', '.')
                def info(*args):
                    return '\n========== %s: ==========\n%s' % args

                msg = info('expected', expected)
                msg += info('actual', actual)
                msg += info('wiki', ''.join(wiki))
                msg += info('diff', diff)
            raise AssertionError( # See below for details
                '%s\n\n%s:%s: "%s" (%s flavor)' \
                % (msg, self.file, self.line, self.title, formatter.flavor))
Esempio n. 2
0
 def test(self):
     """Testing WikiFormatter"""
     formatter = self.formatter()
     v = unicode(formatter.generate(**self.generate_opts))
     v = v.replace('\r', '').replace(u'\u200b', '') # FIXME: keep ZWSP
     v = strip_line_ws(v, leading=False)
     try:
         self.assertEquals(self.correct, v)
     except AssertionError, e:
         msg = to_unicode(e)
         match = re.match(r"u?'(.*)' != u?'(.*)'", msg)
         if match:
             g1 = ["%s\n" % x for x in match.group(1).split(r'\n')]
             g2 = ["%s\n" % x for x in match.group(2).split(r'\n')]
             expected = ''.join(g1)
             actual = ''.join(g2)
             wiki = repr(self.input).replace(r'\n', '\n')
             diff = ''.join(list(difflib.unified_diff(g1, g2, 'expected',
                                                      'actual')))
             # Tip: sometimes, 'expected' and 'actual' differ only by
             #      whitespace, so it can be useful to visualize them, e.g.
             # expected = expected.replace(' ', '.')
             # actual = actual.replace(' ', '.')
             def info(*args):
                 return '\n========== %s: ==========\n%s' % args
             msg = info('expected', expected)
             msg += info('actual', actual)
             msg += info('wiki', ''.join(wiki))
             msg += info('diff', diff)
         raise AssertionError( # See below for details
             '%s\n\n%s:%s: "%s" (%s flavor)' \
             % (msg, self.file, self.line, self.title, formatter.flavor))
Esempio n. 3
0
 def _validate_print_table(self, expected, data, **kwargs):
     out = io.BytesIO()
     kwargs['out'] = out
     print_table(data, **kwargs)
     self.assertEqual(expected.encode('utf-8'),
                      strip_line_ws(out.getvalue(), leading=False))
Esempio n. 4
0
 def _validate_print_table(self, expected, data, **kwargs):
     out = StringIO()
     kwargs["out"] = out
     print_table(data, **kwargs)
     self.assertEqual(expected.encode("utf-8"), strip_line_ws(out.getvalue(), leading=False))