Пример #1
0
    def test_sub_python_is_this_python(self):
        # Try it with a Python command.
        self.set_environ('COV_FOOBAR', 'XYZZY')
        self.make_file("showme.py", """\
            import os, sys
            print(sys.executable)
            print(os.__file__)
            print(os.environ['COV_FOOBAR'])
            """)
        out = self.run_command("python showme.py").splitlines()
        self.assertEqual(actual_path(out[0]), actual_path(sys.executable))
        self.assertEqual(out[1], os.__file__)
        self.assertEqual(out[2], 'XYZZY')

        # Try it with a "coverage debug sys" command.
        out = self.run_command("coverage debug sys")

        executable = re_line(out, "executable:")
        executable = executable.split(":", 1)[1].strip()
        self.assertTrue(_same_python_executable(executable, sys.executable))

        # "environment: COV_FOOBAR = XYZZY" or "COV_FOOBAR = XYZZY"
        environ = re_line(out, "COV_FOOBAR")
        _, _, environ = environ.rpartition(":")
        self.assertEqual(environ.strip(), "COV_FOOBAR = XYZZY")
Пример #2
0
    def test_sub_python_is_this_python(self):
        # Try it with a Python command.
        self.set_environ('COV_FOOBAR', 'XYZZY')
        self.make_file(
            "showme.py", """\
            import os, sys
            print(sys.executable)
            print(os.__file__)
            print(os.environ['COV_FOOBAR'])
            """)
        out = self.run_command("python showme.py").splitlines()
        self.assertEqual(actual_path(out[0]), actual_path(sys.executable))
        self.assertEqual(out[1], os.__file__)
        self.assertEqual(out[2], 'XYZZY')

        # Try it with a "coverage debug sys" command.
        out = self.run_command("coverage debug sys")

        executable = re_line(out, "executable:")
        executable = executable.split(":", 1)[1].strip()
        self.assertTrue(_same_python_executable(executable, sys.executable))

        # "environment: COV_FOOBAR = XYZZY" or "COV_FOOBAR = XYZZY"
        environ = re_line(out, "COV_FOOBAR")
        _, _, environ = environ.rpartition(":")
        self.assertEqual(environ.strip(), "COV_FOOBAR = XYZZY")
Пример #3
0
 def test_empty_file_is_100_not_0(self):
     # https://bitbucket.org/ned/coveragepy/issue/345
     cov = self.run_doit()
     cov.xml_report(outfile="-")
     xml = self.stdout()
     init_line = re_line(xml, 'filename="sub/__init__.py"')
     self.assertIn('line-rate="1"', init_line)
Пример #4
0
 def test_debug_pybehave(self):
     out_text = self.f1_debug_output(["pybehave"])
     out_lines = out_text.splitlines()
     assert 10 < len(out_lines) < 40
     pyversion = re_line(r" PYVERSION:", out_text)
     vtuple = ast.literal_eval(pyversion.partition(":")[-1].strip())
     assert vtuple[:5] == sys.version_info
Пример #5
0
 def test_filename_format_including_module(self):
     cov = self.run_doit()
     import sub.doit                         # pylint: disable=import-error
     cov.xml_report([sub.doit], outfile="-")
     xml = self.stdout()
     doit_line = re_line(xml, "class.*doit")
     self.assertIn('filename="sub/doit.py"', doit_line)
Пример #6
0
 def test_debug_sys_ctracer(self):
     out_lines = self.f1_debug_output(["sys"])
     tracer_line = re_line(out_lines, r"CTracer:").strip()
     if env.C_TRACER:
         expected = "CTracer: available"
     else:
         expected = "CTracer: unavailable"
     assert expected == tracer_line
Пример #7
0
 def test_debug_sys_ctracer(self):
     out_lines = self.f1_debug_output(["sys"])
     tracer_line = re_line(out_lines, r"CTracer:").strip()
     if C_TRACER:
         expected = "CTracer: available"
     else:
         expected = "CTracer: unavailable"
     self.assertEqual(expected, tracer_line)
Пример #8
0
 def test_debug_pybehave(self):
     self.command_line("debug pybehave")
     out = self.stdout()
     assert " CPYTHON:" in out
     assert " PYVERSION:" in out
     assert " pep626:" in out
     pyversion = re_line(r" PYVERSION:", out)
     vtuple = ast.literal_eval(pyversion.partition(":")[-1].strip())
     assert vtuple[:5] == sys.version_info
Пример #9
0
 def test_reporting_on_nothing(self):
     # Used to raise a zero division error:
     # https://bitbucket.org/ned/coveragepy/issue/250
     self.make_file("empty.py", "")
     cov = coverage.Coverage()
     empty = self.start_import_stop(cov, "empty")
     cov.xml_report([empty], outfile="-")
     xml = self.stdout()
     empty_line = re_line(xml, "class.*empty")
     self.assertIn('filename="empty.py"', empty_line)
     self.assertIn('line-rate="1"', empty_line)
Пример #10
0
    def test_bad(self):
        self.make_file("out/gettysburg.txt", BAD_GETTY)

        # compare() raises an assertion.
        msg = rf"Files differ: .*{GOLD_PATH_RX} != {OUT_PATH_RX}"
        with pytest.raises(AssertionError, match=msg):
            compare(gold_path("testing/getty"), "out", scrubs=SCRUBS)

        # Stdout has a description of the diff.  The diff shows the scrubbed content.
        stdout = self.stdout()
        assert "- Four score" in stdout
        assert "+ Five score" in stdout
        assert re_line(rf"^:::: diff '.*{GOLD_PATH_RX}' and '{OUT_PATH_RX}'",
                       stdout)
        assert re_line(
            rf"^:::: end diff '.*{GOLD_PATH_RX}' and '{OUT_PATH_RX}'", stdout)
        assert "  D/D/D, Gxxx, Pennsylvania" in stdout

        # The actual file was saved.
        with open(ACTUAL_GETTY_FILE) as f:
            saved = f.read()
        assert saved == BAD_GETTY
Пример #11
0
 def test_filename_format_showing_everything(self):
     cov = self.run_doit()
     cov.xml_report(outfile="-")
     xml = self.stdout()
     doit_line = re_line(xml, "class.*doit")
     self.assertIn('filename="sub/doit.py"', doit_line)
Пример #12
0
def test_re_line(text, pat, result):
    assert re_line(text, pat) == result
Пример #13
0
def test_re_line_bad(text, pat):
    with pytest.raises(AssertionError):
        re_line(text, pat)
Пример #14
0
 def test_re_line_bad(self, pat, text):
     with pytest.raises(AssertionError):
         re_line(pat, text)
Пример #15
0
def test_re_line(text, pat, result):
    assert re_line(text, pat) == result
Пример #16
0
def test_re_line_bad(text, pat):
    with pytest.raises(AssertionError):
        re_line(text, pat)
Пример #17
0
 def test_re_line(self, pat, text, result):
     assert re_line(pat, text) == result
Пример #18
0
 def test_filename_format_including_filename(self):
     cov = self.run_doit()
     cov.xml_report(["sub/doit.py"], outfile="-")
     xml = self.stdout()
     doit_line = re_line(xml, "class.*doit")
     self.assertIn('filename="sub/doit.py"', doit_line)