How to use the covimerage.logger.logger 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_logging.py View on Github external
def test_loglevel_default(default, mocker, runner):
    from covimerage import cli
    from covimerage.logger import logger

    if default:
        mocker.patch.object(logger, 'level', getattr(logging, default))
    else:
        default = 'INFO'
    reload(cli)

    result = runner.invoke(cli.main, ['-h'])

    assert logging.getLevelName(logger.level) == default
    lines = result.output.splitlines()
    assert lines, result
    idx = lines.index('  -l, --loglevel [error|warning|info|debug]')
    indent = ' ' * 34
    assert lines[idx+1:idx+3] == [
        indent + 'Set logging level explicitly (overrides',
        indent + u'-v/-q).  [default:\xa0%s]' % (default.lower(),),
    ]
    assert result.exit_code == 0
github Vimjas / covimerage / covimerage / __init__.py View on Github external
def map_function(self, f):
        if f.source:
            script, script_lnum = f.source
        else:
            script_line = self.find_func_in_source(f)
            if not script_line:
                return False
            script, script_lnum = script_line

        # Assign counts from function to script.
        for [f_lnum, f_line] in f.lines.items():
            s_lnum = script_lnum + f_lnum
            try:
                s_line = script.lines[s_lnum]
            except KeyError:
                logger.warning(
                    "Could not find script line for function %s (%d, %d)",
                    f.name, script_lnum, f_lnum,
                )
                return False

            # XXX: might not be the same, since function lines
            # are joined, while script lines might be spread
            # across several lines (prefixed with \).
            script_source = s_line.line
            if script_source != f_line.line:
                while True:
                    try:
                        peek = script.lines[script_lnum + f_lnum + 1]
                    except KeyError:
                        pass
                    else:
github Vimjas / covimerage / covimerage / coveragepy.py View on Github external
def source(self):
        try:
            with open(self.filename, 'rb') as f:
                source = f.read()
                try:
                    return source.decode('utf8')
                except UnicodeDecodeError:
                    logger.debug('UnicodeDecodeError in %s for utf8. '
                                 'Trying iso-8859-15.', self.filename)
                    return source.decode('iso-8859-15')
        except FileNotFoundError as exc:
            logger.warning('%s', exc)
            raise coverage.misc.NoSource(str(exc))
        except Exception as exc:
            raise CoverageWrapperException(
                'Could not read source for %s.' % self.filename, orig_exc=exc)
github Vimjas / covimerage / covimerage / __init__.py View on Github external
script_line = s.lines[script_lnum].line

                if script_is_func:
                    found.append((s, lnum))

        if found:
            if len(found) > 1:
                logger.warning(
                    'Found multiple sources for anonymous function %s (%s).',
                    func.name, (', '.join('%s:%d' % (f[0].path, f[1])
                                          for f in found)))

            for s, lnum in found:
                if lnum in s.mapped_dict_functions:
                    # More likely to happen with merged profiles.
                    logger.debug(
                        'Found already mapped dict function again (%s:%d).',
                        s.path, lnum)
                    continue
                s.mapped_dict_functions.add(lnum)
                return (s, lnum)
            return found[0]
github Vimjas / covimerage / covimerage / __init__.py View on Github external
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:
                logger.info('Ignoring non-source: %s', fname)
                continue

            cov_dict[fname] = {
                # lnum: line.count for lnum, line in lines.items()
                # XXX: coveragepy does not support hit counts?!
                lnum: None for lnum, line in lines.items() if line.count
            }
            # Add our plugin as file tracer, so that it gets used with e.g.
            # `coverage annotate`.
            cov_file_tracers[fname] = 'covimerage.CoveragePlugin'
        measured_files = cov_dict.keys()
github Vimjas / covimerage / covimerage / coveragepy.py View on Github external
def source(self):
        try:
            with open(self.filename, 'rb') as f:
                source = f.read()
                try:
                    return source.decode('utf8')
                except UnicodeDecodeError:
                    logger.debug('UnicodeDecodeError in %s for utf8. '
                                 'Trying iso-8859-15.', self.filename)
                    return source.decode('iso-8859-15')
        except FileNotFoundError as exc:
            logger.warning('%s', exc)
            raise coverage.misc.NoSource(str(exc))
        except Exception as exc:
            raise CoverageWrapperException(
                'Could not read source for %s.' % self.filename, orig_exc=exc)
github Vimjas / covimerage / covimerage / cli.py View on Github external
def default_loglevel():
    return logging.getLevelName(logger.level).lower()
github Vimjas / covimerage / covimerage / __init__.py View on Github external
if self.source and fname not in source_files:
                logger.info('Ignoring non-source: %s', fname)
                continue

            cov_dict[fname] = {
                # lnum: line.count for lnum, line in lines.items()
                # XXX: coveragepy does not support hit counts?!
                lnum: None for lnum, line in lines.items() if line.count
            }
            # Add our plugin as file tracer, so that it gets used with e.g.
            # `coverage annotate`.
            cov_file_tracers[fname] = 'covimerage.CoveragePlugin'
        measured_files = cov_dict.keys()
        non_measured_files = set(source_files) - set(measured_files)
        for fname in non_measured_files:
            logger.debug('Non-measured file: %s', fname)
            cov_dict[fname] = {}
            cov_file_tracers[fname] = 'covimerage.CoveragePlugin'

        data.add_lines(cov_dict)
        data.cov_data.add_file_tracers(cov_file_tracers)
        return data.cov_data