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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]