本文整理汇总了Python中coverage.data.CoverageDataFiles.write方法的典型用法代码示例。如果您正苦于以下问题:Python CoverageDataFiles.write方法的具体用法?Python CoverageDataFiles.write怎么用?Python CoverageDataFiles.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coverage.data.CoverageDataFiles
的用法示例。
在下文中一共展示了CoverageDataFiles.write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_writing_to_other_file
# 需要导入模块: from coverage.data import CoverageDataFiles [as 别名]
# 或者: from coverage.data.CoverageDataFiles import write [as 别名]
def test_writing_to_other_file(self):
data_files = CoverageDataFiles(".otherfile")
covdata = CoverageData()
covdata.set_lines(LINES_1)
data_files.write(covdata)
self.assert_doesnt_exist(".coverage")
self.assert_exists(".otherfile")
data_files.write(covdata, suffix="extra")
self.assert_exists(".otherfile.extra")
self.assert_doesnt_exist(".coverage")
示例2: test_debug_data
# 需要导入模块: from coverage.data import CoverageDataFiles [as 别名]
# 或者: from coverage.data.CoverageDataFiles import write [as 别名]
def test_debug_data(self):
data = CoverageData()
data.add_lines({
"file1.py": dict.fromkeys(range(1, 18)),
"file2.py": dict.fromkeys(range(1, 24)),
})
data.add_file_tracers({"file1.py": "a_plugin"})
data_files = CoverageDataFiles()
data_files.write(data)
self.command_line("debug data")
self.assertMultiLineEqual(self.stdout(), textwrap.dedent("""\
-- data ------------------------------------------------------
path: FILENAME
has_arcs: False
2 files:
file1.py: 17 lines [a_plugin]
file2.py: 23 lines
""").replace("FILENAME", data_files.filename))
示例3: Coverage
# 需要导入模块: from coverage.data import CoverageDataFiles [as 别名]
# 或者: from coverage.data.CoverageDataFiles import write [as 别名]
#.........这里部分代码省略.........
if env.TESTING:
# When testing, we use PyContracts, which should be considered
# part of coverage.py, and it uses six. Exclude those directories
# just as we exclude ourselves.
import contracts, six
for mod in [contracts, six]:
self.cover_dirs.append(self._canonical_dir(mod))
# Set the reporting precision.
Numbers.set_precision(self.config.precision)
atexit.register(self._atexit)
self._inited = True
# Create the matchers we need for _should_trace
if self.source or self.source_pkgs:
self.source_match = TreeMatcher(self.source)
self.source_pkgs_match = ModuleMatcher(self.source_pkgs)
else:
if self.cover_dirs:
self.cover_match = TreeMatcher(self.cover_dirs)
if self.pylib_dirs:
self.pylib_match = TreeMatcher(self.pylib_dirs)
if self.include:
self.include_match = FnmatchMatcher(self.include)
if self.omit:
self.omit_match = FnmatchMatcher(self.omit)
# The user may want to debug things, show info if desired.
wrote_any = False
if self.debug.should('config'):
config_info = sorted(self.config.__dict__.items())
self.debug.write_formatted_info("config", config_info)
wrote_any = True
if self.debug.should('sys'):
self.debug.write_formatted_info("sys", self.sys_info())
for plugin in self.plugins:
header = "sys: " + plugin._coverage_plugin_name
info = plugin.sys_info()
self.debug.write_formatted_info(header, info)
wrote_any = True
if wrote_any:
self.debug.write_formatted_info("end", ())
def _canonical_dir(self, morf):
"""Return the canonical directory of the module or file `morf`."""
morf_filename = PythonFileReporter(morf, self).filename
return os.path.split(morf_filename)[0]
def _source_for_file(self, filename):
"""Return the source file for `filename`.
Given a file name being traced, return the best guess as to the source
file to attribute it to.
"""
if filename.endswith(".py"):
# .py files are themselves source files.
return filename
elif filename.endswith((".pyc", ".pyo")):
# Bytecode files probably have source files near them.
py_filename = filename[:-1]
示例4: CoverageDataFilesTest
# 需要导入模块: from coverage.data import CoverageDataFiles [as 别名]
# 或者: from coverage.data.CoverageDataFiles import write [as 别名]
class CoverageDataFilesTest(DataTestHelpers, CoverageTest):
"""Tests of CoverageDataFiles."""
no_files_in_temp_dir = True
def setUp(self):
super(CoverageDataFilesTest, self).setUp()
self.data_files = CoverageDataFiles()
def test_reading_missing(self):
self.assert_doesnt_exist(".coverage")
covdata = CoverageData()
self.data_files.read(covdata)
self.assert_line_counts(covdata, {})
def test_writing_and_reading(self):
covdata1 = CoverageData()
covdata1.set_lines(LINES_1)
self.data_files.write(covdata1)
covdata2 = CoverageData()
self.data_files.read(covdata2)
self.assert_line_counts(covdata2, SUMMARY_1)
def test_debug_output_with_debug_option(self):
# With debug option dataio, we get debug output about reading and
# writing files.
debug = DebugControlString(options=["dataio"])
covdata1 = CoverageData(debug=debug)
covdata1.set_lines(LINES_1)
self.data_files.write(covdata1)
covdata2 = CoverageData(debug=debug)
self.data_files.read(covdata2)
self.assert_line_counts(covdata2, SUMMARY_1)
self.assertRegex(
debug.get_output(),
r"^Writing data to '.*\.coverage'\n"
r"Reading data from '.*\.coverage'\n$"
)
def test_debug_output_without_debug_option(self):
# With a debug object, but not the dataio option, we don't get debug
# output.
debug = DebugControlString(options=[])
covdata1 = CoverageData(debug=debug)
covdata1.set_lines(LINES_1)
self.data_files.write(covdata1)
covdata2 = CoverageData(debug=debug)
self.data_files.read(covdata2)
self.assert_line_counts(covdata2, SUMMARY_1)
self.assertEqual(debug.get_output(), "")
def test_explicit_suffix(self):
self.assert_doesnt_exist(".coverage.SUFFIX")
covdata = CoverageData()
covdata.set_lines(LINES_1)
self.data_files.write(covdata, suffix='SUFFIX')
self.assert_exists(".coverage.SUFFIX")
self.assert_doesnt_exist(".coverage")
def test_true_suffix(self):
self.assertEqual(glob.glob(".coverage.*"), [])
# suffix=True will make a randomly named data file.
covdata1 = CoverageData()
covdata1.set_lines(LINES_1)
self.data_files.write(covdata1, suffix=True)
self.assert_doesnt_exist(".coverage")
data_files1 = glob.glob(".coverage.*")
self.assertEqual(len(data_files1), 1)
# Another suffix=True will choose a different name.
covdata2 = CoverageData()
covdata2.set_lines(LINES_1)
self.data_files.write(covdata2, suffix=True)
self.assert_doesnt_exist(".coverage")
data_files2 = glob.glob(".coverage.*")
self.assertEqual(len(data_files2), 2)
# In addition to being different, the suffixes have the pid in them.
self.assertTrue(all(str(os.getpid()) in fn for fn in data_files2))
def test_combining(self):
self.assert_doesnt_exist(".coverage.1")
self.assert_doesnt_exist(".coverage.2")
covdata1 = CoverageData()
covdata1.set_lines(LINES_1)
self.data_files.write(covdata1, suffix='1')
self.assert_exists(".coverage.1")
self.assert_doesnt_exist(".coverage.2")
covdata2 = CoverageData()
covdata2.set_lines(LINES_2)
self.data_files.write(covdata2, suffix='2')
self.assert_exists(".coverage.2")
#.........这里部分代码省略.........