Beispiel #1
0
 def test_passthrough(self):
     # Strings without variables are passed through unchanged.
     self.assertEqual(Templite("Hello").render(), "Hello")
     self.assertEqual(
         Templite("Hello, 20% fun time!").render(),
         "Hello, 20% fun time!"
         )
Beispiel #2
0
    def __init__(self, cov, config):
        super(HtmlReporter, self).__init__(cov, config)
        self.directory = None
        title = self.config.html_title
        if env.PY2:
            title = title.decode("utf8")
        self.template_globals = {
            'escape': escape,
            'pair': pair,
            'title': title,
            '__url__': coverage.__url__,
            '__version__': coverage.__version__,
        }
        self.source_tmpl = Templite(read_data("pyfile.html"),
                                    self.template_globals)

        self.coverage = cov

        self.files = []
        self.all_files_nums = []
        self.has_arcs = self.coverage.data.has_arcs()
        self.status = HtmlStatus()
        self.extra_css = None
        self.totals = Numbers()
        self.time_stamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
Beispiel #3
0
 def __init__(self, coverage, ignore_errors=False):
     super(HtmlReporter, self).__init__(coverage, ignore_errors)
     self.directory = None
     self.source_tmpl = Templite(data("htmlfiles/pyfile.html"), globals())
     
     self.files = []
     self.arcs = coverage.data.has_arcs()
Beispiel #4
0
    def index_file(self):
        """Write the index.html file for this report."""
        index_tmpl = Templite(read_data("index.html"), self.template_globals)

        skipped_covered_msg = skipped_empty_msg = ""
        if self.skipped_covered_count:
            msg = "{} {} skipped due to complete coverage."
            skipped_covered_msg = msg.format(
                self.skipped_covered_count,
                "file" if self.skipped_covered_count == 1 else "files",
            )
        if self.skipped_empty_count:
            msg = "{} empty {} skipped."
            skipped_empty_msg = msg.format(
                self.skipped_empty_count,
                "file" if self.skipped_empty_count == 1 else "files",
            )

        html = index_tmpl.render({
            'files': self.file_summaries,
            'totals': self.totals,
            'skipped_covered_msg': skipped_covered_msg,
            'skipped_empty_msg': skipped_empty_msg,
        })

        index_file = os.path.join(self.directory, "index.html")
        write_html(index_file, html)
        self.coverage._message(f"Wrote HTML report to {index_file}")

        # Write the latest hashes for next time.
        self.incr.write()
Beispiel #5
0
    def __init__(self, cov):
        self.coverage = cov
        self.config = self.coverage.config
        self.directory = self.config.html_dir

        self.skip_covered = self.config.html_skip_covered
        if self.skip_covered is None:
            self.skip_covered = self.config.skip_covered
        self.skip_empty = self.config.html_skip_empty
        if self.skip_empty is None:
            self.skip_empty = self.config.skip_empty
        self.skipped_covered_count = 0
        self.skipped_empty_count = 0

        title = self.config.html_title

        if self.config.extra_css:
            self.extra_css = os.path.basename(self.config.extra_css)
        else:
            self.extra_css = None

        self.data = self.coverage.get_data()
        self.has_arcs = self.data.has_arcs()

        self.file_summaries = []
        self.all_files_nums = []
        self.incr = IncrementalChecker(self.directory)
        self.datagen = HtmlDataGeneration(self.coverage)
        self.totals = Numbers(precision=self.config.precision)
        self.directory_was_empty = False

        self.template_globals = {
            # Functions available in the templates.
            'escape': escape,
            'pair': pair,
            'len': len,

            # Constants for this report.
            '__url__': coverage.__url__,
            '__version__': coverage.__version__,
            'title': title,
            'time_stamp': format_local_datetime(datetime.datetime.now()),
            'extra_css': self.extra_css,
            'has_arcs': self.has_arcs,
            'show_contexts': self.config.show_contexts,

            # Constants for all reports.
            # These css classes determine which lines are highlighted by default.
            'category': {
                'exc': 'exc show_exc',
                'mis': 'mis show_mis',
                'par': 'par run show_par',
                'run': 'run',
            }
        }
        self.pyfile_html_source = read_data("pyfile.html")
        self.source_tmpl = Templite(self.pyfile_html_source,
                                    self.template_globals)
Beispiel #6
0
    def try_render(self, text, ctx=None, result=None):
        """Render `text` through `ctx`, and it had better be `result`.

        Result defaults to None so we can shorten the calls where we expect
        an exception and never get to the result comparison.
        """
        actual = Templite(text).render(ctx or {})
        if result:
            self.assertEqual(actual, result)
Beispiel #7
0
    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!")
Beispiel #8
0
    def try_render(self, text, ctx=None, result=None):
        """Render `text` through `ctx`, and it had better be `result`.

        Result defaults to None so we can shorten the calls where we expect
        an exception and never get to the result comparison.
        """
        actual = Templite(text).render(ctx or {})
        # If result is None, then an exception should have prevented us getting
        # to here.
        assert result is not None
        self.assertEqual(actual, result)
