Example #1
0
File: covercp.py Project: hkfr/data
 def report(self, name):
     coverage.get_ready()
     filename, statements, excluded, missing, _ = coverage.analysis2(name)
     pc = _percent(statements, missing)
     yield TEMPLATE_COVERAGE % dict(name=os.path.basename(name), fullpath=name, pc=pc)
     yield "<table>\n"
     for line in self.annotated_file(filename, statements, excluded, missing):
         yield line
     yield "</table>"
     yield "</body>"
     yield "</html>"
Example #2
0
 def report(self, name):
     coverage.get_ready()
     filename, statements, excluded, missing, _ = coverage.analysis2(name)
     pc = _percent(statements, missing)
     yield TEMPLATE_COVERAGE % dict(
         name=os.path.basename(name), fullpath=name, pc=pc)
     yield '<table>\n'
     for line in self.annotated_file(filename, statements, excluded,
                                     missing):
         yield line
     yield '</table>'
     yield '</body>'
     yield '</html>'
Example #3
0
File: covercp.py Project: hkfr/data
def _show_branch(root, base, path, pct=0, showpct=False, exclude=""):

    # Show the directory name and any of our children
    dirs = [k for k, v in root.iteritems() if v]
    dirs.sort()
    for name in dirs:
        newpath = os.path.join(path, name)

        if newpath.startswith(base):
            relpath = newpath[len(base) :]
            yield "| " * relpath.count(os.sep)
            yield "<a class='directory' href='menu?base=%s&exclude=%s'>%s</a>\n" % (
                newpath,
                urllib.quote_plus(exclude),
                name,
            )

        for chunk in _show_branch(root[name], base, newpath, pct, showpct, exclude):
            yield chunk

    # Now list the files
    if path.startswith(base):
        relpath = path[len(base) :]
        files = [k for k, v in root.iteritems() if not v]
        files.sort()
        for name in files:
            newpath = os.path.join(path, name)

            pc_str = ""
            if showpct:
                try:
                    _, statements, _, missing, _ = coverage.analysis2(newpath)
                except:
                    # Yes, we really want to pass on all errors.
                    pass
                else:
                    pc = _percent(statements, missing)
                    pc_str = ("%3d%% " % pc).replace(" ", "&nbsp;")
                    if pc < float(pct) or pc == -1:
                        pc_str = "<span class='fail'>%s</span>" % pc_str
                    else:
                        pc_str = "<span class='pass'>%s</span>" % pc_str

            yield TEMPLATE_ITEM % ("| " * (relpath.count(os.sep) + 1), pc_str, newpath, name)
Example #4
0
def _show_branch(root, base, path, pct=0, showpct=False, exclude=""):

    # Show the directory name and any of our children
    dirs = [k for k, v in root.iteritems() if v]
    dirs.sort()
    for name in dirs:
        newpath = os.path.join(path, name)

        if newpath.lower().startswith(base):
            relpath = newpath[len(base):]
            yield "| " * relpath.count(os.sep)
            yield "<a class='directory' href='menu?base=%s&exclude=%s'>%s</a>\n" % \
                   (newpath, urllib.quote_plus(exclude), name)

        for chunk in _show_branch(root[name], base, newpath, pct, showpct,
                                  exclude):
            yield chunk

    # Now list the files
    if path.lower().startswith(base):
        relpath = path[len(base):]
        files = [k for k, v in root.iteritems() if not v]
        files.sort()
        for name in files:
            newpath = os.path.join(path, name)

            pc_str = ""
            if showpct:
                try:
                    _, statements, _, missing, _ = coverage.analysis2(newpath)
                except:
                    # Yes, we really want to pass on all errors.
                    pass
                else:
                    pc = _percent(statements, missing)
                    pc_str = ("%3d%% " % pc).replace(' ', '&nbsp;')
                    if pc < float(pct) or pc == -1:
                        pc_str = "<span class='fail'>%s</span>" % pc_str
                    else:
                        pc_str = "<span class='pass'>%s</span>" % pc_str

            yield TEMPLATE_ITEM % ("| " * (relpath.count(os.sep) + 1), pc_str,
                                   newpath, name)
Example #5
0
if __name__ == '__main__':
  if len(sys.argv) > 1:
    print >> sys.stderr, "Too many arguements"
    sys.exit(1)

  parser = SafeConfigParser()
  if len(parser.read('tools/coverage_tests.ini')) == 0:
    print >> sys.stderr, "No coverage_tests.ini file found"
    sys.exit(1)

  the_coverage.get_ready()

  retval = 0

  for file_name in parser.sections():
    _, statements, exclude, missing, readable = the_coverage.analysis2(file_name)
    the_coverage.annotate_file(file_name, statements, exclude, missing)
    n = len(statements)
    m = n - len(missing)
    if n > 0:
      pc = 100.0 * m / n
    else:
      pc = 100.0

    expected_pc = parser.getfloat(file_name, 'percentage')

    if pc < expected_pc:
      retval = 1
      print >> sys.stderr, \
          "Coverage %% of %s unexpected, got %s, expected %s" % \
          (file_name, pc, expected_pc)