How to use the covimerage.coveragepy.CoverageData function in covimerage

To help you get started, we’ve selected a few covimerage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Vimjas / covimerage / tests / test_coveragepy.py View on Github external
assert excinfo.value.args == (
        'Coverage could not read data_file: /does/not/exist',)
    assert isinstance(excinfo.value.orig_exc, coverage.misc.CoverageException)

    f = StringIO()
    with pytest.raises(CoverageWrapperException) as excinfo:
        CoverageData(data_file=f)
    e = excinfo.value
    assert isinstance(e.orig_exc, coverage.misc.CoverageException)
    assert e.message == 'Coverage could not read data_file: %s' % f
    assert e.format_message() == "%s (CoverageException: Doesn't seem to be a coverage.py data file)" % (e.message,)
    assert str(e) == e.format_message()
    assert repr(e) == 'CoverageWrapperException(message=%r, orig_exc=%r)' % (
        e.message, e.orig_exc)

    cov_data = CoverageData(data_file=coverage_fileobj)
    with pytest.raises(attr.exceptions.FrozenInstanceError):
        cov_data.data = 'foo'

    assert cov_data.lines == {
        '/test_plugin/conditional_function.vim': [
            3, 8, 9, 11, 13, 14, 15, 17, 23]}
github Vimjas / covimerage / tests / test_coveragepy.py View on Github external
def test_coveragedata_empty(covdata_empty):
    from covimerage.coveragepy import CoverageData

    f = StringIO()
    data = CoverageData()
    try:
        write_fileobj = data.cov_data.write_fileobj
    except AttributeError:
        # coveragepy 5
        write_fileobj = data.cov_data._write_fileobj
    write_fileobj(f)
    f.seek(0)
    assert f.read() == covdata_empty
github Vimjas / covimerage / tests / test_coveragepy.py View on Github external
def test_coveragewrapper_accepts_data():
    from covimerage.coveragepy import CoverageData, CoverageWrapper

    data = CoverageData()
    cov = CoverageWrapper(data=data)
    assert cov.data is data
github Vimjas / covimerage / tests / test_coveragepy.py View on Github external
def test_coveragedata(coverage_fileobj):
    import coverage
    from covimerage.coveragepy import (
        CoverageData, CoveragePyData, CoverageWrapperException)

    with pytest.raises(TypeError) as excinfo:
        CoverageData(data_file='foo', cov_data=CoveragePyData())
    assert excinfo.value.args == (
        'data and data_file are mutually exclusive.',)

    data = CoverageData()
    try:
        from coverage.data import CoverageJsonData
    except ImportError:
        assert isinstance(data.cov_data, coverage.data.CoverageData)
    else:
        assert isinstance(data.cov_data, CoverageJsonData)

    with pytest.raises(TypeError) as excinfo:
        CoverageData(cov_data='foo')
    try:
        from coverage.data import CoverageJsonData
    except ImportError:
        assert excinfo.value.args == (
            'data needs to be of type coverage.data.CoverageData',)
    else:
        assert excinfo.value.args == (
github Vimjas / covimerage / tests / test_coveragepy.py View on Github external
def test_coveragedata(coverage_fileobj):
    import coverage
    from covimerage.coveragepy import (
        CoverageData, CoveragePyData, CoverageWrapperException)

    with pytest.raises(TypeError) as excinfo:
        CoverageData(data_file='foo', cov_data=CoveragePyData())
    assert excinfo.value.args == (
        'data and data_file are mutually exclusive.',)

    data = CoverageData()
    try:
        from coverage.data import CoverageJsonData
    except ImportError:
        assert isinstance(data.cov_data, coverage.data.CoverageData)
    else:
        assert isinstance(data.cov_data, CoverageJsonData)

    with pytest.raises(TypeError) as excinfo:
        CoverageData(cov_data='foo')
    try:
        from coverage.data import CoverageJsonData
    except ImportError:
github Vimjas / covimerage / covimerage / __init__.py View on Github external
def _get_coveragepy_data(self):
        if self.append_to and os.path.exists(self.append_to):
            data = CoverageData(data_file=self.append_to)
        else:
            data = CoverageData()

        cov_dict = {}
        cov_file_tracers = {}

        source_files = []
        for source in self.source:
            source = os.path.abspath(source)
            if os.path.isfile(source):
                source_files.append(source)
            else:
                source_files.extend(find_executable_files(source))
        logger.debug('source_files: %r', source_files)

        for fname, lines in self.lines.items():
github Vimjas / covimerage / covimerage / __init__.py View on Github external
def _get_coveragepy_data(self):
        if self.append_to and os.path.exists(self.append_to):
            data = CoverageData(data_file=self.append_to)
        else:
            data = CoverageData()

        cov_dict = {}
        cov_file_tracers = {}

        source_files = []
        for source in self.source:
            source = os.path.abspath(source)
            if os.path.isfile(source):
                source_files.append(source)
            else:
                source_files.extend(find_executable_files(source))
        logger.debug('source_files: %r', source_files)

        for fname, lines in self.lines.items():
            fname = os.path.abspath(fname)
            if self.source and fname not in source_files:
github Vimjas / covimerage / covimerage / coveragepy.py View on Github external
def __attrs_post_init__(self):
        if not isinstance(self.data, CoverageData):
            data = CoverageData(cov_data=self.data, data_file=self.data_file)
            object.__setattr__(self, 'data', data)
            # (confusing to have it twice)
            # object.__setattr__(self, 'data_file', None)
        elif self.data_file:
            raise TypeError('data and data_file are mutually exclusive.')