@@ -13,13 +13,14 @@ class TestQueryFunction:
1313
1414 def test_query_single_prompt (self ):
1515 """Test query with a single prompt."""
16+
1617 async def _test ():
17- with patch ('claude_code_sdk._internal.client.InternalClient.process_query' ) as mock_process :
18+ with patch (
19+ "claude_code_sdk._internal.client.InternalClient.process_query"
20+ ) as mock_process :
1821 # Mock the async generator
1922 async def mock_generator ():
20- yield AssistantMessage (
21- content = [TextBlock (text = "4" )]
22- )
23+ yield AssistantMessage (content = [TextBlock (text = "4" )])
2324
2425 mock_process .return_value = mock_generator ()
2526
@@ -35,41 +36,43 @@ async def mock_generator():
3536
3637 def test_query_with_options (self ):
3738 """Test query with various options."""
39+
3840 async def _test ():
39- with patch ('claude_code_sdk._internal.client.InternalClient.process_query' ) as mock_process :
41+ with patch (
42+ "claude_code_sdk._internal.client.InternalClient.process_query"
43+ ) as mock_process :
44+
4045 async def mock_generator ():
41- yield AssistantMessage (
42- content = [TextBlock (text = "Hello!" )]
43- )
46+ yield AssistantMessage (content = [TextBlock (text = "Hello!" )])
4447
4548 mock_process .return_value = mock_generator ()
4649
4750 options = ClaudeCodeOptions (
4851 allowed_tools = ["Read" , "Write" ],
4952 system_prompt = "You are helpful" ,
5053 permission_mode = "acceptEdits" ,
51- max_turns = 5
54+ max_turns = 5 ,
5255 )
5356
5457 messages = []
55- async for msg in query (
56- prompt = "Hi" ,
57- options = options
58- ):
58+ async for msg in query (prompt = "Hi" , options = options ):
5959 messages .append (msg )
6060
6161 # Verify process_query was called with correct prompt and options
6262 mock_process .assert_called_once ()
6363 call_args = mock_process .call_args
64- assert call_args [1 ][' prompt' ] == "Hi"
65- assert call_args [1 ][' options' ] == options
64+ assert call_args [1 ][" prompt" ] == "Hi"
65+ assert call_args [1 ][" options" ] == options
6666
6767 anyio .run (_test )
6868
6969 def test_query_with_cwd (self ):
7070 """Test query with custom working directory."""
71+
7172 async def _test ():
72- with patch ('claude_code_sdk._internal.client.SubprocessCLITransport' ) as mock_transport_class :
73+ with patch (
74+ "claude_code_sdk._internal.client.SubprocessCLITransport"
75+ ) as mock_transport_class :
7376 mock_transport = AsyncMock ()
7477 mock_transport_class .return_value = mock_transport
7578
@@ -79,8 +82,8 @@ async def mock_receive():
7982 "type" : "assistant" ,
8083 "message" : {
8184 "role" : "assistant" ,
82- "content" : [{"type" : "text" , "text" : "Done" }]
83- }
85+ "content" : [{"type" : "text" , "text" : "Done" }],
86+ },
8487 }
8588 yield {
8689 "type" : "result" ,
@@ -91,7 +94,7 @@ async def mock_receive():
9194 "is_error" : False ,
9295 "num_turns" : 1 ,
9396 "session_id" : "test-session" ,
94- "total_cost" : 0.001
97+ "total_cost" : 0.001 ,
9598 }
9699
97100 mock_transport .receive_messages = mock_receive
@@ -100,16 +103,13 @@ async def mock_receive():
100103
101104 options = ClaudeCodeOptions (cwd = "/custom/path" )
102105 messages = []
103- async for msg in query (
104- prompt = "test" ,
105- options = options
106- ):
106+ async for msg in query (prompt = "test" , options = options ):
107107 messages .append (msg )
108108
109109 # Verify transport was created with correct parameters
110110 mock_transport_class .assert_called_once ()
111111 call_kwargs = mock_transport_class .call_args .kwargs
112- assert call_kwargs [' prompt' ] == "test"
113- assert call_kwargs [' options' ].cwd == "/custom/path"
112+ assert call_kwargs [" prompt" ] == "test"
113+ assert call_kwargs [" options" ].cwd == "/custom/path"
114114
115115 anyio .run (_test )
0 commit comments