Python coverage.CoverageData() Examples
The following are 30
code examples of coverage.CoverageData().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
coverage
, or try the search function
.
Example #1
Source File: conftest.py From mutatest with MIT License | 8 votes |
def write_cov_file(line_data: Dict[str, List[int]], fname: str) -> None: """Write a coverage file supporting both Coverage v4 and v5. Args: line_data: Dictionary of line data for the coverage file. fname: string filename for output location (absolute path) Returns: None """ if coverage.version_info[0] == 4: covdata = coverage.CoverageData() covdata.add_lines(line_data) covdata.write_file(fname) else: # assume coverage v 5 covdata = coverage.CoverageData(basename=fname) covdata.add_lines(line_data) covdata.write() #################################################################################################### # CLI: MOCK ARGS ####################################################################################################
Example #2
Source File: runner.py From recipes-py with Apache License 2.0 | 6 votes |
def _cover_all_imports(main_repo): # If our process is supposed to collect coverage for all recipe module # imports, do that after we recieve the first Description. This way we can # reply to the main process with an Outcome. Otherwise the main process # could be blocked on writing a Description while we're trying to write an # Outcome. if not main_repo.modules: # Prevents a coverage warning when there are no modules to collect coverage # from. return coverage.CoverageData() mod_dir_base = os.path.join(main_repo.recipes_root_path, 'recipe_modules') cov = coverage.Coverage(config_file=False, include=[ os.path.join(mod_dir_base, '*', '*.py') ]) cov.start() for module in main_repo.modules.itervalues(): # Allow exceptions to raise here; they'll be reported as a 'global' # failure. module.do_import() cov.stop() return cov.get_data() # administrative stuff (main, pipe handling, etc.)
Example #3
Source File: control.py From coveragepy with Apache License 2.0 | 6 votes |
def get_data(self): """Get the collected data. Also warn about various problems collecting data. Returns a :class:`coverage.CoverageData`, the collected coverage data. .. versionadded:: 4.0 """ self._init() self._init_data(suffix=None) self._post_init() if self._collector and self._collector.flush_data(): self._post_save_work() return self._data
Example #4
Source File: control.py From coveragepy-bbmirror with Apache License 2.0 | 6 votes |
def get_data(self): """Get the collected data. Also warn about various problems collecting data. Returns a :class:`coverage.CoverageData`, the collected coverage data. .. versionadded:: 4.0 """ self._init() if self._collector.save_data(self.data): self._post_save_work() return self.data
Example #5
Source File: test_process.py From coveragepy with Apache License 2.0 | 6 votes |
def test_append_data_with_different_file(self): self.make_b_or_c_py() self.make_file(".coveragerc", """\ [run] data_file = .mycovdata """) out = self.run_command("coverage run b_or_c.py b") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") self.assert_exists(".mycovdata") out = self.run_command("coverage run --append b_or_c.py c") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") self.assert_exists(".mycovdata") # Read the coverage file and see that b_or_c.py has all 8 lines # executed. data = coverage.CoverageData(".mycovdata") data.read() self.assertEqual(line_counts(data)['b_or_c.py'], 8)
Example #6
Source File: test_process.py From coveragepy with Apache License 2.0 | 6 votes |
def test_append_data(self): self.make_b_or_c_py() out = self.run_command("coverage run b_or_c.py b") self.assertEqual(out, 'done\n') self.assert_exists(".coverage") self.assert_file_count(".coverage.*", 0) out = self.run_command("coverage run --append b_or_c.py c") self.assertEqual(out, 'done\n') self.assert_exists(".coverage") self.assert_file_count(".coverage.*", 0) # Read the coverage file and see that b_or_c.py has all 8 lines # executed. data = coverage.CoverageData() data.read() self.assertEqual(line_counts(data)['b_or_c.py'], 8)
Example #7
Source File: test_concurrency.py From coveragepy-bbmirror with Apache License 2.0 | 5 votes |
def try_some_code(self, code, concurrency, the_module, expected_out=None): """Run some concurrency testing code and see that it was all covered. `code` is the Python code to execute. `concurrency` is the name of the concurrency regime to test it under. `the_module` is the imported module that must be available for this to work at all. `expected_out` is the text we expect the code to produce. """ self.make_file("try_it.py", code) cmd = "coverage run --concurrency=%s try_it.py" % concurrency out = self.run_command(cmd) expected_cant_trace = cant_trace_msg(concurrency, the_module) if expected_cant_trace is not None: self.assertEqual(out, expected_cant_trace) else: # We can fully measure the code if we are using the C tracer, which # can support all the concurrency, or if we are using threads. if expected_out is None: expected_out = "%d\n" % (sum(range(self.QLIMIT))) print(code) self.assertEqual(out, expected_out) # Read the coverage file and see that try_it.py has all its lines # executed. data = coverage.CoverageData() data.read_file(".coverage") # If the test fails, it's helpful to see this info: fname = abs_file("try_it.py") linenos = data.lines(fname) print("{0}: {1}".format(len(linenos), linenos)) print_simple_annotation(code, linenos) lines = line_count(code) self.assertEqual(data.line_counts()['try_it.py'], lines)
Example #8
Source File: test_pytest_cov.py From pytest-cov with MIT License | 5 votes |
def test_contexts(testdir, opts): with open(os.path.join(os.path.dirname(__file__), "contextful.py")) as f: contextful_tests = f.read() script = testdir.makepyfile(contextful_tests) result = testdir.runpytest('-v', '--cov=%s' % script.dirpath(), '--cov-context=test', script, *opts.split() ) assert result.ret == 0 result.stdout.fnmatch_lines([ 'test_contexts* 100%*', ]) data = coverage.CoverageData(".coverage") data.read() assert data.measured_contexts() == set(EXPECTED_CONTEXTS) measured = data.measured_files() assert len(measured) == 1 test_context_path = list(measured)[0] assert test_context_path.lower() == os.path.abspath("test_contexts.py").lower() line_data = find_labels(contextful_tests, r"[crst]\d+(?:-\d+)?") for context, label in EXPECTED_CONTEXTS.items(): if context == '': continue data.set_query_context(context) actual = set(data.lines(test_context_path)) assert line_data[label] == actual, "Wrong lines for context {!r}".format(context)
Example #9
Source File: control.py From coveragepy with Apache License 2.0 | 5 votes |
def _init_data(self, suffix): """Create a data file if we don't have one yet.""" if self._data is None: # Create the data file. We do this at construction time so that the # data file will be written into the directory where the process # started rather than wherever the process eventually chdir'd to. ensure_dir_for_file(self.config.data_file) self._data = CoverageData( basename=self.config.data_file, suffix=suffix, warn=self._warn, debug=self._debug, no_disk=self._no_disk, )
Example #10
Source File: test_process.py From coveragepy with Apache License 2.0 | 5 votes |
def test_combine_parallel_data(self): self.make_b_or_c_py() out = self.run_command("coverage run -p b_or_c.py b") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") self.assert_file_count(".coverage.*", 1) out = self.run_command("coverage run -p b_or_c.py c") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") # After two -p runs, there should be two .coverage.machine.123 files. self.assert_file_count(".coverage.*", 2) # Combine the parallel coverage data files into .coverage . self.run_command("coverage combine") self.assert_exists(".coverage") # After combining, there should be only the .coverage file. self.assert_file_count(".coverage.*", 0) # Read the coverage file and see that b_or_c.py has all 8 lines # executed. data = coverage.CoverageData() data.read() self.assertEqual(line_counts(data)['b_or_c.py'], 8) # Running combine again should fail, because there are no parallel data # files to combine. status, out = self.run_command_status("coverage combine") self.assertEqual(status, 1) self.assertEqual(out, "No data to combine\n") # And the originally combined data is still there. data = coverage.CoverageData() data.read() self.assertEqual(line_counts(data)['b_or_c.py'], 8)
Example #11
Source File: test_process.py From coveragepy with Apache License 2.0 | 5 votes |
def test_combine_parallel_data_with_a_corrupt_file(self): self.make_b_or_c_py() out = self.run_command("coverage run -p b_or_c.py b") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") self.assert_file_count(".coverage.*", 1) out = self.run_command("coverage run -p b_or_c.py c") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") # After two -p runs, there should be two .coverage.machine.123 files. self.assert_file_count(".coverage.*", 2) # Make a bogus data file. self.make_file(".coverage.bad", "This isn't a coverage data file.") # Combine the parallel coverage data files into .coverage . out = self.run_command("coverage combine") self.assert_exists(".coverage") self.assert_exists(".coverage.bad") warning_regex = ( r"Coverage.py warning: Couldn't use data file '.*\.coverage\.bad': " r"file (is encrypted or )?is not a database" ) self.assertRegex(out, warning_regex) # After combining, those two should be the only data files. self.assert_file_count(".coverage.*", 1) # Read the coverage file and see that b_or_c.py has all 8 lines # executed. data = coverage.CoverageData() data.read() self.assertEqual(line_counts(data)['b_or_c.py'], 8)
Example #12
Source File: test_process.py From coveragepy with Apache License 2.0 | 5 votes |
def test_combine_no_usable_files(self): # https://bitbucket.org/ned/coveragepy/issues/629/multiple-use-of-combine-leads-to-empty self.make_b_or_c_py() out = self.run_command("coverage run b_or_c.py b") self.assertEqual(out, 'done\n') self.assert_exists(".coverage") self.assert_file_count(".coverage.*", 0) # Make bogus data files. self.make_file(".coverage.bad1", "This isn't a coverage data file.") self.make_file(".coverage.bad2", "This isn't a coverage data file.") # Combine the parallel coverage data files into .coverage, but nothing is readable. status, out = self.run_command_status("coverage combine") self.assertEqual(status, 1) for n in "12": self.assert_exists(".coverage.bad{}".format(n)) warning_regex = ( r"Coverage.py warning: Couldn't use data file '.*\.coverage.bad{0}': " r"file (is encrypted or )?is not a database" .format(n) ) self.assertRegex(out, warning_regex) self.assertRegex(out, r"No usable data files") # After combining, we should have a main file and two parallel files. self.assert_exists(".coverage") self.assert_file_count(".coverage.*", 2) # Read the coverage file and see that b_or_c.py has 6 lines # executed (we only did b, not c). data = coverage.CoverageData() data.read() self.assertEqual(line_counts(data)['b_or_c.py'], 6)
Example #13
Source File: test_process.py From coveragepy with Apache License 2.0 | 5 votes |
def test_combine_parallel_data_no_append(self): self.make_b_or_c_py() out = self.run_command("coverage run -p b_or_c.py b") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") self.assert_file_count(".coverage.*", 1) # Combine the (one) parallel coverage data file into .coverage . self.run_command("coverage combine") self.assert_exists(".coverage") self.assert_file_count(".coverage.*", 0) out = self.run_command("coverage run -p b_or_c.py c") self.assertEqual(out, 'done\n') self.assert_exists(".coverage") self.assert_file_count(".coverage.*", 1) # Combine the parallel coverage data files into .coverage, but don't # use the data in .coverage already. self.run_command("coverage combine") self.assert_exists(".coverage") # After combining, there should be only the .coverage file. self.assert_file_count(".coverage.*", 0) # Read the coverage file and see that b_or_c.py has only 7 lines # because we didn't keep the data from running b. data = coverage.CoverageData() data.read() self.assertEqual(line_counts(data)['b_or_c.py'], 7)
Example #14
Source File: test_process.py From coveragepy with Apache License 2.0 | 5 votes |
def test_append_can_create_a_data_file(self): self.make_b_or_c_py() out = self.run_command("coverage run --append b_or_c.py b") self.assertEqual(out, 'done\n') self.assert_exists(".coverage") self.assert_file_count(".coverage.*", 0) # Read the coverage file and see that b_or_c.py has only 6 lines # executed. data = coverage.CoverageData() data.read() self.assertEqual(line_counts(data)['b_or_c.py'], 6)
Example #15
Source File: test_process.py From coveragepy with Apache License 2.0 | 5 votes |
def test_combine_with_rc(self): self.make_b_or_c_py() self.make_file(".coveragerc", """\ [run] source = . parallel = true """) out = self.run_command("coverage run b_or_c.py b") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") out = self.run_command("coverage run b_or_c.py c") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") # After two runs, there should be two .coverage.machine.123 files. self.assert_file_count(".coverage.*", 2) # Combine the parallel coverage data files into .coverage . self.run_command("coverage combine") self.assert_exists(".coverage") self.assert_exists(".coveragerc") # After combining, there should be only the .coverage file. self.assert_file_count(".coverage.*", 0) # Read the coverage file and see that b_or_c.py has all 8 lines # executed. data = coverage.CoverageData() data.read() self.assertEqual(line_counts(data)['b_or_c.py'], 8) # Reporting should still work even with the .rc file out = self.run_command("coverage report") self.assertMultiLineEqual(out, textwrap.dedent("""\ Name Stmts Miss Cover ------------------------------- b_or_c.py 8 0 100% """))
Example #16
Source File: test_process.py From coveragepy with Apache License 2.0 | 5 votes |
def test_fullcoverage(self): # pragma: no metacov if env.PY2: # This doesn't work on Python 2. self.skipTest("fullcoverage doesn't work on Python 2.") # It only works with the C tracer, and if we aren't measuring ourselves. if not env.C_TRACER or env.METACOV: self.skipTest("fullcoverage only works with the C tracer.") # fullcoverage is a trick to get stdlib modules measured from # the very beginning of the process. Here we import os and # then check how many lines are measured. self.make_file("getenv.py", """\ import os print("FOOEY == %s" % os.getenv("FOOEY")) """) fullcov = os.path.join( os.path.dirname(coverage.__file__), "fullcoverage" ) self.set_environ("FOOEY", "BOO") self.set_environ("PYTHONPATH", fullcov) out = self.run_command("python -m coverage run -L getenv.py") self.assertEqual(out, "FOOEY == BOO\n") data = coverage.CoverageData() data.read() # The actual number of executed lines in os.py when it's # imported is 120 or so. Just running os.getenv executes # about 5. self.assertGreater(line_counts(data)['os.py'], 50)
Example #17
Source File: test_process.py From coveragepy with Apache License 2.0 | 5 votes |
def test_excepthook(self): self.make_file("excepthook.py", """\ import sys def excepthook(*args): print('in excepthook') if maybe == 2: print('definitely') sys.excepthook = excepthook maybe = 1 raise RuntimeError('Error Outside') """) cov_st, cov_out = self.run_command_status("coverage run excepthook.py") py_st, py_out = self.run_command_status("python excepthook.py") if not env.JYTHON: self.assertEqual(cov_st, py_st) self.assertEqual(cov_st, 1) self.assertIn("in excepthook", py_out) self.assertEqual(cov_out, py_out) # Read the coverage file and see that excepthook.py has 7 lines # executed. data = coverage.CoverageData() data.read() self.assertEqual(line_counts(data)['excepthook.py'], 7)
Example #18
Source File: test_process.py From coveragepy with Apache License 2.0 | 5 votes |
def test_subprocess_with_pth_files(self): # pragma: no metacov if env.METACOV: self.skipTest("Can't test sub-process pth file suppport during metacoverage") # An existing data file should not be read when a subprocess gets # measured automatically. Create the data file here with bogus data in # it. data = coverage.CoverageData(".mycovdata") data.add_lines({os.path.abspath('sub.py'): dict.fromkeys(range(100))}) data.write() self.make_file("coverage.ini", """\ [run] data_file = .mycovdata """) self.set_environ("COVERAGE_PROCESS_START", "coverage.ini") import main # pylint: disable=unused-import with open("out.txt") as f: self.assertEqual(f.read(), "Hello, world!\n") # Read the data from .coverage self.assert_exists(".mycovdata") data = coverage.CoverageData(".mycovdata") data.read() self.assertEqual(line_counts(data)['sub.py'], 3)
Example #19
Source File: test_process.py From coveragepy with Apache License 2.0 | 5 votes |
def test_subprocess_with_pth_files_and_parallel(self): # pragma: no metacov # https://bitbucket.org/ned/coveragepy/issues/492/subprocess-coverage-strange-detection-of if env.METACOV: self.skipTest("Can't test sub-process pth file suppport during metacoverage") self.make_file("coverage.ini", """\ [run] parallel = true """) self.set_environ("COVERAGE_PROCESS_START", "coverage.ini") self.run_command("coverage run main.py") with open("out.txt") as f: self.assertEqual(f.read(), "Hello, world!\n") self.run_command("coverage combine") # assert that the combined .coverage data file is correct self.assert_exists(".coverage") data = coverage.CoverageData() data.read() self.assertEqual(line_counts(data)['sub.py'], 3) # assert that there are *no* extra data files left over after a combine data_files = glob.glob(os.getcwd() + '/.coverage*') self.assertEqual(len(data_files), 1, "Expected only .coverage after combine, looks like there are " "extra data files that were not cleaned up: %r" % data_files)
Example #20
Source File: test_concurrency.py From coveragepy with Apache License 2.0 | 5 votes |
def try_some_code(self, code, concurrency, the_module, expected_out=None): """Run some concurrency testing code and see that it was all covered. `code` is the Python code to execute. `concurrency` is the name of the concurrency regime to test it under. `the_module` is the imported module that must be available for this to work at all. `expected_out` is the text we expect the code to produce. """ self.make_file("try_it.py", code) cmd = "coverage run --concurrency=%s try_it.py" % concurrency out = self.run_command(cmd) expected_cant_trace = cant_trace_msg(concurrency, the_module) if expected_cant_trace is not None: self.assertEqual(out, expected_cant_trace) else: # We can fully measure the code if we are using the C tracer, which # can support all the concurrency, or if we are using threads. if expected_out is None: expected_out = "%d\n" % (sum(range(self.QLIMIT))) print(code) self.assertEqual(out, expected_out) # Read the coverage file and see that try_it.py has all its lines # executed. data = coverage.CoverageData(".coverage") data.read() # If the test fails, it's helpful to see this info: fname = abs_file("try_it.py") linenos = data.lines(fname) print("{}: {}".format(len(linenos), linenos)) print_simple_annotation(code, linenos) lines = line_count(code) self.assertEqual(line_counts(data)['try_it.py'], lines)
Example #21
Source File: test_process.py From coveragepy-bbmirror with Apache License 2.0 | 5 votes |
def test_subprocess_with_pth_files(self): # pragma: no metacov if env.METACOV: self.skipTest("Can't test sub-process pth file suppport during metacoverage") # An existing data file should not be read when a subprocess gets # measured automatically. Create the data file here with bogus data in # it. data = coverage.CoverageData() data.add_lines({os.path.abspath('sub.py'): dict.fromkeys(range(100))}) data.write_file(".mycovdata") self.make_file("coverage.ini", """\ [run] data_file = .mycovdata """) self.set_environ("COVERAGE_PROCESS_START", "coverage.ini") import main # pylint: disable=import-error, unused-variable with open("out.txt") as f: self.assertEqual(f.read(), "Hello, world!\n") # Read the data from .coverage self.assert_exists(".mycovdata") data = coverage.CoverageData() data.read_file(".mycovdata") self.assertEqual(data.line_counts()['sub.py'], 3)
Example #22
Source File: test_main.py From covimerage with MIT License | 5 votes |
def test_merged_profiles_get_coveragepy_data(): from covimerage import MergedProfiles m = MergedProfiles([]) cov_data = m.get_coveragepy_data() try: from coverage.data import CoverageJsonData except ImportError: assert isinstance(cov_data, coverage.CoverageData) else: assert isinstance(cov_data, CoverageJsonData)
Example #23
Source File: reporter.py From acvtool with Apache License 2.0 | 5 votes |
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)
Example #24
Source File: test_process.py From coveragepy-bbmirror with Apache License 2.0 | 5 votes |
def test_combine_parallel_data(self): self.make_b_or_c_py() out = self.run_command("coverage run -p b_or_c.py b") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") self.assertEqual(self.number_of_data_files(), 1) out = self.run_command("coverage run -p b_or_c.py c") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") # After two -p runs, there should be two .coverage.machine.123 files. self.assertEqual(self.number_of_data_files(), 2) # Combine the parallel coverage data files into .coverage . self.run_command("coverage combine") self.assert_exists(".coverage") # After combining, there should be only the .coverage file. self.assertEqual(self.number_of_data_files(), 1) # Read the coverage file and see that b_or_c.py has all 7 lines # executed. data = coverage.CoverageData() data.read_file(".coverage") self.assertEqual(data.line_counts()['b_or_c.py'], 7) # Running combine again should fail, because there are no parallel data # files to combine. status, out = self.run_command_status("coverage combine") self.assertEqual(status, 1) self.assertEqual(out, "No data to combine\n") # And the originally combined data is still there. data = coverage.CoverageData() data.read_file(".coverage") self.assertEqual(data.line_counts()['b_or_c.py'], 7)
Example #25
Source File: test_process.py From coveragepy-bbmirror with Apache License 2.0 | 5 votes |
def test_combine_parallel_data_with_a_corrupt_file(self): self.make_b_or_c_py() out = self.run_command("coverage run -p b_or_c.py b") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") self.assertEqual(self.number_of_data_files(), 1) out = self.run_command("coverage run -p b_or_c.py c") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") # After two -p runs, there should be two .coverage.machine.123 files. self.assertEqual(self.number_of_data_files(), 2) # Make a bogus data file. self.make_file(".coverage.bad", "This isn't a coverage data file.") # Combine the parallel coverage data files into .coverage . out = self.run_command("coverage combine") self.assert_exists(".coverage") self.assert_exists(".coverage.bad") warning_regex = ( r"Coverage.py warning: Couldn't read data from '.*\.coverage\.bad': " r"CoverageException: Doesn't seem to be a coverage\.py data file" ) self.assertRegex(out, warning_regex) # After combining, those two should be the only data files. self.assertEqual(self.number_of_data_files(), 2) # Read the coverage file and see that b_or_c.py has all 7 lines # executed. data = coverage.CoverageData() data.read_file(".coverage") self.assertEqual(data.line_counts()['b_or_c.py'], 7)
Example #26
Source File: test_process.py From coveragepy-bbmirror with Apache License 2.0 | 5 votes |
def test_combine_no_usable_files(self): # https://bitbucket.org/ned/coveragepy/issues/629/multiple-use-of-combine-leads-to-empty self.make_b_or_c_py() out = self.run_command("coverage run b_or_c.py b") self.assertEqual(out, 'done\n') self.assert_exists(".coverage") self.assertEqual(self.number_of_data_files(), 1) # Make bogus data files. self.make_file(".coverage.bad1", "This isn't a coverage data file.") self.make_file(".coverage.bad2", "This isn't a coverage data file.") # Combine the parallel coverage data files into .coverage, but nothing is readable. status, out = self.run_command_status("coverage combine") self.assertEqual(status, 1) for n in "12": self.assert_exists(".coverage.bad{0}".format(n)) warning_regex = ( r"Coverage.py warning: Couldn't read data from '.*\.coverage\.bad{0}': " r"CoverageException: Doesn't seem to be a coverage\.py data file".format(n) ) self.assertRegex(out, warning_regex) self.assertRegex(out, r"No usable data files") # After combining, we should have a main file and two parallel files. self.assertEqual(self.number_of_data_files(), 3) # Read the coverage file and see that b_or_c.py has 6 lines # executed (we only did b, not c). data = coverage.CoverageData() data.read_file(".coverage") self.assertEqual(data.line_counts()['b_or_c.py'], 6)
Example #27
Source File: test_process.py From coveragepy-bbmirror with Apache License 2.0 | 5 votes |
def test_combine_parallel_data_in_two_steps(self): self.make_b_or_c_py() out = self.run_command("coverage run -p b_or_c.py b") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") self.assertEqual(self.number_of_data_files(), 1) # Combine the (one) parallel coverage data file into .coverage . self.run_command("coverage combine") self.assert_exists(".coverage") self.assertEqual(self.number_of_data_files(), 1) out = self.run_command("coverage run -p b_or_c.py c") self.assertEqual(out, 'done\n') self.assert_exists(".coverage") self.assertEqual(self.number_of_data_files(), 2) # Combine the parallel coverage data files into .coverage . self.run_command("coverage combine --append") self.assert_exists(".coverage") # After combining, there should be only the .coverage file. self.assertEqual(self.number_of_data_files(), 1) # Read the coverage file and see that b_or_c.py has all 7 lines # executed. data = coverage.CoverageData() data.read_file(".coverage") self.assertEqual(data.line_counts()['b_or_c.py'], 7)
Example #28
Source File: test_process.py From coveragepy-bbmirror with Apache License 2.0 | 5 votes |
def test_append_data_with_different_file(self): self.make_b_or_c_py() self.make_file(".coveragerc", """\ [run] data_file = .mycovdata """) out = self.run_command("coverage run b_or_c.py b") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") self.assert_exists(".mycovdata") out = self.run_command("coverage run --append b_or_c.py c") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") self.assert_exists(".mycovdata") # Read the coverage file and see that b_or_c.py has all 7 lines # executed. data = coverage.CoverageData() data.read_file(".mycovdata") self.assertEqual(data.line_counts()['b_or_c.py'], 7)
Example #29
Source File: test_process.py From coveragepy-bbmirror with Apache License 2.0 | 5 votes |
def test_append_can_create_a_data_file(self): self.make_b_or_c_py() out = self.run_command("coverage run --append b_or_c.py b") self.assertEqual(out, 'done\n') self.assert_exists(".coverage") self.assertEqual(self.number_of_data_files(), 1) # Read the coverage file and see that b_or_c.py has only 6 lines # executed. data = coverage.CoverageData() data.read_file(".coverage") self.assertEqual(data.line_counts()['b_or_c.py'], 6)
Example #30
Source File: test_process.py From coveragepy-bbmirror with Apache License 2.0 | 5 votes |
def test_combine_with_rc(self): self.make_b_or_c_py() self.make_file(".coveragerc", """\ [run] parallel = true """) out = self.run_command("coverage run b_or_c.py b") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") out = self.run_command("coverage run b_or_c.py c") self.assertEqual(out, 'done\n') self.assert_doesnt_exist(".coverage") # After two runs, there should be two .coverage.machine.123 files. self.assertEqual(self.number_of_data_files(), 2) # Combine the parallel coverage data files into .coverage . self.run_command("coverage combine") self.assert_exists(".coverage") self.assert_exists(".coveragerc") # After combining, there should be only the .coverage file. self.assertEqual(self.number_of_data_files(), 1) # Read the coverage file and see that b_or_c.py has all 7 lines # executed. data = coverage.CoverageData() data.read_file(".coverage") self.assertEqual(data.line_counts()['b_or_c.py'], 7) # Reporting should still work even with the .rc file out = self.run_command("coverage report") self.assertMultiLineEqual(out, textwrap.dedent("""\ Name Stmts Miss Cover ------------------------------- b_or_c.py 7 0 100% """))