当前位置: 首页>>代码示例>>Python>>正文


Python Templite.render方法代码示例

本文整理汇总了Python中coverage.templite.Templite.render方法的典型用法代码示例。如果您正苦于以下问题:Python Templite.render方法的具体用法?Python Templite.render怎么用?Python Templite.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coverage.templite.Templite的用法示例。


在下文中一共展示了Templite.render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_reusability

# 需要导入模块: from coverage.templite import Templite [as 别名]
# 或者: from coverage.templite.Templite import render [as 别名]
    def test_reusability(self):
        # A single Templite can be used more than once with different data.
        globs = {
            'upper': lambda x: x.upper(),
            'punct': '!',
            }

        template = Templite("This is {{name|upper}}{{punct}}", globs)
        self.assertEqual(template.render({'name':'Ned'}), "This is NED!")
        self.assertEqual(template.render({'name':'Ben'}), "This is BEN!")
开发者ID:dstufft,项目名称:coveragepy,代码行数:12,代码来源:test_templite.py

示例2: index_file

# 需要导入模块: from coverage.templite import Templite [as 别名]
# 或者: from coverage.templite.Templite import render [as 别名]
 def index_file(self):
     index_tmpl = Templite(data('index.html'), self.template_globals)
     self.totals = sum([ f['nums'] for f in self.files ])
     html = index_tmpl.render({'arcs': self.arcs,
      'extra_css': self.extra_css,
      'files': self.files,
      'totals': self.totals})
     if sys.version_info < (3, 0):
         html = html.decode('utf-8')
     self.write_html(os.path.join(self.directory, 'index.html'), html)
     self.status.write(self.directory)
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:13,代码来源:html.py

示例3: index_file

# 需要导入模块: from coverage.templite import Templite [as 别名]
# 或者: from coverage.templite.Templite import render [as 别名]
    def index_file(self):
        """Write the index.html file for this report."""
        index_tmpl = Templite(data("htmlfiles/index.html"), globals())

        files = self.files
        arcs = self.arcs

        totals = sum([f['nums'] for f in files])

        fhtml = open(os.path.join(self.directory, "index.html"), "w")
        fhtml.write(index_tmpl.render(locals()))
        fhtml.close()
开发者ID:AndryulE,项目名称:kitsune,代码行数:14,代码来源:html.py

示例4: index_file

# 需要导入模块: from coverage.templite import Templite [as 别名]
# 或者: from coverage.templite.Templite import render [as 别名]
    def index_file(self):
        """Write the index.html file for this report."""
        index_tmpl = Templite(data("index.html"), self.template_globals)

        self.totals = sum(f["nums"] for f in self.files)

        html = index_tmpl.render(
            {"arcs": self.arcs, "extra_css": self.extra_css, "files": self.files, "totals": self.totals}
        )

        self.write_html(os.path.join(self.directory, "index.html"), html)

        # Write the latest hashes for next time.
        self.status.write(self.directory)
开发者ID:th0,项目名称:test2,代码行数:16,代码来源:html.py

示例5: index_file

# 需要导入模块: from coverage.templite import Templite [as 别名]
# 或者: from coverage.templite.Templite import render [as 别名]
    def index_file(self):
        """Write the index.html file for this report."""
        index_tmpl = Templite(data("index.html"), self.template_globals)

        self.totals = sum(f['nums'] for f in self.files)

        html = index_tmpl.render({
            'has_arcs': self.has_arcs,
            'extra_css': self.extra_css,
            'files': self.files,
            'totals': self.totals,
            'time_stamp': self.time_stamp,
        })

        self.write_html(os.path.join(self.directory, "index.html"), html)

        # Write the latest hashes for next time.
        self.status.write(self.directory)
开发者ID:pycom,项目名称:EricShort,代码行数:20,代码来源:html.py

示例6: index_file

# 需要导入模块: from coverage.templite import Templite [as 别名]
# 或者: from coverage.templite.Templite import render [as 别名]
    def index_file(self):
        """Write the index.html file for this report."""
        index_tmpl = Templite(
            data("htmlfiles/index.html"), self.template_globals
            )

        files = self.files
        arcs = self.arcs

        totals = sum([f['nums'] for f in files])

        self.write_html(
            os.path.join(self.directory, "index.html"),
            index_tmpl.render(locals())
            )

        # Write the latest hashes for next time.
        self.status.write(self.directory)
