Do not import grpc_tools.protoc from grpc_tools

pull/24216/head
Richard Belleville 4 years ago
parent 889ea7cd09
commit a80a3b72bb
  1. 28
      src/python/grpcio_tests/tests/protoc_plugin/_python_plugin_test.py
  2. 1
      src/python/grpcio_tests/tests/tests.json
  3. 2
      tools/distrib/python/grpcio_tools/grpc_tools/__init__.py

@ -628,5 +628,33 @@ class SimpleStubsPluginTest(unittest.TestCase):
self.assertEqual(expected_response, response) self.assertEqual(expected_response, response)
class ModuleMainTest(unittest.TestCase):
"""Test case for running `python -m grpc_tools.protoc`.
"""
def test_clean_output(self):
if sys.executable is None:
raise unittest.SkipTest(
"Running on a interpreter that cannot be invoked from the CLI.")
proto_dir_path = os.path.join("src", "proto")
test_proto_path = os.path.join(proto_dir_path, "grpc", "testing",
"empty.proto")
streams = tuple(tempfile.TemporaryFile() for _ in range(2))
with tempfile.TemporaryDirectory() as work_dir:
invocation = (sys.executable, "-m", "grpc_tools.protoc",
"--proto_path", proto_dir_path, "--python_out",
work_dir, "--grpc_python_out", work_dir,
test_proto_path)
proc = subprocess.Popen(invocation,
stdout=streams[0],
stderr=streams[1])
proc.wait()
outs = []
for stream in streams:
stream.seek(0)
self.assertEqual(0, len(stream.read()))
self.assertEqual(0, proc.returncode)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main(verbosity=2) unittest.main(verbosity=2)

@ -8,6 +8,7 @@
"interop._secure_intraop_test.SecureIntraopTest", "interop._secure_intraop_test.SecureIntraopTest",
"protoc_plugin._python_plugin_test.PythonPluginTest", "protoc_plugin._python_plugin_test.PythonPluginTest",
"protoc_plugin._python_plugin_test.SimpleStubsPluginTest", "protoc_plugin._python_plugin_test.SimpleStubsPluginTest",
"protoc_plugin._python_plugin_test.ModuleMainTest",
"protoc_plugin._split_definitions_test.SameProtoGrpcBeforeProtoProtocStyleTest", "protoc_plugin._split_definitions_test.SameProtoGrpcBeforeProtoProtocStyleTest",
"protoc_plugin._split_definitions_test.SameProtoMid2016ProtocStyleTest", "protoc_plugin._split_definitions_test.SameProtoMid2016ProtocStyleTest",
"protoc_plugin._split_definitions_test.SameProtoProtoBeforeGrpcProtocStyleTest", "protoc_plugin._split_definitions_test.SameProtoProtoBeforeGrpcProtocStyleTest",

@ -11,5 +11,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from .protoc import main

Loading…
Cancel
Save