Пример #1
0
    def test_b_branch(self):
        self.output_dir("out/b_branch")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage(branch=True)
            cov.start()
            import b            # pragma: nested
            cov.stop()          # pragma: nested
            cov.html_report(b, directory="../out/b_branch")

        compare("gold_b_branch", "out/b_branch", size_within=10, file_pattern="*.html")
        contains(
            "out/b_branch/b_py.html",
            ('<span class="key">if</span> <span class="nam">x</span> '
             '<span class="op">&lt;</span> <span class="num">2</span>'),
            ('&nbsp; &nbsp; <span class="nam">a</span> <span class="op">=</span> '
             '<span class="num">3</span>'),
            '<span class="pc_cov">70%</span>',
            ('<span class="annotate" title="Line 8 was executed, but never jumped to line 11">'
             '8&#x202F;&#x219B;&#x202F;11 [?]</span>'),
            ('<span class="annotate" title="Line 17 was executed, but never jumped '
             'to the function exit">17&#x202F;&#x219B;&#x202F;exit [?]</span>'),
            ('<span class="annotate" title="Line 25 was executed, but never jumped '
             'to line 26 or line 28">25&#x202F;&#x219B;&#x202F;26,&nbsp;&nbsp; '
             '25&#x202F;&#x219B;&#x202F;28 [?]</span>'),
        )
        contains(
            "out/b_branch/index.html",
            '<a href="b_py.html">b.py</a>',
            '<span class="pc_cov">70%</span>',
            '<td class="right" data-ratio="16 23">70%</td>',
        )
Пример #2
0
    def test_other(self):
        self.make_file("src/here.py", """\
            import other

            if 1 < 2:
                h = 3
            else:
                h = 4
            """)
        self.make_file("othersrc/other.py", """\
            # A file in another directory.  We're checking that it ends up in the
            # HTML report.

            print("This is the other src!")
            """)

        with change_dir("src"):
            sys.path.insert(0, "")          # pytest sometimes has this, sometimes not!?
            sys.path.insert(0, "../othersrc")
            cov = coverage.Coverage(include=["./*", "../othersrc/*"])
            self.start_import_stop(cov, "here")
            cov.html_report(directory="../out")

        # Different platforms will name the "other" file differently. Rename it
        for p in glob.glob("out/*_other_py.html"):
            os.rename(p, "out/blah_blah_other_py.html")

        compare_html(gold_path("html/other"), "out")
        contains(
            "out/index.html",
            '<a href="here_py.html">here.py</a>',
            'other_py.html">', 'other.py</a>',
        )
Пример #3
0
    def test_other(self):
        self.make_file("src/here.py", """\
            import other

            if 1 < 2:
                h = 3
            else:
                h = 4
            """)
        self.make_file("othersrc/other.py", """\
            # A file in another directory.  We're checking that it ends up in the
            # HTML report.

            print("This is the other src!")
            """)

        with change_dir("src"):
            sys.path.insert(0, "")          # pytest sometimes has this, sometimes not!?
            sys.path.insert(0, "../othersrc")
            cov = coverage.Coverage(include=["./*", "../othersrc/*"])
            self.start_import_stop(cov, "here")
            cov.html_report(directory="../out/other")

        # Different platforms will name the "other" file differently. Rename it
        for p in glob.glob("out/other/*_other_py.html"):
            os.rename(p, "out/other/blah_blah_other_py.html")

        compare_html(gold_path("html/other"), "out/other")
        contains(
            "out/other/index.html",
            '<a href="here_py.html">here.py</a>',
            'other_py.html">', 'other.py</a>',
        )