开发者ID:335969568,项目名称:Blink-1,代码行数:20,代码来源:html.py

示例7: index_file

# 需要导入模块: from coverage.templite import Templite [as 别名]
# 或者: from coverage.templite.Templite import render [as 别名]
    def index_file(self):
        """Write the index.html file for this report."""
        index_tmpl = Templite(
            data("htmlfiles/index.html"), self.template_globals
            )

        files = self.files
        arcs = self.arcs

        self.totals = totals = sum([f['nums'] for f in files])
        extra_css = self.extra_css

        html = index_tmpl.render(locals())
        if sys.version_info < (3, 0):
            html = html.decode("utf-8")
        self.write_html(
            os.path.join(self.directory, "index.html"),
            html
            )

        # Write the latest hashes for next time.
        self.status.write(self.directory)
开发者ID:Cameronlroberts,项目名称:Projects,代码行数:24,代码来源:html.py

示例8: index_file

# 需要导入模块: from coverage.templite import Templite [as 别名]
# 或者: from coverage.templite.Templite import render [as 别名]
    def index_file(self):
        """Write the index.html file for this report."""
        index_tmpl = Templite(
            data("index.html"), self.template_globals
            )

        self.totals = sum(f['nums'] for f in self.files)

        html = index_tmpl.render({
            'arcs': self.arcs,
            'extra_css': self.extra_css,
            'files': self.files,
            'totals': self.totals,
        })

        if sys.version_info < (3, 0):
            html = html.decode("utf-8")
        self.write_html(
            os.path.join(self.directory, "index.html"),
            html
            )

        # Write the latest hashes for next time.
        self.status.write(self.directory)
开发者ID:brifordwylie,项目名称:coveragepy,代码行数:26,代码来源:html.py

示例9: HtmlReporter

# 需要导入模块: from coverage.templite import Templite [as 别名]
# 或者: from coverage.templite.Templite import render [as 别名]

#.........这里部分代码省略.........
            "jquery-1.3.2.min.js", "jquery.tablesorter.min.js"
            ]:
            shutil.copyfile(
                data_filename("htmlfiles/" + static),
                os.path.join(directory, static)
                )

    def html_file(self, cu, analysis):
        """Generate an HTML file for one source file."""
        
        source = cu.source_file().read()

        nums = analysis.numbers        

        missing_branch_arcs = analysis.missing_branch_arcs()
        n_par = 0   # accumulated below.
        arcs = self.arcs

        # These classes determine which lines are highlighted by default.
        c_run = " run hide_run"
        c_exc = " exc"
        c_mis = " mis"
        c_par = " par" + c_run

        lines = []
        
        for lineno, line in enumerate(source_token_lines(source)):
            lineno += 1     # 1-based line numbers.
            # Figure out how to mark this line.
            line_class = ""
            annotate_html = ""
            annotate_title = ""
            if lineno in analysis.statements:
                line_class += " stm"
            if lineno in analysis.excluded:
                line_class += c_exc
            elif lineno in analysis.missing:
                line_class += c_mis
            elif self.arcs and lineno in missing_branch_arcs:
                line_class += c_par
                n_par += 1
                annlines = []
                for b in missing_branch_arcs[lineno]:
                    if b == -1:
                        annlines.append("exit")
                    else:
                        annlines.append(str(b))
                annotate_html = "&nbsp;&nbsp; ".join(annlines)
                if len(annlines) > 1:
                    annotate_title = "no jumps to these line numbers"
                elif len(annlines) == 1:
                    annotate_title = "no jump to this line number"
            elif lineno in analysis.statements:
                line_class += c_run
            
            # Build the HTML for the line
            html = ""
            for tok_type, tok_text in line:
                if tok_type == "ws":
                    html += escape(tok_text)
                else:
                    tok_html = escape(tok_text) or '&nbsp;'
                    html += "<span class='%s'>%s</span>" % (tok_type, tok_html)

            lines.append({
                'html': html,
                'number': lineno,
                'class': line_class.strip() or "pln",
                'annotate': annotate_html,
                'annotate_title': annotate_title,
            })

        # Write the HTML page for this file.
        html_filename = cu.flat_rootname() + ".html"
        html_path = os.path.join(self.directory, html_filename)
        html = spaceless(self.source_tmpl.render(locals()))
        fhtml = open(html_path, 'w')
        fhtml.write(html)
        fhtml.close()

        # Save this file's information for the index file.
        self.files.append({
            'nums': nums,
            'par': n_par,
            'html_filename': html_filename,
            'cu': cu,
            })

    def index_file(self):
        """Write the index.html file for this report."""
        index_tmpl = Templite(data("htmlfiles/index.html"), globals())

        files = self.files
        arcs = self.arcs

        totals = sum([f['nums'] for f in files])

        fhtml = open(os.path.join(self.directory, "index.html"), "w")
        fhtml.write(index_tmpl.render(locals()))
        fhtml.close()
