本文整理汇总了Python中coverage.files.FileLocator.relative_filename方法的典型用法代码示例。如果您正苦于以下问题:Python FileLocator.relative_filename方法的具体用法?Python FileLocator.relative_filename怎么用?Python FileLocator.relative_filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coverage.files.FileLocator
的用法示例。
在下文中一共展示了FileLocator.relative_filename方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_simple
# 需要导入模块: from coverage.files import FileLocator [as 别名]
# 或者: from coverage.files.FileLocator import relative_filename [as 别名]
def test_simple(self):
self.make_file("hello.py")
fl = FileLocator()
self.assertEqual(fl.relative_filename("hello.py"), "hello.py")
a = self.abs_path("hello.py")
self.assertNotEqual(a, "hello.py")
self.assertEqual(fl.relative_filename(a), "hello.py")
示例2: test_filepath_contains_absolute_prefix_twice
# 需要导入模块: from coverage.files import FileLocator [as 别名]
# 或者: from coverage.files.FileLocator import relative_filename [as 别名]
def test_filepath_contains_absolute_prefix_twice(self):
# https://bitbucket.org/ned/coveragepy/issue/194
# Build a path that has two pieces matching the absolute path prefix.
# Technically, this test doesn't do that on Windows, but drive
# letters make that impractical to achieve.
fl = FileLocator()
d = abs_file(os.curdir)
trick = os.path.splitdrive(d)[1].lstrip(os.path.sep)
rel = os.path.join('sub', trick, 'file1.py')
self.assertEqual(fl.relative_filename(abs_file(rel)), rel)
示例3: test_peer_directories
# 需要导入模块: from coverage.files import FileLocator [as 别名]
# 或者: from coverage.files.FileLocator import relative_filename [as 别名]
def test_peer_directories(self):
self.make_file("sub/proj1/file1.py")
self.make_file("sub/proj2/file2.py")
a1 = self.abs_path("sub/proj1/file1.py")
a2 = self.abs_path("sub/proj2/file2.py")
d = os.path.normpath("sub/proj1")
os.chdir(d)
fl = FileLocator()
self.assertEqual(fl.relative_filename(a1), "file1.py")
self.assertEqual(fl.relative_filename(a2), a2)
示例4: Coverage
# 需要导入模块: from coverage.files import FileLocator [as 别名]
# 或者: from coverage.files.FileLocator import relative_filename [as 别名]
#.........这里部分代码省略.........
Returns an `Analysis` object.
"""
self._harvest_data()
if not isinstance(it, FileReporter):
it = self._get_file_reporter(it)
return Analysis(self, it)
def _get_file_reporter(self, morf):
"""Get a FileReporter for a module or filename."""
plugin = None
if isinstance(morf, string_class):
abs_morf = abs_file(morf)
plugin_name = self.data.plugin_data().get(abs_morf)
if plugin_name:
plugin = self.plugins.get(plugin_name)
if plugin:
file_reporter = plugin.file_reporter(abs_morf)
if file_reporter is None:
raise CoverageException(
"Plugin %r did not provide a file reporter for %r." % (
plugin._coverage_plugin_name, morf
)
)
else:
file_reporter = PythonFileReporter(morf, self)
# The FileReporter can have a name attribute, but if it doesn't, we'll
# supply it as the relative path to self.filename.
if not hasattr(file_reporter, "name"):
file_reporter.name = self.file_locator.relative_filename(
file_reporter.filename
)
return file_reporter
def _get_file_reporters(self, morfs=None):
"""Get a list of FileReporters for a list of modules or filenames.
For each module or filename in `morfs`, find a FileReporter. Return
the list of FileReporters.
If `morfs` is a single module or filename, this returns a list of one
FileReporter. If `morfs` is empty or None, then the list of all files
measured is used to find the FileReporters.
"""
if not morfs:
morfs = self.data.measured_files()
# Be sure we have a list.
if not isinstance(morfs, (list, tuple)):
morfs = [morfs]
file_reporters = []
for morf in morfs:
file_reporter = self._get_file_reporter(morf)
file_reporters.append(file_reporter)
return file_reporters
def report(
self, morfs=None, show_missing=True, ignore_errors=None,