Пример #4
0
    def test_b_branch(self):
        self.output_dir("out/b_branch")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage(branch=True)
            cov.start()
            import b            # pragma: nested
            cov.stop()          # pragma: nested
            cov.html_report(b, directory="../out/b_branch")

        compare("gold_b_branch", "out/b_branch", size_within=10, file_pattern="*.html")
        contains(
            "out/b_branch/b_py.html",
            ('<span class="key">if</span> <span class="nam">x</span> '
             '<span class="op">&lt;</span> <span class="num">2</span>'),
            ('    <span class="nam">a</span> <span class="op">=</span> '
             '<span class="num">3</span>'),
            '<span class="pc_cov">70%</span>',
            ('<span class="annotate short">8&#x202F;&#x219B;&#x202F;11</span>'
             '<span class="annotate long">line 8 didn\'t jump to line 11, because the condition on line 8 was never false</span>'),
            ('<span class="annotate short">17&#x202F;&#x219B;&#x202F;exit</span>'
             '<span class="annotate long">line 17 didn\'t return from function \'two\', because the condition on line 17 was never false</span>'),
            ('<span class="annotate short">25&#x202F;&#x219B;&#x202F;26,&nbsp;&nbsp; '
                                                '25&#x202F;&#x219B;&#x202F;28</span>'
             '<span class="annotate long">2 missed branches: 1) line 25 didn\'t jump to line 26, because the condition on line 25 was never true, 2) line 25 didn\'t jump to line 28, because the condition on line 25 was never false</span>'),
        )
        contains(
            "out/b_branch/index.html",
            '<a href="b_py.html">b.py</a>',
            '<span class="pc_cov">70%</span>',
            '<td class="right" data-ratio="16 23">70%</td>',
        )
Пример #5
0
    def test_partial(self):
        self.output_dir("out/partial")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage(config_file="partial.ini")
            cov.start()
            import partial  # pragma: nested
            cov.stop()  # pragma: nested
            cov.html_report(partial, directory="../out/partial")

        compare_html("gold_partial", "out/partial")
        contains(
            "out/partial/partial_py.html",
            '<p id="t8" class="stm run hide_run">',
            '<p id="t11" class="stm run hide_run">',
            '<p id="t14" class="stm run hide_run">',
            # The "if 0" and "if 1" statements are optimized away.
            '<p id="t17" class="pln">',
            # The "raise AssertionError" is excluded by regex in the .ini.
            '<p id="t24" class="exc">',
        )
        contains(
            "out/partial/index.html",
            '<a href="partial_py.html">partial.py</a>',
        )
        contains("out/partial/index.html", '<span class="pc_cov">100%</span>')
Пример #6
0
    def test_a(self):
        self.output_dir("out/a")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage()
            cov.start()
            import a  # pragma: nested
            cov.stop()  # pragma: nested
            cov.html_report(a, directory='../out/a')

        compare_html("gold_a", "out/a")
        contains(
            "out/a/a_py.html",
            ('<span class="key">if</span> <span class="num">1</span> '
             '<span class="op">&lt;</span> <span class="num">2</span>'),
            ('    <span class="nam">a</span> '
             '<span class="op">=</span> <span class="num">3</span>'),
            '<span class="pc_cov">67%</span>',
        )
        contains(
            "out/a/index.html",
            '<a href="a_py.html">a.py</a>',
            '<span class="pc_cov">67%</span>',
            '<td class="right" data-ratio="2 3">67%</td>',
        )
Пример #7
0
 def test_nonascii_directory(self):
     # https://bitbucket.org/ned/coveragepy/issues/573/cant-generate-xml-report-if-some-source
     self.make_file("테스트/program.py", "a = 1")
     with change_dir("테스트"):
         cov = coverage.Coverage()
         self.start_import_stop(cov, "program")
         cov.xml_report()
Пример #8
0
    def test_partial(self):
        self.output_dir("out/partial")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage(branch=True)
            cov.start()
            import partial          # pragma: nested
            cov.stop()              # pragma: nested
            cov.html_report(partial, directory="../out/partial")

        compare("gold_partial", "out/partial", size_within=10, file_pattern="*.html")
        contains(
            "out/partial/partial_py.html",
            '<p id="t8" class="stm run hide_run">',
            '<p id="t11" class="stm run hide_run">',
            '<p id="t14" class="stm run hide_run">',
            # The "if 0" and "if 1" statements are optimized away.
            '<p id="t17" class="pln">',
        )
        contains(
            "out/partial/index.html",
            '<a href="partial_py.html">partial.py</a>',
        )
        contains(
            "out/partial/index.html",
            '<span class="pc_cov">100%</span>'
        )
Пример #9
0
    def test_partial(self):
        self.output_dir("out/partial")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage(branch=True)
            cov.start()
            import partial          # pragma: nested
            cov.stop()              # pragma: nested
            cov.html_report(partial, directory="../out/partial")

        compare("gold_partial", "out/partial", size_within=10, file_pattern="*.html")
        contains(
            "out/partial/partial_py.html",
            '<p id="t8" class="stm run hide_run">',
            '<p id="t11" class="stm run hide_run">',
            '<p id="t14" class="stm run hide_run">',
            # The "if 0" and "if 1" statements are optimized away.
            '<p id="t17" class="pln">',
        )
        contains(
            "out/partial/index.html",
            '<a href="partial_py.html">partial.py</a>',
        )
        contains(
            "out/partial/index.html",
            '<span class="pc_cov">100%</span>'
        )