开发者ID:AndryulE,项目名称:kitsune,代码行数:104,代码来源:html.py

示例10: HtmlReporter

# 需要导入模块: from coverage.templite import Templite [as 别名]
# 或者: from coverage.templite.Templite import render [as 别名]

#.........这里部分代码省略.........

        missing_branch_arcs = analysis.missing_branch_arcs()
        n_par = 0   # accumulated below.
        arcs = self.arcs

        # These classes determine which lines are highlighted by default.
        c_run = "run hide_run"
        c_exc = "exc"
        c_mis = "mis"
        c_par = "par " + c_run

        lines = []

        for lineno, line in enumerate(source_token_lines(source)):
            lineno += 1     # 1-based line numbers.
            # Figure out how to mark this line.
            line_class = []
            annotate_html = ""
            annotate_title = ""
            if lineno in analysis.statements:
                line_class.append("stm")
            if lineno in analysis.excluded:
                line_class.append(c_exc)
            elif lineno in analysis.missing:
                line_class.append(c_mis)
            elif self.arcs and lineno in missing_branch_arcs:
                line_class.append(c_par)
                n_par += 1
                annlines = []
                for b in missing_branch_arcs[lineno]:
                    if b < 0:
                        annlines.append("exit")
                    else:
                        annlines.append(str(b))
                annotate_html = "&nbsp;&nbsp; ".join(annlines)
                if len(annlines) > 1:
                    annotate_title = "no jumps to these line numbers"
                elif len(annlines) == 1:
                    annotate_title = "no jump to this line number"
            elif lineno in analysis.statements:
                line_class.append(c_run)

            # Build the HTML for the line
            html = []
            for tok_type, tok_text in line:
                if tok_type == "ws":
                    html.append(escape(tok_text))
                else:
                    tok_html = escape(tok_text) or '&nbsp;'
                    html.append(
                        "<span class='%s'>%s</span>" % (tok_type, tok_html)
                        )

            lines.append({
                'html': ''.join(html),
                'number': lineno,
                'class': ' '.join(line_class) or "pln",
                'annotate': annotate_html,
                'annotate_title': annotate_title,
            })

        # Write the HTML page for this file.
        html_filename = flat_rootname + ".html"
        html_path = os.path.join(self.directory, html_filename)
        extra_css = self.extra_css

        html = spaceless(self.source_tmpl.render(locals()))
        if sys.version_info < (3, 0):
            html = html.decode(encoding)
        self.write_html(html_path, html)

        # Save this file's information for the index file.
        index_info = {
            'nums': nums,
            'par': n_par,
            'html_filename': html_filename,
            'name': cu.name,
            }
        self.files.append(index_info)
        self.status.set_index_info(flat_rootname, index_info)

    def index_file(self):
        """Write the index.html file for this report."""
        index_tmpl = Templite(
            data("htmlfiles/index.html"), self.template_globals
            )

        files = self.files
        arcs = self.arcs

        totals = sum([f['nums'] for f in files])
        extra_css = self.extra_css

        self.write_html(
            os.path.join(self.directory, "index.html"),
            index_tmpl.render(locals())
            )

        # Write the latest hashes for next time.
        self.status.write(self.directory)
开发者ID:msabramo,项目名称:coverage.py,代码行数:104,代码来源:html.py

示例11: HtmlReporter

# 需要导入模块: from coverage.templite import Templite [as 别名]
# 或者: from coverage.templite.Templite import render [as 别名]

