14 """Test of dynamic stub import API."""
19 import multiprocessing
26 _DATA_DIR = os.path.join(
"tests",
"unit",
"data")
29 @contextlib.contextmanager
31 original_sys_path = sys.path
32 sys.path = [path
for path
in sys.path
if "grpcio_tools" not in path]
39 sys.path = original_sys_path
40 raise unittest.SkipTest(
"Failed to make grpc_tools unimportable.")
44 sys.path = original_sys_path
50 def _wrapped(error_queue):
53 except Exception
as e:
64 if sys.version_info[0] == 3:
74 0, os.path.join(os.path.realpath(os.path.dirname(__file__)),
".."))
75 error_queue = multiprocessing.Queue()
76 proc = multiprocessing.Process(target=test_case, args=(error_queue,))
80 if not error_queue.empty():
81 raise error_queue.get()
82 assert proc.exitcode == 0,
"Process exited with code {}".
format(
89 protos, services = grpc.protos_and_services(
90 "tests/unit/data/foo/bar.proto")
91 except NotImplementedError
as e:
92 assert msg_substr
in str(e),
"{} was not in '{}'".
format(
95 assert False,
"Did not raise NotImplementedError"
102 protos, services = grpc.protos_and_services(
103 os.path.join(_DATA_DIR,
"foo",
"bar.proto"))
104 assert protos.BarMessage
is not None
105 assert services.BarStub
is not None
112 protos, services = grpc.protos_and_services(
113 os.path.join(_DATA_DIR,
"foo",
"bar_with_wkt.proto"))
114 assert protos.BarMessage
is not None
115 assert services.BarStub
is not None
128 @unittest.skipIf(os.name ==
"nt",
"Windows multiprocessing unsupported")
129 @unittest.skipIf(test_common.running_under_gevent(),
130 "Import paths do not work with gevent runner.")
143 if __name__ ==
"__main__":
144 logging.basicConfig()
145 unittest.main(verbosity=2)