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_zip__file_not_found():
from pycobertura.filesystem import ZipFileSystem
fs = ZipFileSystem("tests/dummy/dummy.zip")
dummy_source_file = 'foo/non-existent-file.py'
try:
with fs.open(dummy_source_file) as f:
pass
except ZipFileSystem.FileNotFound as fnf:
assert fnf.path == dummy_source_file
def test_filesystem_zip__with_source_prefix():
from pycobertura.filesystem import ZipFileSystem
fs = ZipFileSystem(
"tests/dummy/dummy-with-prefix.zip", # code zipped as dummy-with-prefix/dummy/dummy.py
source_prefix="dummy-with-prefix",
)
source_files_in_zip = [
'dummy/dummy.py',
'dummy/dummy2.py',
]
for source_file in source_files_in_zip:
with fs.open(source_file) as f:
assert hasattr(f, 'read')
def test_filesystem_zip__returns_fileobject():
from pycobertura.filesystem import ZipFileSystem
fs = ZipFileSystem("tests/dummy/dummy.zip")
source_files_in_zip = [
'dummy/dummy.py',
'dummy/dummy2.py',
]
for source_file in source_files_in_zip:
with fs.open(source_file) as f:
assert hasattr(f, 'read')
def test_filesystem_zip__file_not_found():
from pycobertura.filesystem import ZipFileSystem
fs = ZipFileSystem("tests/dummy/dummy.zip")
dummy_source_file = 'foo/non-existent-file.py'
try:
with fs.open(dummy_source_file) as f:
pass
except ZipFileSystem.FileNotFound as fnf:
assert fnf.path == dummy_source_file
The optional argument `source_prefix` will be used to lookup source
files if a zip archive is provided and will be prepended to filenames
found in the coverage report.
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)