def test_validate_bazel_deps_valid() -> None: result = validate_bazel_deps( py2_compatible=False, py3_compatible=True, imports=[ Import( module="dropbox.runfiles", location=SourceLocation(source_file=Path("foo.py"), lineno=5), is_from=False, ), Import( module="asyncio", location=SourceLocation(source_file=Path("foo.py"), lineno=6), is_from=False, ), Import( module="grpc.codes", location=SourceLocation(source_file=Path("foo.py"), lineno=7), is_from=False, ), ], primary_target="//target", provides_map={"dropbox.runfiles": "//dropbox/runfiles"}, prefix_provides_map={"grpc": "//pip/grpc"}, ) assert not result.unresolved_imports assert not result.unused_targets
def test_validate_bazel_deps_invalid_with_identifier() -> None: result = validate_bazel_deps( py2_compatible=False, py3_compatible=True, imports=[ Import( module="dropbox.runfiles.data_path", location=SourceLocation(source_file=Path("foo.py"), lineno=5), is_from=False, ), Import( module="asyncio", location=SourceLocation(source_file=Path("foo.py"), lineno=6), is_from=False, ), ], primary_target="//target", provides_map={"dropbox.runfiles": "//dropbox/runfiles"}, prefix_provides_map={}, ) assert [i.module for i in result.unresolved_imports ] == ["dropbox.runfiles.data_path"] assert result.unused_targets == {"//dropbox/runfiles"}