#.........这里部分代码省略.........

            # Build the HTML for the line
            html = []
            for tok_type, tok_text in line:
                if tok_type == "ws":
                    html.append(escape(tok_text))
                else:
                    tok_html = escape(tok_text) or '&nbsp;'
                    html.append(
                        "<span class='%s'>%s</span>" % (tok_type, tok_html)
                        )

            callers_html_list = []
            callers = analysis.callers_data.get(lineno)
            if callers:
                line_class.append("has_callers")
                for caller in sorted(callers.test_methods.keys()):
                    caller_count = callers.test_methods[caller]
                    html_filename = self.get_href_for_source_file(caller.filename)
                    content = caller.function_name + " in " + caller.filename + " line " + str(caller.line_no) + \
                        " (" + str(caller_count) + ")"
                    caller_html = "<a href=" + html_filename + "#n" + str(caller.line_no) + ">" + content + "</a>"
                    callers_html_list.append(caller_html)

            lines.append({
                'html': ''.join(html),
                'number': lineno,
                'class': ' '.join(line_class) or "pln",
                'annotate': annotate_html,
                'annotate_title': annotate_title,
                'callers_html_list': callers_html_list,
            })

        # Write the HTML page for this file.
        html = spaceless(self.source_tmpl.render({
            'c_exc': c_exc, 'c_mis': c_mis, 'c_par': c_par, 'c_run': c_run,
            'arcs': self.arcs, 'extra_css': self.extra_css,
            'cu': cu, 'nums': nums, 'lines': lines,
        }))

        if sys.version_info < (3, 0):
            # In theory, all the characters in the source can be decoded, but
            # strange things happen, so use 'replace' to keep errors at bay.
            html = html.decode(encoding, 'replace')

        html_filename = flat_rootname + ".html"
        html_path = os.path.join(self.directory, html_filename)
        self.write_html(html_path, html)

        # Save this file's information for the index file.
        index_info = {
            'nums': nums,
            'html_filename': html_filename,
            'name': cu.name,
            }
        self.files.append(index_info)
        self.status.set_index_info(flat_rootname, index_info)

    def get_href_for_source_file(self, source_filename):
        # Bad hacks here...
        found_cu = None
        for cu in self.code_units:
            if cu.filename == source_filename:
                found_cu = cu
                break
        if found_cu is not None:
            # Best case: we found the code unit in our data already.
            return found_cu.flat_rootname() + ".html"
        else:
            # Test seems to live outside our code unit files.
            # This is almost certainly wrong below.
            if source_filename[0] == "<":
                source_filename = source_filename.replace("<", "_").replace(">", "_")
            source_filename = source_filename.replace(".py", ".html").replace("/", "_")
            return source_filename

    def index_file(self):
        """Write the index.html file for this report."""
        index_tmpl = Templite(
            data("index.html"), self.template_globals
            )

        self.totals = sum(f['nums'] for f in self.files)

        html = index_tmpl.render({
            'arcs': self.arcs,
            'extra_css': self.extra_css,
            'files': self.files,
            'totals': self.totals,
        })

        if sys.version_info < (3, 0):
            html = html.decode("utf-8")
        self.write_html(
            os.path.join(self.directory, "index.html"),
            html
            )

        # Write the latest hashes for next time.
        self.status.write(self.directory)
开发者ID:MPLinder,项目名称:coveragepy,代码行数:104,代码来源:html.py

示例12: HtmlReporter

# 需要导入模块: from coverage.templite import Templite [as 别名]
# 或者: from coverage.templite.Templite import render [as 别名]

