def test_output_formatter_get_table_formatter(table_type, mocker, monkeypatch): """The returned table formatter uses the correct table type.""" mock_table_format = mocker.Mock() monkeypatch.setattr(utils.tabulate, "TableFormat", mock_table_format) mock_functools_partial = mocker.Mock() # functools.partial does not have an __eq__ method so any comparison # between two partial functions will use id() and not actual equality. # To work around this, we mock functools.partial. But it isn't as # easy as it is with other monkeypatching: # https://github.com/pytest-dev/pytest/pull/3382 # However, this fails on py3.8 with monkeypatch.context() as m: m.setattr(utils.functools, "partial", mock_functools_partial) conf = config.InterrogateConfig() formatter = utils.OutputFormatter(conf) formatter.get_table_formatter(table_type=table_type) mock_table_format.assert_called_once_with( lineabove=None, linebelowheader=None, linebetweenrows=None, linebelow=None, headerrow=mock_functools_partial.return_value, datarow=mock_functools_partial.return_value, padding=1, with_header_hide=None, ) mock_functools_partial.assert_called_once_with( formatter._interrogate_line_formatter, table_type=table_type)
def __init__(self, paths, conf=None, excluded=None): self.paths = paths self.config = conf or config.InterrogateConfig() self.excluded = excluded or () self.common_base = pathlib.Path("/") self.output_formatter = None self._add_common_exclude()
def test_print_results_ignore_module( ignore_module, level, exp_fixture_file, capsys, monkeypatch ): """Do not print module info if ignore_module is True.""" monkeypatch.setattr(coverage.utils.OutputFormatter, "TERMINAL_WIDTH", 80) conf = {"ignore_module": ignore_module} conf = config.InterrogateConfig(**conf) interrogate_coverage = coverage.InterrogateCoverage( paths=[SAMPLE_DIR], conf=conf ) results = interrogate_coverage.get_coverage() interrogate_coverage.print_results( results=results, output=None, verbosity=level ) captured = capsys.readouterr() expected_fixture = os.path.join(FIXTURES, exp_fixture_file) if IS_WINDOWS: expected_fixture = os.path.join(FIXTURES, "windows", exp_fixture_file) with open(expected_fixture, "r") as f: expected_out = f.read() assert expected_out in captured.out
def main(ctx, paths, **kwargs): """Measure and report on documentation coverage in Python modules. \f # below the "\f" is ignored when running ``interrogate --help`` .. versionchanged:: 1.1.3 ``--ignore-regex`` may now accept multiple values. .. versionadded:: 1.1.3 ``--whitelist-regex`` .. versionadded:: 1.2.0 ``--ignore-nested-functions`` .. versionadded:: 1.2.0 ``--color``/``--no-color`` .. versionadded:: 1.3.0 ``--ignore-property-decorators`` .. versionadded:: 1.3.0 config parsing support for setup.cfg """ if not paths: paths = (os.path.abspath(os.getcwd()), ) # NOTE: this will need to be fixed if we want to start supporting # --whitelist-regex on filenames. This otherwise assumes you # want to ignore module-level docs when only white listing # items (visit.py will also need to be addressed since white/ # black listing only looks at classes & funcs, not modules). if kwargs["whitelist_regex"]: kwargs["ignore_module"] = True conf = config.InterrogateConfig( ignore_init_method=kwargs["ignore_init_method"], ignore_init_module=kwargs["ignore_init_module"], ignore_magic=kwargs["ignore_magic"], ignore_module=kwargs["ignore_module"], ignore_nested_functions=kwargs["ignore_nested_functions"], ignore_property_decorators=kwargs["ignore_property_decorators"], ignore_private=kwargs["ignore_private"], ignore_regex=kwargs["ignore_regex"], ignore_semiprivate=kwargs["ignore_semiprivate"], fail_under=kwargs["fail_under"], include_regex=kwargs["whitelist_regex"], color=kwargs["color"], ) interrogate_coverage = coverage.InterrogateCoverage( paths=paths, conf=conf, excluded=kwargs["exclude"], ) results = interrogate_coverage.get_coverage() is_quiet = kwargs["quiet"] if not is_quiet: colorama.init() # needed for Windows interrogate_coverage.print_results(results, kwargs["output"], kwargs["verbose"]) if kwargs["generate_badge"] is not None: output_path = badge_gen.create(kwargs["generate_badge"], results) if not is_quiet: click.echo("Generated badge to {}".format(output_path)) sys.exit(results.ret_code)
def test_output_formatter_set_summary_markup(has_markup, padded_cells, expected_cells, monkeypatch): """Summary info is marked up with expected esc codes.""" conf = config.InterrogateConfig() formatter = utils.OutputFormatter(conf) monkeypatch.setattr(formatter, "should_markup", lambda: has_markup) actual_cells = formatter.set_summary_markup(padded_cells) assert expected_cells == actual_cells
def test_coverage_simple(paths, conf, exp_results, mocker): """Happy path - get expected results given a file or directory""" conf = config.InterrogateConfig(**conf) interrogate_coverage = coverage.InterrogateCoverage(paths=paths, conf=conf) results = interrogate_coverage.get_coverage() assert exp_results[0] == results.total assert exp_results[1] == results.covered assert exp_results[2] == results.missing assert exp_results[3] == "{:.1f}".format(results.perc_covered)
def test_output_formatter_get_table_formatter_py38(table_type, mocker, monkeypatch): """The returned table formatter uses the correct table type.""" mock_table_format = mocker.Mock() monkeypatch.setattr(utils.tabulate, "TableFormat", mock_table_format) conf = config.InterrogateConfig() formatter = utils.OutputFormatter(conf) formatter.get_table_formatter(table_type=table_type) mock_table_format.assert_called_once()
def test_output_formatter_should_markup(color_conf, envvar, hasmarkup, expected, monkeypatch): """Expect markup unless configured (envvar or config) otherwise.""" conf = config.InterrogateConfig(color=color_conf) formatter = utils.OutputFormatter(conf) if hasmarkup: monkeypatch.setattr(formatter.tw, "hasmarkup", hasmarkup) if envvar: monkeypatch.setenv("INTERROGATE_COLOR", envvar) assert expected == formatter.should_markup()
def test_output_formatter_interrogate_line_formatter_windows( table_type, padded_cells, colwidths, colaligns, width, expected, monkeypatch, ): """Data is padded and aligned correctly to fit the terminal width.""" conf = config.InterrogateConfig(color=False) formatter = utils.OutputFormatter(conf) monkeypatch.setattr(formatter, "TERMINAL_WIDTH", width) actual = formatter._interrogate_line_formatter(padded_cells, colwidths, colaligns, table_type=table_type) assert width - 1 == len(actual) assert expected == actual
def __init__(self, paths, conf=None, excluded=None): self.paths = paths self.config = conf or config.InterrogateConfig() self.excluded = excluded or () self.common_base = "" self._add_common_exclude()
def test_output_formatter_get_table_formatter_raises(): """Raise if received an table type other than 'detailed' or 'summary'.""" conf = config.InterrogateConfig() formatter = utils.OutputFormatter(conf) with pytest.raises(AssertionError): formatter.get_table_formatter(table_type="not_a_type")