def _primer_test(package: PackageToLint,
                     caplog: LogCaptureFixture) -> None:
        """Runs pylint over external packages to check for crashes and fatal messages.

        We only check for crashes (bit-encoded exit code 32) and fatal messages
        (bit-encoded exit code 1). We assume that these external repositories do not
        have any fatal errors in their code so that any fatal errors are pylint false
        positives
        """
        caplog.set_level(logging.INFO)
        package.lazy_clone()

        try:
            # We want to test all the code we can
            enables = ["--enable-all-extensions", "--enable=all"]
            # Duplicate code takes too long and is relatively safe
            disables = ["--disable=duplicate-code"]
            command = ["pylint"] + enables + disables + package.pylint_args
            logging.info("Launching primer:\n%s", " ".join(command))
            subprocess.run(command, check=True)
        except subprocess.CalledProcessError as ex:
            msg = f"Encountered {{}} during primer test for {package}"
            assert ex.returncode != 32, msg.format("a crash")
            assert ex.returncode % 2 == 0, msg.format(
                "a message of category 'fatal'")
def test_package_to_lint() -> None:
    """Test that the PackageToLint is instantiated correctly."""
    expected_dir_path = PRIMER_DIRECTORY_PATH / "vimeo" / "graph-explorer"
    expected_path_to_lint = expected_dir_path / "graph_explorer"
    expected_pylintrc_path = expected_dir_path / ".pylintrcui"

    args = ["--ignore-pattern='re*'"]
    package_to_lint = PackageToLint(
        url="https://github.com/vimeo/graph-explorer.git",
        branch="main",
        directories=["graph_explorer"],
        pylintrc_relpath=".pylintrcui",
        pylint_additional_args=args,
    )

    assert package_to_lint.url == "https://github.com/vimeo/graph-explorer.git"
    assert package_to_lint.branch == "main"
    assert package_to_lint.directories == ["graph_explorer"]
    assert package_to_lint.pylintrc_relpath == ".pylintrcui"
    assert package_to_lint.pylint_additional_args == args
    assert package_to_lint.paths_to_lint == [str(expected_path_to_lint)]
    assert package_to_lint.clone_directory == expected_dir_path
    assert package_to_lint.pylintrc == expected_pylintrc_path
    expected_args = [
        str(expected_path_to_lint),
        f"--rcfile={expected_pylintrc_path}",
    ] + args
    assert package_to_lint.pylint_args == expected_args
def get_packages_to_lint_from_json(
        json_path: Union[Path, str]) -> Dict[str, PackageToLint]:
    result: Dict[str, PackageToLint] = {}
    with open(json_path, encoding="utf8") as f:
        for name, package_data in json.load(f).items():
            result[name] = PackageToLint(**package_data)
    return result
def test_package_to_lint_default_value() -> None:
    """Test that the PackageToLint is instantiated correctly with default value."""
    package_to_lint = PackageToLint(
        url="https://github.com/pallets/flask.git",
        branch="main",
        directories=["src/flask"],  # Must work on Windows (src\\flask)
    )
    assert package_to_lint.pylintrc is None
    expected_path_to_lint = (PRIMER_DIRECTORY_PATH / "pallets" / "flask" /
                             "src" / "flask")
    assert package_to_lint.pylint_args == [str(expected_path_to_lint)]