Пример #10
0
    def test_a(self):
        self.output_dir("out/a")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage()
            cov.start()
            import a            # pragma: nested
            cov.stop()          # pragma: nested
            cov.html_report(a, directory='../out/a')

        compare("gold_a", "out/a", size_within=10, file_pattern="*.html")
        contains(
            "out/a/a_py.html",
            ('<span class="key">if</span> <span class="num">1</span> '
             '<span class="op">&lt;</span> <span class="num">2</span>'),
            ('    <span class="nam">a</span> '
             '<span class="op">=</span> <span class="num">3</span>'),
            '<span class="pc_cov">67%</span>',
        )
        contains(
            "out/a/index.html",
            '<a href="a_py.html">a.py</a>',
            '<span class="pc_cov">67%</span>',
            '<td class="right" data-ratio="2 3">67%</td>',
        )
Пример #11
0
    def test_styled(self):
        self.output_dir("out/styled")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage()
            cov.start()
            import a            # pragma: nested
            cov.stop()          # pragma: nested
            cov.html_report(a, directory="../out/styled", extra_css="extra.css")

        compare("gold_styled", "out/styled", size_within=10, file_pattern="*.html")
        compare("gold_styled", "out/styled", size_within=10, file_pattern="*.css")
        contains(
            "out/styled/a_py.html",
            '<link rel="stylesheet" href="extra.css" type="text/css">',
            ('<span class="key">if</span> <span class="num">1</span> '
             '<span class="op">&lt;</span> <span class="num">2</span>'),
            ('    <span class="nam">a</span> <span class="op">=</span> '
             '<span class="num">3</span>'),
            '<span class="pc_cov">67%</span>'
        )
        contains(
            "out/styled/index.html",
            '<link rel="stylesheet" href="extra.css" type="text/css">',
            '<a href="a_py.html">a.py</a>',
            '<span class="pc_cov">67%</span>'
        )
Пример #12
0
    def test_unicode(self):
        self.output_dir("out/unicode")

        with change_dir("src"):
            # pylint: disable=import-error, redefined-builtin
            cov = coverage.Coverage()
            cov.start()
            import unicode  # pragma: nested
            cov.stop()  # pragma: nested
            cov.html_report(unicode, directory="../out/unicode")

        compare("gold_unicode",
                "out/unicode",
                size_within=10,
                file_pattern="*.html")
        contains(
            "out/unicode/unicode_py.html",
            '<span class="str">"&#654;d&#729;&#477;b&#592;&#633;&#477;&#652;o&#596;"</span>',
        )

        contains_any(
            "out/unicode/unicode_py.html",
            '<span class="str">"db40,dd00: x&#56128;&#56576;"</span>',
            '<span class="str">"db40,dd00: x&#917760;"</span>',
        )
Пример #13
0
    def test_other(self):
        self.output_dir("out/other")

        with change_dir("src"):
            # pylint: disable=import-error, unused-variable
            sys.path.insert(0, "../othersrc")
            cov = coverage.Coverage(include=["./*", "../othersrc/*"])
            cov.start()
            import here  # pragma: nested
            cov.stop()  # pragma: nested
            cov.html_report(directory="../out/other")

        # Different platforms will name the "other" file differently. Rename it
        for p in glob.glob("out/other/*_other_py.html"):
            os.rename(p, "out/other/blah_blah_other_py.html")

        compare("gold_other",
                "out/other",
                size_within=10,
                file_pattern="*.html")
        contains(
            "out/other/index.html",
            '<a href="here_py.html">here.py</a>',
            'other_py.html">',
            'other.py</a>',
        )
Пример #14
0
 def test_nonascii_directory(self):
     # https://bitbucket.org/ned/coveragepy/issues/573/cant-generate-xml-report-if-some-source
     self.make_file("테스트/program.py", "a = 1")
     with change_dir("테스트"):
         cov = coverage.Coverage()
         self.start_import_stop(cov, "program")
         cov.xml_report()