Beispiel #9
0
    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()
Beispiel #10
0
    def index_file(self):
        """Write the index.html file for this report."""
        index_tmpl = Templite(read_data("index.html"), self.template_globals)

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

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

        # Write the latest hashes for next time.
        self.incr.write()
Beispiel #11
0
 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)
Beispiel #12
0
    def __init__(self, cov):
        self.coverage = cov
        self.config = self.coverage.config
        self.directory = self.config.html_dir
        title = self.config.html_title
        if env.PY2:
            title = title.decode("utf8")

        if self.config.extra_css:
            self.extra_css = os.path.basename(self.config.extra_css)
        else:
            self.extra_css = None

        self.data = self.coverage.get_data()
        self.has_arcs = self.data.has_arcs()

        self.file_summaries = []
        self.all_files_nums = []
        self.incr = IncrementalChecker(self.directory)
        self.datagen = HtmlDataGeneration(self.coverage)
        self.totals = Numbers()

        self.template_globals = {
            # Functions available in the templates.
            'escape': escape,
            'pair': pair,
            'len': len,

            # Constants for this report.
            '__url__': coverage.__url__,
            '__version__': coverage.__version__,
            'title': title,
            'time_stamp': datetime.datetime.now().strftime('%Y-%m-%d %H:%M'),
            'extra_css': self.extra_css,
            'has_arcs': self.has_arcs,
            'show_contexts': self.config.show_contexts,

            # Constants for all reports.
            # These css classes determine which lines are highlighted by default.
            'category': {
                'exc': 'exc',
                'mis': 'mis',
                'par': 'par run hide_run',
                'run': 'run hide_run',
            }
        }
        self.pyfile_html_source = read_data("pyfile.html")
        self.source_tmpl = Templite(self.pyfile_html_source,
                                    self.template_globals)
Beispiel #13
0
    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)
Beispiel #14
0
    def __init__(self, cov, ignore_errors=False):
        super(HtmlReporter, self).__init__(cov, ignore_errors)
        self.directory = None
        self.template_globals = {
            'escape': escape,
            '__url__': coverage.__url__,
            '__version__': coverage.__version__,
        }
        self.source_tmpl = Templite(data("htmlfiles/pyfile.html"),
                                    self.template_globals)

        self.coverage = cov

        self.files = []
        self.arcs = self.coverage.data.has_arcs()
        self.status = HtmlStatus()
Beispiel #15
0
 def __init__(self, cov, config):
     super(HtmlReporter, self).__init__(cov, config)
     self.directory = None
     self.template_globals = {
         'escape': escape,
         'title': self.config.html_title,
         '__url__': coverage.__url__,
         '__version__': coverage.__version__
     }
     self.source_tmpl = Templite(data('pyfile.html'), self.template_globals)
     self.coverage = cov
     self.files = []
     self.arcs = self.coverage.data.has_arcs()
     self.status = HtmlStatus()
     self.extra_css = None
     self.totals = Numbers()
Beispiel #16
0
    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)
Beispiel #17
0
    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])

        fhtml = open(os.path.join(self.directory, "index.html"), "w")
        try:
            fhtml.write(index_tmpl.render(locals()))
        finally:
            fhtml.close()

        # Write the latest hashes for next time.
        self.status.write(self.directory)
Beispiel #18
0
    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)
Beispiel #19
0
    def __init__(self, cov, config):
        super(HtmlReporter, self).__init__(cov, config)
        self.directory = None
        title = self.config.html_title
        try:
            self.inline_styles = self.config.inline_styles
            self.not_inline_styles = False

            # reading the css stylesheet
            f = open(
                os.path.join(os.path.dirname(__file__),
                             *["htmlfiles", "style.css"]), "rb")
            self.css_styles = f.read().decode('utf-8').strip()
            f.flush()
            f.close()
        except Exception as e:
            print(e)
            self.inline_styles = False
            self.not_inline_styles = True
            self.css_styles = None
        if env.PY2:
            title = title.decode("utf8")
        self.template_globals = {
            'escape': escape,
            'pair': pair,
            'title': title,
            '__url__': coverage.__url__,
            '__version__': coverage.__version__,
        }

        self.source_tmpl = Templite(read_data("pyfile.html"),
                                    self.template_globals)

        self.data = cov.get_data()

        self.files = []
        self.all_files_nums = []
        self.has_arcs = self.data.has_arcs()
        self.status = HtmlStatus()
        self.extra_css = None
        self.totals = Numbers()
        self.time_stamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
Beispiel #20
0
 def try_render(self, text, ctx, result):
     """Render `text` through `ctx`, and it had better be `result`."""
     self.assertEqual(Templite(text).render(ctx), result)