(self)
| 25 | |
| 26 | class TestGrpcioTools(unittest.TestCase): |
| 27 | def test_compile_proto(self): |
| 28 | with tempfile.TemporaryDirectory() as tmpdir: |
| 29 | proto_path = os.path.join(tmpdir, "ping.proto") |
| 30 | with open(proto_path, "w") as f: |
| 31 | f.write(PROTO_CONTENT) |
| 32 | |
| 33 | subprocess.check_call( |
| 34 | [ |
| 35 | sys.executable, |
| 36 | "-m", |
| 37 | "grpc_tools.protoc", |
| 38 | f"--proto_path={tmpdir}", |
| 39 | f"--python_out={tmpdir}", |
| 40 | f"--grpc_python_out={tmpdir}", |
| 41 | f"--pyi_out={tmpdir}", |
| 42 | "ping.proto", |
| 43 | ] |
| 44 | ) |
| 45 | |
| 46 | pb2_path = os.path.join(tmpdir, "ping_pb2.py") |
| 47 | pb2_grpc_path = os.path.join(tmpdir, "ping_pb2_grpc.py") |
| 48 | pyi_path = os.path.join(tmpdir, "ping_pb2.pyi") |
| 49 | self.assertTrue(os.path.exists(pb2_path)) |
| 50 | self.assertTrue(os.path.exists(pb2_grpc_path)) |
| 51 | self.assertTrue(os.path.exists(pyi_path)) |
| 52 | |
| 53 | sys.path.insert(0, tmpdir) |
| 54 | import ping_pb2 |
| 55 | import ping_pb2_grpc |
| 56 | |
| 57 | req = ping_pb2.PingRequest(message="hello") |
| 58 | self.assertEqual(req.message, "hello") |
| 59 | self.assertTrue(hasattr(ping_pb2_grpc, "PingServiceStub")) |
| 60 | self.assertTrue(hasattr(ping_pb2_grpc, "PingServiceServicer")) |
nothing calls this directly
no outgoing calls
no test coverage detected