Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_filesystem_directory__file_not_found():
from pycobertura.filesystem import DirectoryFileSystem
fs = DirectoryFileSystem('foo/bar/baz')
expected_filepaths = {
'Main.java': 'foo/bar/baz/Main.java',
'search/BinarySearch.java': 'foo/bar/baz/search/BinarySearch.java',
'search/ISortedArraySearch.java': 'foo/bar/baz/search/ISortedArraySearch.java',
'search/LinearSearch.java': 'foo/bar/baz/search/LinearSearch.java',
}
for filename in expected_filepaths:
try:
with fs.open(filename) as f:
pass
except DirectoryFileSystem.FileNotFound as fnf:
assert fnf.path == expected_filepaths[filename]
def test_filesystem_directory__with_source_prefix():
from pycobertura.filesystem import DirectoryFileSystem
fs = DirectoryFileSystem(
'tests/',
source_prefix='dummy' # should resolve to tests/dummy/
)
expected_filepaths = {
'dummy/dummy.py': 'dummy/dummy/dummy.py',
}
for filename in expected_filepaths:
with fs.open(filename) as f:
assert hasattr(f, 'read')
def test_filesystem_directory__returns_fileobject():
from pycobertura.filesystem import DirectoryFileSystem
fs = DirectoryFileSystem('tests/dummy')
expected_filepaths = {
'dummy/dummy.py': 'dummy/dummy/dummy.py',
}
for filename in expected_filepaths:
with fs.open(filename) as f:
assert hasattr(f, 'read')
from pycobertura.filesystem import DirectoryFileSystem
fs = DirectoryFileSystem('foo/bar/baz')
expected_filepaths = {
'Main.java': 'foo/bar/baz/Main.java',
'search/BinarySearch.java': 'foo/bar/baz/search/BinarySearch.java',
'search/ISortedArraySearch.java': 'foo/bar/baz/search/ISortedArraySearch.java',
'search/LinearSearch.java': 'foo/bar/baz/search/LinearSearch.java',
}
for filename in expected_filepaths:
try:
with fs.open(filename) as f:
pass
except DirectoryFileSystem.FileNotFound as fnf:
assert fnf.path == expected_filepaths[filename]
The optional argument `ref` will be taken into account when
instantiating a GitFileSystem, and it shall be a branch name, a commit
ID or a git ref ID.
"""
if source is None:
if isinstance(report, str):
# get the directory in which the coverage file lives
source = os.path.dirname(report)
if zipfile.is_zipfile(source):
return ZipFileSystem(source, source_prefix=source_prefix)
if ref:
return GitFileSystem(source, ref)
return DirectoryFileSystem(source, source_prefix=source_prefix)