Пример #15
0
    def test_styled(self):
        self.output_dir("out/styled")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage()
            cov.start()
            import a  # pragma: nested
            cov.stop()  # pragma: nested
            cov.html_report(a,
                            directory="../out/styled",
                            extra_css="extra.css")

        compare_html("gold_styled", "out/styled")
        compare("gold_styled",
                "out/styled",
                size_within=10,
                file_pattern="*.css")
        contains("out/styled/a_py.html",
                 '<link rel="stylesheet" href="extra.css" type="text/css">',
                 ('<span class="key">if</span> <span class="num">1</span> '
                  '<span class="op">&lt;</span> <span class="num">2</span>'),
                 ('    <span class="nam">a</span> <span class="op">=</span> '
                  '<span class="num">3</span>'),
                 '<span class="pc_cov">67%</span>')
        contains("out/styled/index.html",
                 '<link rel="stylesheet" href="extra.css" type="text/css">',
                 '<a href="a_py.html">a.py</a>',
                 '<span class="pc_cov">67%</span>')
Пример #16
0
    def test_omit_3(self):
        self.output_dir("out/omit_3")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage(include=["./*"])
            cov.start()
            import main  # pragma: nested # pylint: disable=unused-variable
            cov.stop()  # pragma: nested
            cov.html_report(directory="../out/omit_3", omit=["m1.py", "m2.py"])

        compare_html("gold_omit_3", "out/omit_3")
Пример #17
0
    def test_omit_4(self):
        self.output_dir("out/omit_4")

        with change_dir("src"):
            # pylint: disable=import-error, unused-variable
            cov = coverage.Coverage(config_file="omit4.ini", include=["./*"])
            cov.start()
            import main         # pragma: nested
            cov.stop()          # pragma: nested
            cov.html_report(directory="../out/omit_4")

        compare("gold_omit_4", "out/omit_4", size_within=10, file_pattern="*.html")
Пример #18
0
    def test_omit_5(self):
        self.output_dir("out/omit_5")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage(config_file="omit5.ini", include=["./*"])
            cov.start()
            import main  # pragma: nested # pylint: disable=unused-variable
            cov.stop()  # pragma: nested
            cov.html_report()

        compare_html("gold_omit_5", "out/omit_5")
Пример #19
0
    def test_omit_5(self):
        self.output_dir("out/omit_5")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage(config_file="omit5.ini", include=["./*"])
            cov.start()
            import main         # pragma: nested
            cov.stop()          # pragma: nested
            cov.html_report()

        compare("gold_omit_5", "out/omit_5", size_within=10, file_pattern="*.html")
Пример #20
0
    def test_omit_3(self):
        self.output_dir("out/omit_3")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage(include=["./*"])
            cov.start()
            import main         # pragma: nested
            cov.stop()          # pragma: nested
            cov.html_report(directory="../out/omit_3", omit=["m1.py", "m2.py"])

        compare("gold_omit_3", "out/omit_3", size_within=10, file_pattern="*.html")
Пример #21
0
    def test_bom(self):
        self.output_dir("out/bom")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage()
            cov.start()
            import bom          # pragma: nested
            cov.stop()          # pragma: nested
            cov.html_report(bom, directory="../out/bom")

        compare("gold_bom", "out/bom", size_within=10, file_pattern="*.html")
        contains(
            "out/bom/bom_py.html",
            '<span class="str">&quot;3&#215;4 = 12, &#247;2 = 6&#177;0&quot;</span>',
        )
Пример #22
0
    def test_isolatin1(self):
        self.output_dir("out/isolatin1")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage()
            cov.start()
            import isolatin1            # pragma: nested
            cov.stop()                  # pragma: nested
            cov.html_report(isolatin1, directory="../out/isolatin1")

        compare("gold_isolatin1", "out/isolatin1", size_within=10, file_pattern="*.html")
        contains(
            "out/isolatin1/isolatin1_py.html",
            '<span class="str">"3&#215;4 = 12, &#247;2 = 6&#177;0"</span>',
        )
Пример #23
0
    def test_isolatin1(self):
        self.output_dir("out/isolatin1")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage()
            cov.start()
            import isolatin1  # pragma: nested
            cov.stop()  # pragma: nested
            cov.html_report(isolatin1, directory="../out/isolatin1")

        compare_html("gold_isolatin1", "out/isolatin1")
        contains(
            "out/isolatin1/isolatin1_py.html",
            '<span class="str">"3&#215;4 = 12, &#247;2 = 6&#177;0"</span>',
        )
