Ejemplo n.º 1
0
 def create_for_test(cls, address: Address,
                     compat: str | None) -> MockFieldSet:
     return cls(
         address=address,
         interpreter_constraints=InterpreterConstraintsField(
             [compat] if compat else None, address=address),
     )
Ejemplo n.º 2
0
def test_first_party_plugins(rule_runner: RuleRunner) -> None:
    rule_runner.write_files(
        {
            "BUILD": dedent(
                """\
                python_requirement(name='flake8', requirements=['flake8==2.11.1'])
                python_requirement(name='colors', requirements=['ansicolors'])
                """
            ),
            "flake8-plugins/subdir1/util.py": "",
            "flake8-plugins/subdir1/BUILD": dedent(
                """\
                python_sources(
                    interpreter_constraints=['==3.9.*'],
                    dependencies=['flake8-plugins/subdir2']
                )
                """
            ),
            "flake8-plugins/subdir2/another_util.py": "",
            "flake8-plugins/subdir2/BUILD": "python_sources(interpreter_constraints=['==3.8.*'])",
            "flake8-plugins/plugin.py": "",
            "flake8-plugins/BUILD": dedent(
                """\
                python_sources(
                    dependencies=['//:flake8', '//:colors', "flake8-plugins/subdir1"]
                )
                """
            ),
        }
    )
    rule_runner.set_options(
        [
            "--source-root-patterns=flake8-plugins",
            "--flake8-source-plugins=flake8-plugins/plugin.py",
        ],
        env_inherit={"PATH", "PYENV_ROOT", "HOME"},
    )
    first_party_plugins = rule_runner.request(Flake8FirstPartyPlugins, [])
    assert first_party_plugins.requirement_strings == FrozenOrderedSet(
        ["ansicolors", "flake8==2.11.1"]
    )
    assert first_party_plugins.interpreter_constraints_fields == FrozenOrderedSet(
        [
            InterpreterConstraintsField(ic, Address("", target_name="tgt"))
            for ic in (None, ["==3.9.*"], ["==3.8.*"])
        ]
    )
    assert (
        first_party_plugins.sources_digest
        == rule_runner.make_snapshot(
            {
                f"{Flake8FirstPartyPlugins.PREFIX}/plugin.py": "",
                f"{Flake8FirstPartyPlugins.PREFIX}/subdir1/util.py": "",
                f"{Flake8FirstPartyPlugins.PREFIX}/subdir2/another_util.py": "",
            }
        ).digest
    )
Ejemplo n.º 3
0
def test_first_party_plugins(rule_runner: RuleRunner) -> None:
    rule_runner.write_files(
        {
            "BUILD": dedent(
                """\
                python_requirement_library(name='pylint', requirements=['pylint==2.6.2'])
                python_requirement_library(name='colors', requirements=['ansicolors'])
                """
            ),
            "pylint-plugins/subdir1/util.py": "",
            "pylint-plugins/subdir1/BUILD": dedent(
                """\
                python_library(
                    interpreter_constraints=['==3.5.*'],
                    dependencies=['pylint-plugins/subdir2']
                )
                """
            ),
            "pylint-plugins/subdir2/another_util.py": "",
            "pylint-plugins/subdir2/BUILD": ("python_library(interpreter_constraints=['==3.4.*'])"),
            "pylint-plugins/plugin.py": "",
            "pylint-plugins/BUILD": dedent(
                """\
                python_library(
                    dependencies=['//:pylint', '//:colors', "pylint-plugins/subdir1"]
                )
                """
            ),
        }
    )
    rule_runner.set_options(
        [
            "--source-root-patterns=pylint-plugins",
            "--pylint-source-plugins=pylint-plugins/plugin.py",
        ]
    )
    first_party_plugins = rule_runner.request(PylintFirstPartyPlugins, [])
    assert first_party_plugins.requirement_strings == FrozenOrderedSet(
        ["ansicolors", "pylint==2.6.2"]
    )
    assert first_party_plugins.interpreter_constraints_fields == FrozenOrderedSet(
        [
            InterpreterConstraintsField(ic, Address("", target_name="tgt"))
            for ic in (None, ["==3.5.*"], ["==3.4.*"])
        ]
    )
    assert (
        first_party_plugins.sources_digest
        == rule_runner.make_snapshot(
            {
                f"{PylintFirstPartyPlugins.PREFIX}/plugin.py": "",
                f"{PylintFirstPartyPlugins.PREFIX}/subdir1/util.py": "",
                f"{PylintFirstPartyPlugins.PREFIX}/subdir2/another_util.py": "",
            }
        ).digest
    )