class DiffReporter(object):
    def __init__(self,
                 outpath=None,
                 title=None,
                 showDiffs=True,
                 excludeMatch=False):
        self.outpath = os.path.abspath(outpath or 'robotdiff.html')
        self._title = title or 'Test Run Diff Report'
        self._writer = HtmlWriter(self.outpath)
        self._showDiffs = showDiffs
        self._excludeMatch = excludeMatch

    def report(self, results):
        self._start(results.column_names)
        for row in results.rows:
            self._write_row(row)
        self._end()

    def _start(self, columns):
        self._writer.content((START_HTML % {
            'TITLE': self._title
        }).encode('utf-8'),
                             escape=False)
        self._writer.start('tr')
        self._writer.element('th', 'Name', {'class': 'col_name'})
        for name in columns:
            self._writer.element('th', name, {'class': 'col_status'})
        self._writer.end('tr')

    def _write_row(self, row):
        diff = not 'all' in row.status
        if (self._excludeMatch and not diff):
            return
        self._writer.start('tr')
        self._write_name(row)
        for item in row:
            self._write_status(item, row)
        self._writer.end('tr')

    def _write_name(self, row):
        self._writer.element('td', row.name, {
            'class': 'col_name ' + row.status,
            'title': row.explanation
        })

    def _write_status(self, item, row):
        if (self._showDiffs and hasattr(item, 'comparison')
                and row.status == 'diff'):
            self._writer.element(
                'td',
                item.comparison.encode('utf-8').decode('utf-8'),
                {'class': 'col_status ' + item.status}, False)
        else:
            self._writer.element('td', item.name,
                                 {'class': 'col_status ' + item.status})

    def _end(self):
        for tag in 'table', 'body', 'html':
            self._writer.end(tag)
        self._writer.close()
示例#2
0
class DiffReporter(object):
    def __init__(self, outpath=None, title=None):
        self.outpath = os.path.abspath(outpath or 'robotdiff.html')
        self._title = title or 'Test Run Diff Report'
        self._writer = HtmlWriter(open(self.outpath, 'w'))

    def report(self, results):
        self._start(results.column_names)
        for row in results.rows:
            self._write_row(row)
        self._end()

    def _start(self, columns):
        self._writer.content(START_HTML % {'TITLE': self._title}, escape=False)
        self._writer.start('tr')
        self._writer.element('th', 'Name', {'class': 'col_name'})
        for name in columns:
            self._writer.element('th', name, {'class': 'col_status'})
        self._writer.end('tr')

    def _write_row(self, row):
        self._writer.start('tr')
        self._write_name(row)
        for item in row:
            self._write_status(item)
        self._writer.end('tr')

    def _write_name(self, row):
        self._writer.element('td', row.name, {
            'class': 'col_name ' + row.status,
            'title': row.explanation
        })

    def _write_status(self, item):
        self._writer.element('td', item.name,
                             {'class': 'col_status ' + item.status})

    def _end(self):
        for tag in 'table', 'body', 'html':
            self._writer.end(tag)
        self._writer.close()
示例#3
0
class DiffReporter(object):

    def __init__(self, outpath=None, title=None):
        self.outpath = os.path.abspath(outpath or 'robotdiff.html')
        self._title = title or 'Test Run Diff Report'
        self._writer = HtmlWriter(open(self.outpath, 'w'))

    def report(self, results):
        self._start(results.column_names)
        for row in results.rows:
            self._write_row(row)
        self._end()

    def _start(self, columns):
        self._writer.content(START_HTML % {'TITLE': self._title}, escape=False)
        self._writer.start('tr')
        self._writer.element('th', 'Name', {'class': 'col_name'})
        for name in columns:
            self._writer.element('th', name, {'class': 'col_status'})
        self._writer.end('tr')

    def _write_row(self, row):
        self._writer.start('tr')
        self._write_name(row)
        for item in row:
            self._write_status(item)
        self._writer.end('tr')

    def _write_name(self, row):
        self._writer.element('td', row.name, {'class': 'col_name ' + row.status,
                                              'title': row.explanation})

    def _write_status(self, item):
        self._writer.element('td', item.name,
                             {'class': 'col_status ' + item.status})

    def _end(self):
        for tag in 'table', 'body', 'html':
            self._writer.end(tag)
        self._writer.close()