Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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')
Exemplo n.º 4
0
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')
Exemplo n.º 5
0
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')
Exemplo n.º 6
0
    def __init__(self, report, source=None, source_prefix=None):
        """
        Initialize a Cobertura report given a coverage report `report`. It can
        be either a file object or the path to an XML file that is in the
        Cobertura format.

        The optional argument `source` is the location of the source code
        provided as a directory path or a file object zip archive containing
        the source code.

        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.
        """
        self.xml = ET.parse(report).getroot()

        if source is None:
            if isinstance(report, basestring):
                # get the directory in which the coverage file lives
                source = os.path.dirname(report)
            self.filesystem = DirectoryFileSystem(
                source, source_prefix=source_prefix
            )
        elif zipfile.is_zipfile(source):
            self.filesystem = ZipFileSystem(
                source, source_prefix=source_prefix
            )
        else:
            self.filesystem = DirectoryFileSystem(
                source, source_prefix=source_prefix
            )
Exemplo n.º 7
0
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')