def assert_requirements(expected_req_strs, addr): tgt = rule_runner.get_target(Address.parse(addr)) reqs = rule_runner.request( ExportedTargetRequirements, [DependencyOwner(ExportedTarget(tgt))], ) assert sorted(expected_req_strs) == list(reqs)
def assert_owned(owned: Iterable[str], exported: Address): tgt = rule_runner.get_target(exported) assert sorted(owned) == sorted( od.target.address.spec for od in rule_runner.request( OwnedDependencies, [DependencyOwner(ExportedTarget(tgt))], ))
def assert_sources( expected_files, expected_packages, expected_namespace_packages, expected_package_data, addrs, ): rule_runner = create_setup_py_rule_runner( rules=[ get_sources, get_owned_dependencies, get_exporting_owner, *target_types_rules.rules(), *python_sources.rules(), QueryRule(OwnedDependencies, (DependencyOwner,)), QueryRule(DistBuildSources, (DistBuildChrootRequest,)), ] ) rule_runner.write_files( { "src/python/foo/bar/baz/BUILD": textwrap.dedent( """ python_sources(name='baz1', sources=['baz1.py']) python_sources(name='baz2', sources=['baz2.py']) """ ), "src/python/foo/bar/baz/baz1.py": "", "src/python/foo/bar/baz/baz2.py": "", "src/python/foo/bar/__init__.py": _namespace_decl, "src/python/foo/qux/BUILD": "python_sources()", "src/python/foo/qux/__init__.py": "", "src/python/foo/qux/qux.py": "", "src/python/foo/resources/BUILD": 'resource(source="js/code.js")', "src/python/foo/resources/js/code.js": "", "src/python/foo/__init__.py": "", # We synthesize an owner for the addrs, so we have something to put in SetupPyChrootRequest. "src/python/foo/BUILD": textwrap.dedent( f""" python_distribution( name="dist", dependencies=["{'","'.join(addr.spec for addr in addrs)}"], provides=setup_py(name="foo", version="3.2.1"), ) """ ), } ) owner_tgt = rule_runner.get_target(Address("src/python/foo", target_name="dist")) srcs = rule_runner.request( DistBuildSources, [DistBuildChrootRequest(ExportedTarget(owner_tgt), py2=False)], ) chroot_snapshot = rule_runner.request(Snapshot, [srcs.digest]) assert sorted(expected_files) == sorted(chroot_snapshot.files) assert sorted(expected_packages) == sorted(srcs.packages) assert sorted(expected_namespace_packages) == sorted(srcs.namespace_packages) assert expected_package_data == dict(srcs.package_data)
def assert_chroot( rule_runner: RuleRunner, expected_files: list[str], expected_setup_kwargs, addr: Address, ) -> None: tgt = rule_runner.get_target(addr) req = DistBuildChrootRequest(ExportedTarget(tgt), py2=False) chroot = rule_runner.request(DistBuildChroot, [req]) snapshot = rule_runner.request(Snapshot, [chroot.digest]) assert sorted(expected_files) == sorted(snapshot.files) if expected_setup_kwargs is not None: sources = rule_runner.request(DistBuildSources, [req]) setup_kwargs = rule_runner.request( FinalizedSetupKwargs, [GenerateSetupPyRequest(ExportedTarget(tgt), sources)] ) assert expected_setup_kwargs == setup_kwargs.kwargs
def assert_chroot(rule_runner: RuleRunner, expected_files, expected_setup_kwargs, addr: Address) -> None: tgt = rule_runner.get_target(addr) chroot = rule_runner.request( SetupPyChroot, [SetupPyChrootRequest(ExportedTarget(tgt), py2=False)], ) snapshot = rule_runner.request(Snapshot, [chroot.digest]) assert sorted(expected_files) == sorted(snapshot.files) assert expected_setup_kwargs == chroot.setup_kwargs.kwargs
def assert_chroot_error(rule_runner: RuleRunner, addr: Address, exc_cls: Type[Exception]) -> None: tgt = rule_runner.get_target(addr) with pytest.raises(ExecutionError) as excinfo: rule_runner.request( SetupPyChroot, [SetupPyChrootRequest(ExportedTarget(tgt), py2=False)], ) ex = excinfo.value assert len(ex.wrapped_exceptions) == 1 assert type(ex.wrapped_exceptions[0]) == exc_cls
def assert_requirements( expected_req_strs, addr: Address, *, version_scheme: FirstPartyDependencyVersionScheme = FirstPartyDependencyVersionScheme.EXACT, ): rule_runner.set_options( [f"--setup-py-generation-first-party-dependency-version-scheme={version_scheme.value}"], env_inherit={"PATH", "PYENV_ROOT", "HOME"}, ) tgt = rule_runner.get_target(addr) reqs = rule_runner.request( ExportedTargetRequirements, [DependencyOwner(ExportedTarget(tgt))], ) assert sorted(expected_req_strs) == list(reqs)