예제 #1
0
def save_coverage(tree, templates, output_dir, app_name, granularity):
    groups = Utils2.get_groupped_classes(tree)
    init_row = templates['init_row.pt']
    init_table = templates['init_table.pt']
    index_template = templates['index.pt']

    rows = []
    total_coverage_data = CoverageData()
    for g in groups:
        (package, path, coverage_data) = save_package_indexhtml(g, templates, output_dir, app_name, granularity)
        coverage = coverage_data.get_formatted_coverage(granularity)
        row = init_row(elementlink=path, type='package', elementname=package,
                  coverage=coverage,
                  respath='', coverage_data=coverage_data,
                  is_instruction_level=Granularity.is_instruction(granularity),
                  progress_covered=coverage_data.covered(granularity),
                  progress_missed=coverage_data.missed(granularity))
        rows.append(Markup(row))
        total_coverage_data.add_data(coverage_data)
    total_coverage = total_coverage_data.get_formatted_coverage(granularity)
    table = init_table(rows=Markup("\n".join(rows)),
                        total_coverage=total_coverage,
                        total_coverage_data=total_coverage_data,
                        is_instruction_level=Granularity.is_instruction(granularity),
                        progress_covered=total_coverage_data.covered(granularity),
                        progress_all=total_coverage_data.coverable(granularity))
    root_path = ''
    html = index_template(table=Markup(table), appname=app_name, title=app_name, package=None, 
                          respath=root_path, file_name=None, granularity=Granularity.get(granularity))
    path = os.path.join(output_dir, 'index.html')
    with open(path, 'w') as f:
        f.write(html)
예제 #2
0
def save_package_indexhtml(class_group, templates, output_dir, app_name,
                           granularity):
    folder = class_group[0].folder.replace('\\', '/')
    class_name_with_pkg = class_group[0].name
    package_name = Utils2.get_standart_package_name(class_name_with_pkg)
    init_table = templates['init_table.pt']
    init_row = templates['init_row.pt']
    index_template = templates['index.pt']

    slash_num = class_name_with_pkg.count('/')
    root_path = ''
    for i in range(slash_num):
        root_path += '../'
    total_coverage_data = CoverageData()
    rows = []
    for cl in class_group:
        elementlink = os.path.join(root_path, folder,
                                   cl.file_name + '.html').replace('\\', '/')
        elementname = cl.file_name
        coverage_data = CoverageData(lines=cl.coverable(),
                                     lines_missed=cl.not_covered(),
                                     lines_covered=cl.covered(),
                                     methods_covered=cl.mtds_covered(),
                                     methods_missed=cl.mtds_not_covered(),
                                     methods=cl.mtds_coverable())
        coverage_data.update_coverage_for_single_class_from_methods()
        coverage = coverage_data.get_coverage(granularity)
        row = init_row(
            elementlink=elementlink,
            type='class',
            elementname=elementname,
            coverage=coverage_data.format_coverage(coverage),
            respath=root_path,
            coverage_data=coverage_data,
            is_instruction_level=Granularity.is_instruction(granularity),
            progress_missed=coverage_data.missed(granularity),
            progress_covered=coverage_data.covered(granularity))
        rows.append(Markup(row))
        total_coverage_data.add_data(coverage_data)
    total_coverage = total_coverage_data.get_formatted_coverage(granularity)
    table = init_table(
        rows=Markup("\n".join(rows)),
        total_coverage=total_coverage,
        is_instruction_level=Granularity.is_instruction(granularity),
        total_coverage_data=total_coverage_data,
        progress_covered=total_coverage_data.covered(granularity),
        progress_all=total_coverage_data.coverable(granularity))
    html = index_template(table=Markup(table),
                          appname=app_name,
                          title=folder,
                          package=package_name,
                          respath=root_path,
                          file_name=None,
                          granularity=Granularity.get(granularity))
    rel_path = os.path.join(folder, 'index.html').replace('\\', '/')
    path = os.path.join(output_dir, rel_path).replace('\\', '/')
    with open(path, 'w') as f:
        f.write(html)
    return (package_name, rel_path, total_coverage_data)
예제 #3
0
def save_class(cl, class_template, output_dir, app_name, granularity):
    dir = os.path.join(output_dir, cl.folder)
    if not os.path.exists(dir):
        os.makedirs(dir)
    class_path = os.path.join(dir, cl.file_name + '.html')
    buf = [LI_TAG(d) for d in cl.get_class_description()]
    buf.append(LI_TAG(''))
    buf.extend([LI_TAG(a) for a in cl.get_annotations()])
    buf.append(LI_TAG(''))
    buf.extend([LI_TAG(f) for f in cl.get_fields()])
    buf.append(LI_TAG(''))
    for m in cl.methods:
        ins_buf = []
        for ins in m.insns:
            if ins.covered:
                ins_buf.append(span_tab_tag(ins.buf, COV_CLASS))
            else:
                ins_buf.append(span_tab_tag(ins.buf))
        # insert labels and tries
        # sort the labels by index
        count = 0
        labels = m.labels.values()
        labels = sorted(labels, key=attrgetter('index'))
        for l in labels:
            if l.covered:
                ins_buf.insert(l.index + count, span_tab_tag(l.buf, COV_CLASS))
            else:
                ins_buf.insert(l.index + count, span_tab_tag(l.buf))
            count += 1
            for t in l.tries:
                ins_buf.insert(l.index + count, span_tab_tag(t.buf))
                count += 1
            if l.switch:
                for sl in l.switch.buf:
                    ins_buf.insert(l.index + count, span_tab_tag(sl))
                    count += 1
            if l.array_data:
                for sl in l.array_data.buf:
                    ins_buf.insert(l.index + count, span_tab_tag(sl))
                    count += 1
        ins_buf.insert(0, LI_TAG(''))
        for a in m.annotations:
            a.reload()
            ins_buf[0:0] = [span_tab_tag(d) for d in a.buf]
        for p in reversed(m.parameters):
            p.reload()
            ins_buf[0:0] = [span_tab_tag(d) for d in p.buf]
        ins_buf.insert(0, span_tab_tag(m.get_registers_line()))
        html_method_line = span_tag(
            cgi.escape(m.get_method_line()),
            COV_CLASS) if m.called else m.get_method_line()
        ins_buf.insert(0, html_method_line)
        ins_buf.append(LI_TAG(".end method"))
        buf.append(LI_TAG(''))
        buf.extend(ins_buf)
    slash_num = cl.name.count('/')
    respath = ''
    for i in range(slash_num):
        respath += '../'
    html = class_template(code=Markup("\n".join(buf)),
                          appname=app_name,
                          title=cl.file_name,
                          package=Utils2.get_standart_package_name(cl.name),
                          respath=respath,
                          granularity=Granularity.get(granularity))
    with open(class_path, 'w') as f:
        f.write(html)
예제 #4
0
 def coverable(self, granularity):
     if Granularity.is_instruction(granularity):
         return self.lines
     if Granularity.is_method(granularity):
         return self.methods
     return self.classes
예제 #5
0
 def missed(self, granularity):
     if Granularity.is_instruction(granularity):
         return self.lines_missed
     if Granularity.is_method(granularity):
         return self.methods_missed
     return self.classes_missed
예제 #6
0
 def get_coverage(self, granularity):
     if Granularity.is_instruction(granularity):
         return self.get_line_coverage()
     if Granularity.is_method(granularity):
         return self.get_method_coverage()
     return self.get_class_coverage()