Ejemplo n.º 1
0
    def get_annotation_data(self, context):
        add_stylesheet(context.req, 'bitten/bitten_coverage.css')

        resource = context.resource

        # attempt to use the version passed in with the request,
        # otherwise fall back to the latest version of this file.
        version = context.req.args.get('rev') or resource.version
        # get the last change revision for the file so that we can
        # pick coverage data as latest(version >= file_revision)
        created = context.req.args.get('created') or resource.version

        full_path = get_resource_path(resource)
        _name, repos, _path = get_repos(self.env, full_path, None)
        version_time = to_timestamp(repos.get_changeset(version).date)
        if version != created:
            created_time = to_timestamp(repos.get_changeset(created).date)
        else:
            created_time = version_time

        self.log.debug("Looking for coverage report for %s@%s [%s:%s]..." % (
                        full_path, str(resource.version), created, version))

        db = self.env.get_db_cnx()
        cursor = db.cursor()
        cursor.execute("""
                SELECT b.id, b.rev, i2.value
                FROM bitten_config AS c
                    INNER JOIN bitten_build AS b ON c.name=b.config
                    INNER JOIN bitten_report AS r ON b.id=r.build
                    INNER JOIN bitten_report_item AS i1 ON r.id=i1.report
                    INNER JOIN bitten_report_item AS i2 ON (i1.item=i2.item
                                                    AND i1.report=i2.report)
                WHERE i2.name='line_hits'
                    AND b.rev_time>=%s
                    AND b.rev_time<=%s
                    AND i1.name='file'
                    AND """ + db.concat('c.path', "'/'", 'i1.value') + """=%s
                ORDER BY b.rev_time DESC LIMIT 1""" ,
            (created_time, version_time, full_path))

        row = cursor.fetchone()
        if row:
            build_id, build_rev, line_hits = row
            coverage = line_hits.split()
            self.log.debug("Coverage annotate for %s@%s using build %d: %s",
                            resource.id, build_rev, build_id, coverage)
            return coverage
        add_warning(context.req, "No coverage annotation found for "
                                 "/%s for revision range [%s:%s]." % (
                                 resource.id.lstrip('/'), version, created))
        return []
Ejemplo n.º 2
0
 def post_process_request(self, req, template, data, content_type):
     """ Adds a 'Coverage' context navigation menu item. """
     resource = data and data.get('context') \
                     and data.get('context').resource or None
     if resource and isinstance(resource, Resource) \
                 and resource.realm=='source' and data.get('file') \
                 and not req.args.get('annotate', '') == 'coverage':
         add_ctxtnav(req, tag.a('Coverage',
                 title='Annotate file with test coverage '
                       'data (if available)',
                 href=req.href.browser(get_resource_path(resource),
                     annotate='coverage', rev=req.args.get('rev'),
                     created=data.get('created_rev') or data.get('rev')),
                 rel='nofollow'))
     return template, data, content_type
Ejemplo n.º 3
0
 def test_parent(self):
     resource = Resource('source', '/some/path', '123',
                          parent=Resource('repository', 'foo'))
     self.assertEquals("foo/some/path", get_resource_path(resource))
Ejemplo n.º 4
0
 def test_parent_without_name(self):
     resource = Resource('source', '/some/path', '123',
                          parent=Resource('repository', ''))
     self.assertEquals("some/path", get_resource_path(resource))
Ejemplo n.º 5
0
 def test_wihout_parent(self):
     resource = Resource('source', '/some/path', '123', parent=None)
     self.assertEquals("some/path", get_resource_path(resource))
Ejemplo n.º 6
0
 def test_parent(self):
     resource = Resource('source',
                         '/some/path',
                         '123',
                         parent=Resource('repository', 'foo'))
     self.assertEquals("foo/some/path", get_resource_path(resource))
Ejemplo n.º 7
0
 def test_parent_without_name(self):
     resource = Resource('source',
                         '/some/path',
                         '123',
                         parent=Resource('repository', ''))
     self.assertEquals("some/path", get_resource_path(resource))
Ejemplo n.º 8
0
 def test_wihout_parent(self):
     resource = Resource('source', '/some/path', '123', parent=None)
     self.assertEquals("some/path", get_resource_path(resource))