#.........这里部分代码省略.........
            # Figure out how to mark this line.
            line_class = []
            annotate_html = ""
            annotate_long = ""
            if lineno in analysis.statements:
                line_class.append("stm")
            if lineno in analysis.excluded:
                line_class.append(c_exc)
            elif lineno in analysis.missing:
                line_class.append(c_mis)
            elif self.has_arcs and lineno in missing_branch_arcs:
                line_class.append(c_par)
                shorts = []
                longs = []
                for b in missing_branch_arcs[lineno]:
                    if b < 0:
                        shorts.append("exit")
                    else:
                        shorts.append(b)
                    longs.append(fr.missing_arc_description(lineno, b, arcs_executed))
                # 202F is NARROW NO-BREAK SPACE.
                # 219B is RIGHTWARDS ARROW WITH STROKE.
                short_fmt = "%s&#x202F;&#x219B;&#x202F;%s"
                annotate_html = ",&nbsp;&nbsp; ".join(short_fmt % (lineno, d) for d in shorts)

                if len(longs) == 1:
                    annotate_long = longs[0]
                else:
                    annotate_long = "%d missed branches: %s" % (
                        len(longs),
                        ", ".join("%d) %s" % (num, ann_long)
                            for num, ann_long in enumerate(longs, start=1)),
                    )
            elif lineno in analysis.statements:
                line_class.append(c_run)

            # Build the HTML for the line.
            html = []
            for tok_type, tok_text in line:
                if tok_type == "ws":
                    html.append(escape(tok_text))
                else:
                    tok_html = escape(tok_text) or '&nbsp;'
                    html.append(
                        '<span class="%s">%s</span>' % (tok_type, tok_html)
                    )

            lines.append({
                'html': ''.join(html),
                'number': lineno,
                'class': ' '.join(line_class) or "pln",
                'annotate': annotate_html,
                'annotate_long': annotate_long,
            })

        # Write the HTML page for this file.
        html = self.source_tmpl.render({
            'c_exc': c_exc,
            'c_mis': c_mis,
            'c_par': c_par,
            'c_run': c_run,
            'has_arcs': self.has_arcs,
            'extra_css': self.extra_css,
            'fr': fr,
            'nums': nums,
            'lines': lines,
            'time_stamp': self.time_stamp,
        })

        html_filename = rootname + ".html"
        html_path = os.path.join(self.directory, html_filename)
        write_html(html_path, html)

        # Save this file's information for the index file.
        index_info = {
            'nums': nums,
            'html_filename': html_filename,
            'relative_filename': fr.relative_filename(),
        }
        self.files.append(index_info)
        self.status.set_index_info(rootname, index_info)

    def index_file(self):
        """Write the index.html file for this report."""
        index_tmpl = Templite(read_data("index.html"), self.template_globals)

        self.totals = sum(f['nums'] for f in self.files)

        html = index_tmpl.render({
            'has_arcs': self.has_arcs,
            'extra_css': self.extra_css,
            'files': self.files,
            'totals': self.totals,
            'time_stamp': self.time_stamp,
        })

        write_html(os.path.join(self.directory, "index.html"), html)

        # Write the latest hashes for next time.
        self.status.write(self.directory)
开发者ID:nedbat,项目名称:coveragepy,代码行数:104,代码来源:html.py

示例13: HtmlReporter

# 需要导入模块: from coverage.templite import Templite [as 别名]
# 或者: from coverage.templite.Templite import render [as 别名]

#.........这里部分代码省略.........
        return m.digest()

    def html_file(self, cu, analysis):
        source_file = cu.source_file()
        try:
            source = source_file.read()
        finally:
            source_file.close()

        flat_rootname = cu.flat_rootname()
        this_hash = self.file_hash(source, cu)
        that_hash = self.status.file_hash(flat_rootname)
        if this_hash == that_hash:
            self.files.append(self.status.index_info(flat_rootname))
            return
        self.status.set_file_hash(flat_rootname, this_hash)
        if sys.version_info < (3, 0):
            encoding = source_encoding(source)
            if encoding.startswith('utf-8') and source[:3] == '\xef\xbb\xbf':
                source = source[3:]
                encoding = 'utf-8'
        nums = analysis.numbers
        missing_branch_arcs = analysis.missing_branch_arcs()
        c_run = 'run hide_run'
        c_exc = 'exc'
        c_mis = 'mis'
        c_par = 'par ' + c_run
        lines = []
        for lineno, line in enumerate(source_token_lines(source)):
            lineno += 1
            line_class = []
            annotate_html = ''
            annotate_title = ''
            if lineno in analysis.statements:
                line_class.append('stm')
            if lineno in analysis.excluded:
                line_class.append(c_exc)
            elif lineno in analysis.missing:
                line_class.append(c_mis)
            elif self.arcs and lineno in missing_branch_arcs:
                line_class.append(c_par)
                annlines = []
                for b in missing_branch_arcs[lineno]:
                    if b < 0:
                        annlines.append('exit')
                    else:
                        annlines.append(str(b))

                annotate_html = '&nbsp;&nbsp; '.join(annlines)
                if len(annlines) > 1:
                    annotate_title = 'no jumps to these line numbers'
                elif len(annlines) == 1:
                    annotate_title = 'no jump to this line number'
            elif lineno in analysis.statements:
                line_class.append(c_run)
            html = []
            for tok_type, tok_text in line:
                if tok_type == 'ws':
                    html.append(escape(tok_text))
                else:
                    tok_html = escape(tok_text) or '&nbsp;'
                    html.append("<span class='%s'>%s</span>" % (tok_type, tok_html))

            lines.append({'html': ''.join(html),
             'number': lineno,
             'class': ' '.join(line_class) or 'pln',
             'annotate': annotate_html,
             'annotate_title': annotate_title})

        html = spaceless(self.source_tmpl.render({'c_exc': c_exc,
         'c_mis': c_mis,
         'c_par': c_par,
         'c_run': c_run,
         'arcs': self.arcs,
         'extra_css': self.extra_css,
         'cu': cu,
         'nums': nums,
         'lines': lines}))
        if sys.version_info < (3, 0):
            html = html.decode(encoding)
        html_filename = flat_rootname + '.html'
        html_path = os.path.join(self.directory, html_filename)
        self.write_html(html_path, html)
        index_info = {'nums': nums,
         'html_filename': html_filename,
         'name': cu.name}
        self.files.append(index_info)
        self.status.set_index_info(flat_rootname, index_info)

    def index_file(self):
        index_tmpl = Templite(data('index.html'), self.template_globals)
        self.totals = sum([ f['nums'] for f in self.files ])
        html = index_tmpl.render({'arcs': self.arcs,
         'extra_css': self.extra_css,
         'files': self.files,
         'totals': self.totals})
        if sys.version_info < (3, 0):
            html = html.decode('utf-8')
        self.write_html(os.path.join(self.directory, 'index.html'), html)
        self.status.write(self.directory)
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:104,代码来源:html.py

