def test_get_config( mocker, tmp_path, tool, cli_config, defaults, file_content, expected ): if file_content: toml_file = tmp_path / "foo.toml" toml_file.write_text(file_content) cli_config["config_file"] = expected["config_file"] = str(toml_file) else: cli_config["config_file"] = expected["config_file"] = None parser = mocker.Mock() parser.parse_args().__dict__ = cli_config assert get_config(parser, argv=[], defaults=defaults, tool=tool) == expected
def parse_coverage_args(argv): """ Parse command line arguments, returning a dict of valid options: { 'coverage_xml': COVERAGE_XML, 'html_report': None | HTML_REPORT, 'json_report': None | JSON_REPORT, 'external_css_file': None | CSS_FILE, } where `COVERAGE_XML`, `HTML_REPORT`, `JSON_REPORT`, and `CSS_FILE` are paths. The path strings may or may not exist. """ parser = argparse.ArgumentParser(description=DESCRIPTION) parser.add_argument("coverage_xml", type=str, help=COVERAGE_XML_HELP, nargs="+") parser.add_argument( "--html-report", metavar="FILENAME", type=str, help=HTML_REPORT_HELP, ) parser.add_argument( "--json-report", metavar="FILENAME", type=str, help=JSON_REPORT_HELP, ) parser.add_argument( "--markdown-report", metavar="FILENAME", type=str, help=MARKDOWN_REPORT_HELP, ) parser.add_argument("--show-uncovered", action="store_true", default=None, help=SHOW_UNCOVERED) parser.add_argument( "--external-css-file", metavar="FILENAME", type=str, help=CSS_FILE_HELP, ) parser.add_argument( "--compare-branch", metavar="BRANCH", type=str, help=COMPARE_BRANCH_HELP, ) parser.add_argument("--fail-under", metavar="SCORE", type=float, default=None, help=FAIL_UNDER_HELP) parser.add_argument("--ignore-staged", action="store_true", default=None, help=IGNORE_STAGED_HELP) parser.add_argument( "--ignore-unstaged", action="store_true", default=None, help=IGNORE_UNSTAGED_HELP, ) parser.add_argument( "--include-untracked", action="store_true", default=None, help=INCLUDE_UNTRACKED_HELP, ) parser.add_argument("--exclude", metavar="EXCLUDE", type=str, nargs="+", help=EXCLUDE_HELP) parser.add_argument( "--src-roots", metavar="DIRECTORY", type=str, nargs="+", help=SRC_ROOTS_HELP, ) parser.add_argument( "--diff-range-notation", metavar="RANGE_NOTATION", type=str, choices=["...", ".."], help=DIFF_RANGE_NOTATION_HELP, ) parser.add_argument("--version", action="version", version=f"diff-cover {VERSION}") parser.add_argument( "--ignore-whitespace", action="store_true", default=None, help=IGNORE_WHITESPACE, ) parser.add_argument("-q", "--quiet", action="store_true", default=None, help=QUIET_HELP) parser.add_argument("-c", "--config-file", help=CONFIG_FILE_HELP, metavar="CONFIG_FILE") defaults = { "show_uncovered": False, "compare_branch": "origin/main", "fail_under": 0, "ignore_staged": False, "ignore_unstaged": False, "ignore_untracked": False, "src_roots": ["src/main/java", "src/test/java"], "ignore_whitespace": False, "diff_range_notation": "...", "quiet": False, } return get_config(parser=parser, argv=argv, defaults=defaults, tool=Tool.DIFF_COVER)
def test_get_config_unrecognized_file(mocker, tool): parser = mocker.Mock() parser.parse_args().__dict__ = {"config_file": "foo.bar"} with pytest.raises(ParserError): get_config(parser, argv=[], defaults={}, tool=tool)
def parse_quality_args(argv): """ Parse command line arguments, returning a dict of valid options: { 'violations': pycodestyle| pyflakes | flake8 | pylint | ..., 'html_report': None | HTML_REPORT, 'external_css_file': None | CSS_FILE, } where `HTML_REPORT` and `CSS_FILE` are paths. """ parser = argparse.ArgumentParser( description=diff_cover.QUALITY_DESCRIPTION) parser.add_argument("--violations", metavar="TOOL", type=str, help=VIOLATION_CMD_HELP, required=True) parser.add_argument( "--html-report", metavar="FILENAME", type=str, help=HTML_REPORT_HELP, ) parser.add_argument( "--json-report", metavar="FILENAME", type=str, help=JSON_REPORT_HELP, ) parser.add_argument( "--markdown-report", metavar="FILENAME", type=str, help=MARKDOWN_REPORT_HELP, ) parser.add_argument( "--external-css-file", metavar="FILENAME", type=str, help=CSS_FILE_HELP, ) parser.add_argument( "--compare-branch", metavar="BRANCH", type=str, help=COMPARE_BRANCH_HELP, ) parser.add_argument("input_reports", type=str, nargs="*", help=INPUT_REPORTS_HELP) parser.add_argument("--options", type=str, nargs="?", help=OPTIONS_HELP) parser.add_argument("--fail-under", metavar="SCORE", type=float, help=FAIL_UNDER_HELP) parser.add_argument("--ignore-staged", action="store_true", default=None, help=IGNORE_STAGED_HELP) parser.add_argument( "--ignore-unstaged", action="store_true", default=None, help=IGNORE_UNSTAGED_HELP, ) parser.add_argument( "--include-untracked", action="store_true", default=None, help=INCLUDE_UNTRACKED_HELP, ) parser.add_argument("--exclude", metavar="EXCLUDE", type=str, nargs="+", help=EXCLUDE_HELP) parser.add_argument("--include", metavar="INCLUDE", nargs="+", type=str, help=INCLUDE_HELP) parser.add_argument( "--diff-range-notation", metavar="RANGE_NOTATION", type=str, help=DIFF_RANGE_NOTATION_HELP, ) parser.add_argument( "--version", action="version", version=f"diff-quality {diff_cover.VERSION}", ) parser.add_argument( "--ignore-whitespace", action="store_true", default=None, help=IGNORE_WHITESPACE, ) parser.add_argument("-q", "--quiet", action="store_true", default=None, help=QUIET_HELP) parser.add_argument("-c", "--config-file", help=CONFIG_FILE_HELP, metavar="CONFIG_FILE") parser.add_argument("--report-root-path", help=REPORT_ROOT_PATH_HELP, metavar="ROOT_PATH") defaults = { "ignore_whitespace": False, "compare_branch": "origin/main", "diff_range_notation": "...", "input_reports": [], "fail_under": 0, "ignore_staged": False, "ignore_unstaged": False, "ignore_untracked": False, "quiet": False, } return get_config(parser=parser, argv=argv, defaults=defaults, tool=Tool.DIFF_QUALITY)