def test_grid_face_count(): model = UnstructuredGridBmiModel() server = BmiServer(model, True) grid_id, request = make_grid_request(model) result = server.getGridFaceCount(request, None).count assert result == 3
def test_get_grid_nodes_per_face(): model = UnstructuredGridBmiModel() server = BmiServer(model, True) grid_id, request = make_grid_request(model) result = server.getGridNodesPerFace(request, None).nodes_per_face numpy.testing.assert_allclose(result, (4, 4, 3))
def make_bmi_classes(init=False): server, local = BmiServer(FlatBmiHeat()), FlatBmiHeat() if init: req = RequestStub() numpy.random.seed(0) server.initialize(req, None) numpy.random.seed(0) local.initialize(None) return server, local
def test_get_grid_face_edges(): model = UnstructuredGridBmiModel() server = BmiServer(model, True) grid_id, request = make_grid_request(model) result = server.getGridFaceEdges(request, None).face_edges expected = (0, 1, 2, 3, 4, 5, 6, 1, 6, 7, 2) numpy.testing.assert_allclose(result, expected)
def test_get_grid_edge_nodes(): model = UnstructuredGridBmiModel() server = BmiServer(model, True) grid_id, request = make_grid_request(model) result = server.getGridEdgeNodes(request, None).edge_nodes expected = (0, 1, 1, 2, 2, 3, 3, 0, 1, 4, 4, 5, 5, 2, 5, 3) numpy.testing.assert_allclose(result, expected)
def test_get_grid_z(): model = Rect3DGridModel() server = BmiServer(model, True) grid_id, request = make_grid_request(model) result = server.getGridZ(request, None).coordinates expected = numpy.array([2.1, 2.2]) numpy.testing.assert_allclose(result, expected)
def make_bmi_classes(init=False): client = BmiClient(stub=ServerWrapper(BmiServer(FlatBmiHeat()))) local = FlatBmiHeat() if init: numpy.random.seed(0) client.initialize(None) numpy.random.seed(0) local.initialize(None) return client, local
def test_method_exception(client_method, client_request): exc = SomeException('bmi method always fails') model = FailingModel(exc) client = BmiClient(stub=ServerWrapper(BmiServer(model))) with pytest.raises(Exception) as excinfo: getattr(client, client_method)(*client_request) assert "bmi method always fails" in str(excinfo.value)
def test_method_exceptions_with_stacktrace(server_method, server_request): exc = SomeException('Bmi method always fails') model = FailingModel(exc) server = BmiServer(model, True) context = Mock(grpc.ServicerContext) getattr(server, server_method)(server_request, context) context.abort_with_status.assert_called_once() status = context.abort_with_status.call_args[0][0] assert status.code == grpc.StatusCode.INTERNAL assert status.details == 'Bmi method always fails' metadata = status_pb2.Status.FromString(status.trailing_metadata[0][1]) debuginfo = error_details_pb2.DebugInfo() metadata.details[0].Unpack(debuginfo) assert debuginfo.detail == "SomeException('Bmi method always fails',)" assert len(debuginfo.stack_entries) > 0
def bmiclient(self, bmimodel): client = BmiClient(stub=ServerWrapper(BmiServer(bmimodel))) yield client del client
def bmiclient(self): model = UnstructuredGridBmiModel() client = BmiClient(stub=ServerWrapper(BmiServer(model))) yield client del client
def bmiclient(self): model = Structured2DQuadrilateralsGridModel() client = BmiClient(stub=ServerWrapper(BmiServer(model))) yield client del client
def bmiclient(self): model = Rect2DGridModel() client = BmiClient(stub=ServerWrapper(BmiServer(model))) yield client del client