Fix Windows

pull/21458/head
Richard Belleville 4 years ago
parent 05aaf3d939
commit b50110b583
  1. 2
      src/python/grpcio/grpc/_runtime_protos.py
  2. 21
      src/python/grpcio_tests/tests/unit/_dynamic_stubs_test.py
  3. 4
      tools/distrib/python/grpcio_tools/grpc_tools/protoc.py
  4. 1
      tools/distrib/python/grpcio_tools/grpc_tools/test/protoc_test.py

@ -105,7 +105,7 @@ if sys.version_info[0] < 3:
protos_and_services = _interpreter_version_protos_and_services
else:
try:
import grpc_tool # pylint: disable=unused-import
import grpc_tools # pylint: disable=unused-import
except ImportError as e:
# NOTE: It's possible that we're encountering a transitive ImportError, so
# we check for that and re-raise if so.

@ -13,12 +13,13 @@
# limitations under the License.
"""Test of dynamic stub import API."""
import unittest
import logging
import contextlib
import sys
import multiprocessing
import functools
import logging
import multiprocessing
import os
import sys
import unittest
@contextlib.contextmanager
@ -39,11 +40,10 @@ def _grpc_tools_unimportable():
sys.path = original_sys_path
# TODO: Dedupe with grpc_tools test?
def _wrap_in_subprocess(error_queue, fn):
def _collect_errors(fn):
@functools.wraps(fn)
def _wrapped():
def _wrapped(error_queue):
try:
fn()
except Exception as e:
@ -55,8 +55,7 @@ def _wrap_in_subprocess(error_queue, fn):
def _run_in_subprocess(test_case):
error_queue = multiprocessing.Queue()
wrapped_case = _wrap_in_subprocess(error_queue, test_case)
proc = multiprocessing.Process(target=wrapped_case)
proc = multiprocessing.Process(target=test_case, args=(error_queue,))
proc.start()
proc.join()
if not error_queue.empty():
@ -77,17 +76,19 @@ def _assert_unimplemented(msg_substr):
assert False, "Did not raise NotImplementedError"
@_collect_errors
def _test_sunny_day():
if sys.version_info[0] == 3:
import grpc
protos, services = grpc.protos_and_services(
"tests/unit/data/foo/bar.proto")
os.path.join("tests", "unit", "data", "foo", "bar.proto"))
assert protos.BarMessage is not None
assert services.BarStub is not None
else:
_assert_unimplemented("Python 3")
@_collect_errors
def _test_grpc_tools_unimportable():
with _grpc_tools_unimportable():
if sys.version_info[0] == 3:

@ -62,7 +62,9 @@ if sys.version_info[0] > 2:
def _module_name_to_proto_file(suffix, module_name):
components = module_name.split(".")
proto_name = components[-1][:-1 * len(suffix)]
return os.path.sep.join(components[:-1] + [proto_name + ".proto"])
# NOTE(rbellevi): The Protobuf library expects this path to use
# forward slashes on every platform.
return "/".join(components[:-1] + [proto_name + ".proto"])
def _proto_file_to_module_name(suffix, proto_file):
components = proto_file.split(os.path.sep)

@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for protoc."""
from __future__ import absolute_import

Loading…
Cancel
Save