本文整理汇总了Python中coverage.data.CoverageDataFiles.read方法的典型用法代码示例。如果您正苦于以下问题:Python CoverageDataFiles.read方法的具体用法?Python CoverageDataFiles.read怎么用?Python CoverageDataFiles.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coverage.data.CoverageDataFiles
的用法示例。
在下文中一共展示了CoverageDataFiles.read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Coverage
# 需要导入模块: from coverage.data import CoverageDataFiles [as 别名]
# 或者: from coverage.data.CoverageDataFiles import read [as 别名]
class Coverage(object):
"""Programmatic access to coverage.py.
To use::
from coverage import Coverage
cov = Coverage()
cov.start()
#.. call your code ..
cov.stop()
cov.html_report(directory='covhtml')
"""
def __init__(
self, data_file=None, data_suffix=None, cover_pylib=None,
auto_data=False, timid=None, branch=None, config_file=True,
source=None, omit=None, include=None, debug=None,
concurrency=None,
):
"""
`data_file` is the base name of the data file to use, defaulting to
".coverage". `data_suffix` is appended (with a dot) to `data_file` to
create the final file name. If `data_suffix` is simply True, then a
suffix is created with the machine and process identity included.
`cover_pylib` is a boolean determining whether Python code installed
with the Python interpreter is measured. This includes the Python
standard library and any packages installed with the interpreter.
If `auto_data` is true, then any existing data file will be read when
coverage measurement starts, and data will be saved automatically when
measurement stops.
If `timid` is true, then a slower and simpler trace function will be
used. This is important for some environments where manipulation of
tracing functions breaks the faster trace function.
If `branch` is true, then branch coverage will be measured in addition
to the usual statement coverage.
`config_file` determines what configuration file to read:
* If it is ".coveragerc", it is interpreted as if it were True,
for backward compatibility.
* If it is a string, it is the name of the file to read. If the
file can't be read, it is an error.
* If it is True, then a few standard files names are tried
(".coveragerc", "setup.cfg"). It is not an error for these files
to not be found.
* If it is False, then no configuration file is read.
`source` is a list of file paths or package names. Only code located
in the trees indicated by the file paths or package names will be
measured.
`include` and `omit` are lists of file name patterns. Files that match
`include` will be measured, files that match `omit` will not. Each
will also accept a single string argument.
`debug` is a list of strings indicating what debugging information is
desired.
`concurrency` is a string indicating the concurrency library being used
in the measured code. Without this, coverage.py will get incorrect
results. Valid strings are "greenlet", "eventlet", "gevent",
"multiprocessing", or "thread" (the default).
.. versionadded:: 4.0
The `concurrency` parameter.
"""
# Build our configuration from a number of sources:
# 1: defaults:
self.config = CoverageConfig()
# 2: from the rcfile, .coveragerc or setup.cfg file:
if config_file:
did_read_rc = False
# Some API users were specifying ".coveragerc" to mean the same as
# True, so make it so.
if config_file == ".coveragerc":
config_file = True
specified_file = (config_file is not True)
if not specified_file:
config_file = ".coveragerc"
did_read_rc = self.config.from_file(config_file)
if not did_read_rc:
if specified_file:
raise CoverageException(
"Couldn't read '%s' as a config file" % config_file
)
self.config.from_file("setup.cfg", section_prefix="coverage:")
# 3: from environment variables:
#.........这里部分代码省略.........
示例2: CoverageDataFilesTest
# 需要导入模块: from coverage.data import CoverageDataFiles [as 别名]
# 或者: from coverage.data.CoverageDataFiles import read [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")
#.........这里部分代码省略.........