示例14: HtmlReporter

# 需要导入模块: from coverage.templite import Templite [as 别名]
# 或者: from coverage.templite.Templite import render [as 别名]

#.........这里部分代码省略.........
        if not self.files:
            raise CoverageException("No data to report.")

        # Write the index file.
        self.index_file()

        # Create the once-per-directory files.
        for static in ["style.css", "coverage_html.js", "jquery-1.3.2.min.js", "jquery.tablesorter.min.js"]:
            shutil.copyfile(data_filename("htmlfiles/" + static), os.path.join(self.directory, static))

    def html_file(self, cu, analysis):
        """Generate an HTML file for one source file."""

        source = cu.source_file().read()

        nums = analysis.numbers

        missing_branch_arcs = analysis.missing_branch_arcs()
        n_par = 0  # accumulated below.
        arcs = self.arcs

        # These classes determine which lines are highlighted by default.
        c_run = "run hide_run"
        c_exc = "exc"
        c_mis = "mis"
        c_par = "par " + c_run

        lines = []

        for lineno, line in enumerate(source_token_lines(source)):
            lineno += 1  # 1-based line numbers.
            # Figure out how to mark this line.
            line_class = []
            annotate_html = ""
            annotate_title = ""
            if lineno in analysis.statements:
                line_class.append("stm")
            if lineno in analysis.excluded:
                line_class.append(c_exc)
            elif lineno in analysis.missing:
                line_class.append(c_mis)
            elif self.arcs and lineno in missing_branch_arcs:
                line_class.append(c_par)
                n_par += 1
                annlines = []
                for b in missing_branch_arcs[lineno]:
                    if b < 0:
                        annlines.append("exit")
                    else:
                        annlines.append(str(b))
                annotate_html = "&nbsp;&nbsp; ".join(annlines)
                if len(annlines) > 1:
                    annotate_title = "no jumps to these line numbers"
                elif len(annlines) == 1:
                    annotate_title = "no jump to this line number"
            elif lineno in analysis.statements:
                line_class.append(c_run)

            # Build the HTML for the line
            html = []
            for tok_type, tok_text in line:
                if tok_type == "ws":
                    html.append(escape(tok_text))
                else:
                    tok_html = escape(tok_text) or "&nbsp;"
                    html.append("<span class='%s'>%s</span>" % (tok_type, tok_html))

            lines.append(
                {
                    "html": "".join(html),
                    "number": lineno,
                    "class": " ".join(line_class) or "pln",
                    "annotate": annotate_html,
                    "annotate_title": annotate_title,
                }
            )

        # Write the HTML page for this file.
        html_filename = cu.flat_rootname() + ".html"
        html_path = os.path.join(self.directory, html_filename)
        html = spaceless(self.source_tmpl.render(locals()))
        fhtml = open(html_path, "w")
        fhtml.write(html)
        fhtml.close()

        # Save this file's information for the index file.
        self.files.append({"nums": nums, "par": n_par, "html_filename": html_filename, "cu": cu})

    def index_file(self):
        """Write the index.html file for this report."""
        index_tmpl = Templite(data("htmlfiles/index.html"), globals())

        files = self.files
        arcs = self.arcs

        totals = sum([f["nums"] for f in files])

        fhtml = open(os.path.join(self.directory, "index.html"), "w")
        fhtml.write(index_tmpl.render(locals()))
        fhtml.close()