Пример #24
0
    def test_bom(self):
        self.output_dir("out/bom")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage()
            cov.start()
            import bom          # pragma: nested
            cov.stop()          # pragma: nested
            cov.html_report(bom, directory="../out/bom")

        compare("gold_bom", "out/bom", size_within=10, file_pattern="*.html")
        contains(
            "out/bom/bom_py.html",
            '<span class="str">"3&#215;4 = 12, &#247;2 = 6&#177;0"</span>',
        )
Пример #25
0
    def test_a_xml_2(self):
        self.output_dir("out/xml_2")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage(config_file="run_a_xml_2.ini")
            cov.start()
            import a            # pragma: nested
            cov.stop()          # pragma: nested
            cov.xml_report(a)
            source_path = coverage.files.relative_directory().rstrip(r"\/")

        compare("gold_x_xml", "out/xml_2", scrubs=[
            (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
            (r' version="[-.\w]+"', ' version="VERSION"'),
            (r'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_path),
            (r'/coverage.readthedocs.io/?[-.\w/]*', '/coverage.readthedocs.io/VER'),
        ])
Пример #26
0
    def test_y_xml_branch(self):
        self.output_dir("out/y_xml_branch")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage(branch=True)
            cov.start()
            import y            # pragma: nested
            cov.stop()          # pragma: nested
            cov.xml_report(y, outfile="../out/y_xml_branch/coverage.xml")
            source_path = coverage.files.relative_directory().rstrip(r"\/")

        compare("gold_y_xml_branch", "out/y_xml_branch", scrubs=[
            (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
            (r' version="[-.\w]+"', ' version="VERSION"'),
            (r'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_path),
            (r'/coverage.readthedocs.io/?[-.\w/]*', '/coverage.readthedocs.io/VER'),
        ])
Пример #27
0
    def test_y_xml_branch(self):
        self.output_dir("out/y_xml_branch")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage(branch=True)
            cov.start()
            import y            # pragma: nested
            cov.stop()          # pragma: nested
            cov.xml_report(y, outfile="../out/y_xml_branch/coverage.xml")
            source_path = coverage.files.relative_directory().rstrip(r"\/")

        compare("gold_y_xml_branch", "out/y_xml_branch", scrubs=[
            (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
            (r' version="[-.\w]+"', ' version="VERSION"'),
            (r'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_path),
            (r'/coverage.readthedocs.io/?[-.\w/]*', '/coverage.readthedocs.io/VER'),
        ])
Пример #28
0
    def test_a_xml_2(self):
        self.output_dir("out/xml_2")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage(config_file="run_a_xml_2.ini")
            cov.start()
            import a            # pragma: nested
            cov.stop()          # pragma: nested
            cov.xml_report(a)
            source_path = coverage.files.relative_directory().rstrip(r"\/")

        compare("gold_x_xml", "out/xml_2", scrubs=[
            (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
            (r' version="[-.\w]+"', ' version="VERSION"'),
            (r'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_path),
            (r'/coverage.readthedocs.io/?[-.\w/]*', '/coverage.readthedocs.io/VER'),
        ])
Пример #29
0
    def test_b_branch(self):
        self.output_dir("out/b_branch")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage(branch=True)
            cov.start()
            import b  # pragma: nested
            cov.stop()  # pragma: nested
            cov.html_report(b, directory="../out/b_branch")

        compare("gold_b_branch",
                "out/b_branch",
                size_within=10,
                file_pattern="*.html")
        contains(
            "out/b_branch/b_py.html",
            ('<span class="key">if</span> <span class="nam">x</span> '
             '<span class="op">&lt;</span> <span class="num">2</span>'),
            ('    <span class="nam">a</span> <span class="op">=</span> '
             '<span class="num">3</span>'),
            '<span class="pc_cov">70%</span>',
            ('<span class="annotate short">8&#x202F;&#x219B;&#x202F;11</span>'
             '<span class="annotate long">line 8 didn\'t jump to line 11, '
             'because the condition on line 8 was never false</span>'),
            ('<span class="annotate short">17&#x202F;&#x219B;&#x202F;exit</span>'
             '<span class="annotate long">line 17 didn\'t return from function \'two\', '
             'because the condition on line 17 was never false</span>'),
            ('<span class="annotate short">25&#x202F;&#x219B;&#x202F;26,&nbsp;&nbsp; '
             '25&#x202F;&#x219B;&#x202F;28</span>'
             '<span class="annotate long">2 missed branches: '
             '1) line 25 didn\'t jump to line 26, '
             'because the condition on line 25 was never true, '
             '2) line 25 didn\'t jump to line 28, '
             'because the condition on line 25 was never false</span>'),
        )
        contains(
            "out/b_branch/index.html",
            '<a href="b_py.html">b.py</a>',
            '<span class="pc_cov">70%</span>',
            '<td class="right" data-ratio="16 23">70%</td>',
        )
Пример #30
0
    def test_unicode(self):
        self.output_dir("out/unicode")

        with change_dir("src"):
            # pylint: disable=import-error, redefined-builtin
            cov = coverage.Coverage()
            cov.start()
            import unicode          # pragma: nested
            cov.stop()              # pragma: nested
            cov.html_report(unicode, directory="../out/unicode")

        compare("gold_unicode", "out/unicode", size_within=10, file_pattern="*.html")
        contains(
            "out/unicode/unicode_py.html",
            '<span class="str">"&#654;d&#729;&#477;b&#592;&#633;&#477;&#652;o&#596;"</span>',
        )

        contains_any(
            "out/unicode/unicode_py.html",
            '<span class="str">"db40,dd00: x&#56128;&#56576;"</span>',
            '<span class="str">"db40,dd00: x&#917760;"</span>',
        )
Пример #31
0
    def test_other(self):
        self.output_dir("out/other")

        with change_dir("src"):
            # pylint: disable=import-error
            sys.path.insert(0, "../othersrc")
            cov = coverage.Coverage(include=["./*", "../othersrc/*"])
            cov.start()
            import here         # pragma: nested
            cov.stop()          # pragma: nested
            cov.html_report(directory="../out/other")

        # Different platforms will name the "other" file differently. Rename it
        for p in glob.glob("out/other/*_other_py.html"):
            os.rename(p, "out/other/blah_blah_other_py.html")

        compare("gold_other", "out/other", size_within=10, file_pattern="*.html")
        contains(
            "out/other/index.html",
            '<a href="here_py.html">here.py</a>',
            'other_py.html">', 'other.py</a>',
        )
Пример #32
0
    def test_bom(self):
        self.output_dir("out/bom")

        with change_dir("src"):
            # It's important that the source file really have a BOM, which can
            # get lost, so check that it's really there.
            with open("bom.py", "rb") as f:
                first_three = f.read(3)
                assert first_three == b"\xef\xbb\xbf"

            # pylint: disable=import-error
            cov = coverage.Coverage()
            cov.start()
            import bom  # pragma: nested
            cov.stop()  # pragma: nested
            cov.html_report(bom, directory="../out/bom")

        compare_html("gold_bom", "out/bom")
        contains(
            "out/bom/bom_py.html",
            '<span class="str">"3&#215;4 = 12, &#247;2 = 6&#177;0"</span>',
        )
Пример #33
0
    def test_tabbed(self):
        self.output_dir("out/tabbed")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage()
            cov.start()
            import tabbed  # pragma: nested
            cov.stop()  # pragma: nested
            cov.html_report(tabbed, directory="../out/tabbed")

        # Editors like to change things, make sure our source file still has tabs.
        contains("src/tabbed.py", "\tif x:\t\t\t\t\t# look nice")

        contains(
            "out/tabbed/tabbed_py.html",
            '>        <span class="key">if</span> '
            '<span class="nam">x</span><span class="op">:</span>'
            '                                   '
            '<span class="com"># look nice</span>')

        doesnt_contain("out/tabbed/tabbed_py.html", "\t")
Пример #34
0
    def test_tabbed(self):
        self.output_dir("out/tabbed")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage()
            cov.start()
            import tabbed           # pragma: nested
            cov.stop()              # pragma: nested
            cov.html_report(tabbed, directory="../out/tabbed")

        # Editors like to change things, make sure our source file still has tabs.
        contains("src/tabbed.py", "\tif x:\t\t\t\t\t# look nice")

        contains(
            "out/tabbed/tabbed_py.html",
            '>        <span class="key">if</span> '
            '<span class="nam">x</span><span class="op">:</span>'
            '                                   '
            '<span class="com"># look nice</span>'
        )

        doesnt_contain("out/tabbed/tabbed_py.html", "\t")