This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new c50e3fbab2 ARROW-16216: [Python][FlightRPC] Fix test_flight.py when 
Flight is not available
c50e3fbab2 is described below

commit c50e3fbab20923eec7358a0f7c94fbe8f57abf25
Author: David Li <[email protected]>
AuthorDate: Tue Apr 19 08:28:22 2022 +0900

    ARROW-16216: [Python][FlightRPC] Fix test_flight.py when Flight is not 
available
    
    Closes #12911 from lidavidm/arrow-16216
    
    Authored-by: David Li <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 python/pyarrow/tests/test_flight.py | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/python/pyarrow/tests/test_flight.py 
b/python/pyarrow/tests/test_flight.py
index 9c61097251..56a033df41 100644
--- a/python/pyarrow/tests/test_flight.py
+++ b/python/pyarrow/tests/test_flight.py
@@ -355,20 +355,23 @@ class SlowFlightServer(FlightServerBase):
 class ErrorFlightServer(FlightServerBase):
     """A Flight server that uses all the Flight-specific errors."""
 
-    errors = {
-        "internal": flight.FlightInternalError,
-        "timedout": flight.FlightTimedOutError,
-        "cancel": flight.FlightCancelledError,
-        "unauthenticated": flight.FlightUnauthenticatedError,
-        "unauthorized": flight.FlightUnauthorizedError,
-        "notimplemented": NotImplementedError,
-        "invalid": pa.ArrowInvalid,
-        "key": KeyError,
-    }
+    @staticmethod
+    def error_cases():
+        return {
+            "internal": flight.FlightInternalError,
+            "timedout": flight.FlightTimedOutError,
+            "cancel": flight.FlightCancelledError,
+            "unauthenticated": flight.FlightUnauthenticatedError,
+            "unauthorized": flight.FlightUnauthorizedError,
+            "notimplemented": NotImplementedError,
+            "invalid": pa.ArrowInvalid,
+            "key": KeyError,
+        }
 
     def do_action(self, context, action):
-        if action.type in self.errors:
-            raise self.errors[action.type]("foo")
+        error_cases = ErrorFlightServer.error_cases()
+        if action.type in error_cases:
+            raise error_cases[action.type]("foo")
         elif action.type == "protobuf":
             err_msg = b'this is an error message'
             raise flight.FlightUnauthorizedError("foo", err_msg)
@@ -1564,7 +1567,7 @@ def test_roundtrip_errors():
     with ErrorFlightServer() as server, \
             FlightClient(('localhost', server.port)) as client:
 
-        for arg, exc_type in ErrorFlightServer.errors.items():
+        for arg, exc_type in ErrorFlightServer.error_cases().items():
             with pytest.raises(exc_type, match=".*foo.*"):
                 list(client.do_action(flight.Action(arg, b"")))
         with pytest.raises(flight.FlightInternalError, match=".*foo.*"):

Reply via email to