开发者ID:jokajak,项目名称:itweb,代码行数:104,代码来源:html.py

示例15: HtmlReporter

# 需要导入模块: from coverage.templite import Templite [as 别名]
# 或者: from coverage.templite.Templite import render [as 别名]

#.........这里部分代码省略.........
            # Figure out how to mark this line.
            line_class = []
            annotate_html = ""
            annotate_title = ""
            if lineno in analysis.statements:
                line_class.append("stm")
            if lineno in analysis.excluded:
                line_class.append(c_exc)
            elif lineno in analysis.missing:
                line_class.append(c_mis)
            elif self.has_arcs and lineno in missing_branch_arcs:
                line_class.append(c_par)
                shorts = []
                longs = []
                for b in missing_branch_arcs[lineno]:
                    if b < 0:
                        shorts.append("exit")
                        longs.append("the function exit")
                    else:
                        shorts.append(b)
                        longs.append("line %d" % b)
                # 202F is NARROW NO-BREAK SPACE.
                # 219B is RIGHTWARDS ARROW WITH STROKE.
                short_fmt = "%s&#x202F;&#x219B;&#x202F;%s"
                annotate_html = ",&nbsp;&nbsp; ".join(short_fmt % (lineno, d) for d in shorts)
                annotate_html += " [?]"

                annotate_title = "Line %d was executed, but never jumped to " % lineno
                if len(longs) == 1:
                    annotate_title += longs[0]
                elif len(longs) == 2:
                    annotate_title += longs[0] + " or " + longs[1]
                else:
                    annotate_title += ", ".join(longs[:-1]) + ", or " + longs[-1]
            elif lineno in analysis.statements:
                line_class.append(c_run)

            # Build the HTML for the line.
            html = []
            for tok_type, tok_text in line:
                if tok_type == "ws":
                    html.append(escape(tok_text))
                else:
                    tok_html = escape(tok_text) or "&nbsp;"
                    html.append('<span class="%s">%s</span>' % (tok_type, tok_html))

            lines.append(
                {
                    "html": "".join(html),
                    "number": lineno,
                    "class": " ".join(line_class) or "pln",
                    "annotate": annotate_html,
                    "annotate_title": annotate_title,
                }
            )

        # Write the HTML page for this file.
        template_values = {
            "c_exc": c_exc,
            "c_mis": c_mis,
            "c_par": c_par,
            "c_run": c_run,
            "has_arcs": self.has_arcs,
            "extra_css": self.extra_css,
            "fr": fr,
            "nums": nums,
            "lines": lines,
            "time_stamp": self.time_stamp,
        }
        html = spaceless(self.source_tmpl.render(template_values))

        html_filename = rootname + ".html"
        html_path = os.path.join(self.directory, html_filename)
        self.write_html(html_path, html)

        # Save this file's information for the index file.
        index_info = {"nums": nums, "html_filename": html_filename, "relative_filename": fr.relative_filename()}
        self.files.append(index_info)
        self.status.set_index_info(rootname, index_info)

    def index_file(self):
        """Write the index.html file for this report."""
        index_tmpl = Templite(data("index.html"), self.template_globals)

        self.totals = sum(f["nums"] for f in self.files)

        html = index_tmpl.render(
            {
                "has_arcs": self.has_arcs,
                "extra_css": self.extra_css,
                "files": self.files,
                "totals": self.totals,
                "time_stamp": self.time_stamp,
            }
        )

        self.write_html(os.path.join(self.directory, "index.html"), html)

        # Write the latest hashes for next time.
        self.status.write(self.directory)
开发者ID:HiroIshikawa,项目名称:21playground,代码行数:104,代码来源:html.py


注:本文中的coverage.templite.Templite.render方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。