diff --git a/tools/distrib/python/grpcio_tools/grpc_tools/BUILD b/tools/distrib/python/grpcio_tools/grpc_tools/BUILD index 7538cf61a03..d9822e100bf 100644 --- a/tools/distrib/python/grpcio_tools/grpc_tools/BUILD +++ b/tools/distrib/python/grpcio_tools/grpc_tools/BUILD @@ -43,41 +43,3 @@ py_library( srcs_version = "PY2AND3", imports = [NON_BAZEL_ROOT], ) - -proto_library( - name = "simplest_proto", - srcs = ["simplest.proto"], - strip_import_prefix = "/tools/distrib/python/grpcio_tools/", - testonly = True, -) - -proto_library( - name = "complicated_proto", - srcs = ["complicated.proto"], - deps = [":simplest_proto"], - strip_import_prefix = "/tools/distrib/python/grpcio_tools/", - testonly = True, -) - -py_proto_library( - name = "complicated_py_pb2", - deps = ["complicated_proto"], - testonly = True, -) - -py_test( - name = "protoc_test", - srcs = ["protoc_test.py"], - deps = [ - "//tools/distrib/python/grpcio_tools/grpc_tools:grpc_tools", - ":complicated_py_pb2", - ], - data = [ - "simple.proto", - "simpler.proto", - "simplest.proto", - "complicated.proto", - "flawed.proto", - ], - python_version = "PY3", -) diff --git a/tools/distrib/python/grpcio_tools/grpc_tools/complicated.proto b/tools/distrib/python/grpcio_tools/grpc_tools/complicated.proto deleted file mode 100644 index c6c500d3504..00000000000 --- a/tools/distrib/python/grpcio_tools/grpc_tools/complicated.proto +++ /dev/null @@ -1,12 +0,0 @@ -syntax = "proto3"; - -package grpc_tools.complicated; - -import "grpc_tools/simplest.proto"; - -message ComplicatedMessage { - bool yes = 1; - bool no = 2; - bool why = 3; - grpc_tools.simplest.SimplestMessage simplest_message = 4; -}; diff --git a/tools/distrib/python/grpcio_tools/grpc_tools/simpler.proto b/tools/distrib/python/grpcio_tools/grpc_tools/simpler.proto deleted file mode 100644 index 9e0943acef3..00000000000 --- a/tools/distrib/python/grpcio_tools/grpc_tools/simpler.proto +++ /dev/null @@ -1,11 +0,0 @@ -syntax = "proto3"; - -package grpc_tools.simpler; - -import "grpc_tools/simplest.proto"; - -message SimplerMessage { - int64 do_i_even_exist = 1; - grpc_tools.simplest.SimplestMessage simplest_message = 2; -}; - diff --git a/tools/distrib/python/grpcio_tools/grpc_tools/test/BUILD.bazel b/tools/distrib/python/grpcio_tools/grpc_tools/test/BUILD.bazel new file mode 100644 index 00000000000..037add24278 --- /dev/null +++ b/tools/distrib/python/grpcio_tools/grpc_tools/test/BUILD.bazel @@ -0,0 +1,41 @@ +package(default_testonly = 1) + +load("//bazel:python_rules.bzl", "py_grpc_library", "py_proto_library") + +proto_library( + name = "simplest_proto", + srcs = ["simplest.proto"], + strip_import_prefix = "/tools/distrib/python/grpcio_tools/", + testonly = True, +) + +proto_library( + name = "complicated_proto", + srcs = ["complicated.proto"], + deps = [":simplest_proto"], + strip_import_prefix = "/tools/distrib/python/grpcio_tools/", + testonly = True, +) + +py_proto_library( + name = "complicated_py_pb2", + deps = ["complicated_proto"], + testonly = True, +) + +py_test( + name = "protoc_test", + srcs = ["protoc_test.py"], + deps = [ + "//tools/distrib/python/grpcio_tools/grpc_tools:grpc_tools", + ":complicated_py_pb2", + ], + data = [ + "simple.proto", + "simpler.proto", + "simplest.proto", + "complicated.proto", + "flawed.proto", + ], + python_version = "PY3", +) diff --git a/tools/distrib/python/grpcio_tools/grpc_tools/test/complicated.proto b/tools/distrib/python/grpcio_tools/grpc_tools/test/complicated.proto new file mode 100644 index 00000000000..cdbdb128860 --- /dev/null +++ b/tools/distrib/python/grpcio_tools/grpc_tools/test/complicated.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package grpc_tools.test.complicated; + +import "grpc_tools/test/simplest.proto"; + +message ComplicatedMessage { + bool yes = 1; + bool no = 2; + bool why = 3; + grpc_tools.test.simplest.SimplestMessage simplest_message = 4; +}; diff --git a/tools/distrib/python/grpcio_tools/grpc_tools/flawed.proto b/tools/distrib/python/grpcio_tools/grpc_tools/test/flawed.proto similarity index 100% rename from tools/distrib/python/grpcio_tools/grpc_tools/flawed.proto rename to tools/distrib/python/grpcio_tools/grpc_tools/test/flawed.proto diff --git a/tools/distrib/python/grpcio_tools/grpc_tools/protoc_test.py b/tools/distrib/python/grpcio_tools/grpc_tools/test/protoc_test.py similarity index 69% rename from tools/distrib/python/grpcio_tools/grpc_tools/protoc_test.py rename to tools/distrib/python/grpcio_tools/grpc_tools/test/protoc_test.py index d5a9e039dae..f35b458c549 100644 --- a/tools/distrib/python/grpcio_tools/grpc_tools/protoc_test.py +++ b/tools/distrib/python/grpcio_tools/grpc_tools/test/protoc_test.py @@ -38,57 +38,60 @@ def _run_in_subprocess(test_case): def _test_import_protos(): from grpc_tools import protoc proto_path = "tools/distrib/python/grpcio_tools/" - protos = protoc._protos("grpc_tools/simple.proto", [proto_path]) + protos = protoc._protos("grpc_tools/test/simple.proto", [proto_path]) assert protos.SimpleMessage is not None def _test_import_services(): from grpc_tools import protoc proto_path = "tools/distrib/python/grpcio_tools/" - protos = protoc._protos("grpc_tools/simple.proto", [proto_path]) - services = protoc._services("grpc_tools/simple.proto", [proto_path]) + protos = protoc._protos("grpc_tools/test/simple.proto", [proto_path]) + services = protoc._services("grpc_tools/test/simple.proto", [proto_path]) assert services.SimpleMessageServiceStub is not None # NOTE: In this case, we use sys.path to determine where to look for our protos. def _test_import_implicit_include(): from grpc_tools import protoc - protos = protoc._protos("grpc_tools/simple.proto") - services = protoc._services("grpc_tools/simple.proto") + protos = protoc._protos("grpc_tools/test/simple.proto") + services = protoc._services("grpc_tools/test/simple.proto") assert services.SimpleMessageServiceStub is not None def _test_import_services_without_protos(): from grpc_tools import protoc - services = protoc._services("grpc_tools/simple.proto") + services = protoc._services("grpc_tools/test/simple.proto") assert services.SimpleMessageServiceStub is not None def _test_proto_module_imported_once(): from grpc_tools import protoc proto_path = "tools/distrib/python/grpcio_tools/" - protos = protoc._protos("grpc_tools/simple.proto", [proto_path]) - services = protoc._services("grpc_tools/simple.proto", [proto_path]) - complicated_protos = protoc._protos("grpc_tools/complicated.proto", + protos = protoc._protos("grpc_tools/test/simple.proto", [proto_path]) + services = protoc._services("grpc_tools/test/simple.proto", [proto_path]) + complicated_protos = protoc._protos("grpc_tools/test/complicated.proto", [proto_path]) - assert (complicated_protos.grpc__tools_dot_simplest__pb2.SimplestMessage is - protos.grpc__tools_dot_simpler__pb2.grpc__tools_dot_simplest__pb2. - SimplestMessage) + simple_message = protos.SimpleMessage() + complicated_message = complicated_protos.ComplicatedMessage() + assert (simple_message.simpler_message.simplest_message.__class__ is + complicated_message.simplest_message.__class__) def _test_static_dynamic_combo(): - from grpc_tools import complicated_pb2 + from grpc_tools.test import complicated_pb2 from grpc_tools import protoc proto_path = "tools/distrib/python/grpcio_tools/" - protos = protoc._protos("grpc_tools/simple.proto", [proto_path]) - assert (complicated_pb2.grpc__tools_dot_simplest__pb2.SimplestMessage is - protos.grpc__tools_dot_simpler__pb2.grpc__tools_dot_simplest__pb2. - SimplestMessage) + protos = protoc._protos("grpc_tools/test/simple.proto", [proto_path]) + static_message = complicated_pb2.ComplicatedMessage() + dynamic_message = protos.SimpleMessage() + assert (dynamic_message.simpler_message.simplest_message.__class__ is + static_message.simplest_message.__class__) def _test_combined_import(): from grpc_tools import protoc - protos, services = protoc._protos_and_services("grpc_tools/simple.proto") + protos, services = protoc._protos_and_services( + "grpc_tools/test/simple.proto") assert protos.SimpleMessage is not None assert services.SimpleMessageServiceStub is not None @@ -96,7 +99,7 @@ def _test_combined_import(): def _test_syntax_errors(): from grpc_tools import protoc try: - protos = protoc._protos("grpc_tools/flawed.proto") + protos = protoc._protos("grpc_tools/test/flawed.proto") except Exception as e: error_str = str(e) assert "flawed.proto" in error_str diff --git a/tools/distrib/python/grpcio_tools/grpc_tools/simple.proto b/tools/distrib/python/grpcio_tools/grpc_tools/test/simple.proto similarity index 73% rename from tools/distrib/python/grpcio_tools/grpc_tools/simple.proto rename to tools/distrib/python/grpcio_tools/grpc_tools/test/simple.proto index 94cc880d641..8454e62492c 100644 --- a/tools/distrib/python/grpcio_tools/grpc_tools/simple.proto +++ b/tools/distrib/python/grpcio_tools/grpc_tools/test/simple.proto @@ -1,8 +1,8 @@ syntax = "proto3"; -package grpc_tools.simple; +package grpc_tools.test.simple; -import "grpc_tools/simpler.proto"; +import "grpc_tools/test/simpler.proto"; message SimpleMessage { string msg = 1; @@ -10,7 +10,7 @@ message SimpleMessage { bool personal = 2; bool business = 3; }; - grpc_tools.simpler.SimplerMessage simpler_message = 4; + grpc_tools.test.simpler.SimplerMessage simpler_message = 4; }; message SimpleMessageRequest { diff --git a/tools/distrib/python/grpcio_tools/grpc_tools/test/simpler.proto b/tools/distrib/python/grpcio_tools/grpc_tools/test/simpler.proto new file mode 100644 index 00000000000..41b428cd520 --- /dev/null +++ b/tools/distrib/python/grpcio_tools/grpc_tools/test/simpler.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package grpc_tools.test.simpler; + +import "grpc_tools/test/simplest.proto"; + +message SimplerMessage { + int64 do_i_even_exist = 1; + grpc_tools.test.simplest.SimplestMessage simplest_message = 2; +}; + diff --git a/tools/distrib/python/grpcio_tools/grpc_tools/simplest.proto b/tools/distrib/python/grpcio_tools/grpc_tools/test/simplest.proto similarity index 72% rename from tools/distrib/python/grpcio_tools/grpc_tools/simplest.proto rename to tools/distrib/python/grpcio_tools/grpc_tools/test/simplest.proto index 6056c4aaa51..f88b8b52153 100644 --- a/tools/distrib/python/grpcio_tools/grpc_tools/simplest.proto +++ b/tools/distrib/python/grpcio_tools/grpc_tools/test/simplest.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package grpc_tools.simplest; +package grpc_tools.test.simplest; message SimplestMessage { int64 i_definitely_dont_exist = 1;