Rehome grpc_tools tests

pull/21504/head
Richard Belleville 5 years ago
parent d4ad4ad03b
commit 5f5402505e
  1. 38
      tools/distrib/python/grpcio_tools/grpc_tools/BUILD
  2. 12
      tools/distrib/python/grpcio_tools/grpc_tools/complicated.proto
  3. 11
      tools/distrib/python/grpcio_tools/grpc_tools/simpler.proto
  4. 41
      tools/distrib/python/grpcio_tools/grpc_tools/test/BUILD.bazel
  5. 12
      tools/distrib/python/grpcio_tools/grpc_tools/test/complicated.proto
  6. 0
      tools/distrib/python/grpcio_tools/grpc_tools/test/flawed.proto
  7. 41
      tools/distrib/python/grpcio_tools/grpc_tools/test/protoc_test.py
  8. 6
      tools/distrib/python/grpcio_tools/grpc_tools/test/simple.proto
  9. 11
      tools/distrib/python/grpcio_tools/grpc_tools/test/simpler.proto
  10. 2
      tools/distrib/python/grpcio_tools/grpc_tools/test/simplest.proto

@ -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",
)

@ -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;
};

@ -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;
};

@ -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",
)

@ -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;
};

@ -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

@ -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 {

@ -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;
};

@ -1,6 +1,6 @@
syntax = "proto3";
package grpc_tools.simplest;
package grpc_tools.test.simplest;
message SimplestMessage {
int64 i_definitely_dont_exist = 1;
Loading…
Cancel
Save