You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "HyukjinKwon (via GitHub)" <gi...@apache.org> on 2023/02/17 01:46:01 UTC
[GitHub] [spark] HyukjinKwon commented on a diff in pull request #40054: pyspark: accept user_agent in spark connect's connection string
HyukjinKwon commented on code in PR #40054:
URL: https://github.com/apache/spark/pull/40054#discussion_r1109190403
##########
python/pyspark/sql/tests/connect/test_client.py:
##########
@@ -0,0 +1,50 @@
+import unittest
+
+from pyspark.sql.connect.client import SparkConnectClient
+import pyspark.sql.connect.proto as proto
+
+
+class SparkConnectClientTestCase(unittest.TestCase):
+ def test_user_agent_passthrough(self):
+ client = SparkConnectClient('sc://foo/;user_agent=bar')
+ mock = MockService(client._session_id)
+ client._stub = mock
+
+ command = proto.Command()
+ client.execute_command(command)
+
+ self.assertIsNotNone(mock.req, "ExecutePlan API was not called when expected")
+ self.assertEqual(mock.req.client_type, "bar")
+
+ def test_user_agent_default(self):
+ client = SparkConnectClient('sc://foo/')
+ mock = MockService(client._session_id)
+ client._stub = mock
+
+ command = proto.Command()
+ client.execute_command(command)
+
+ self.assertIsNotNone(mock.req, "ExecutePlan API was not called when expected")
+ self.assertEqual(mock.req.client_type, "_SPARK_CONNECT_PYTHON")
+
+
+class MockService:
+ """
+ Simplest mock of the SparkConnectService.
+ If this needs more complex logic, it needs to be replaced with Python mocking.
+ """
+ req: proto.ExecutePlanRequest | None
Review Comment:
we don't need type hints in tests
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org