1- """Shared test configuration and fixtures for BalatroBot API tests ."""
1+ """Lua API test-specific configuration and fixtures."""
22
33import json
44import socket
88
99# Connection settings
1010HOST = "127.0.0.1"
11- PORT : int = 12346 # default port for BalatroBot TCP API
1211TIMEOUT : float = 30.0 # timeout for socket operations in seconds
1312BUFFER_SIZE : int = 65536 # 64KB buffer for TCP messages
1413
1514
1615@pytest .fixture
17- def tcp_client () -> Generator [socket .socket , None , None ]:
16+ def tcp_client (port ) -> Generator [socket .socket , None , None ]:
1817 """Create and clean up a TCP client socket.
1918
2019 Yields:
@@ -24,21 +23,7 @@ def tcp_client() -> Generator[socket.socket, None, None]:
2423 sock .settimeout (TIMEOUT )
2524 # Set socket receive buffer size
2625 sock .setsockopt (socket .SOL_SOCKET , socket .SO_RCVBUF , BUFFER_SIZE )
27- sock .connect ((HOST , PORT ))
28- yield sock
29-
30-
31- @pytest .fixture
32- def udp_client () -> Generator [socket .socket , None , None ]:
33- """Create and clean up a TCP client socket (legacy support).
34-
35- Yields:
36- Configured TCP socket for testing.
37- """
38- with socket .socket (socket .AF_INET , socket .SOCK_DGRAM ) as sock :
39- sock .settimeout (TIMEOUT )
40- # Set socket receive buffer size
41- sock .setsockopt (socket .SOL_SOCKET , socket .SO_RCVBUF , BUFFER_SIZE )
26+ sock .connect ((HOST , port ))
4227 yield sock
4328
4429
@@ -51,10 +36,7 @@ def send_api_message(sock: socket.socket, name: str, arguments: dict) -> None:
5136 arguments: Arguments dictionary for the function.
5237 """
5338 message = {"name" : name , "arguments" : arguments }
54- if sock .type == socket .SOCK_STREAM :
55- sock .send (json .dumps (message ).encode () + b"\n " )
56- else :
57- sock .sendto (json .dumps (message ).encode (), (HOST , PORT ))
39+ sock .send (json .dumps (message ).encode () + b"\n " )
5840
5941
6042def receive_api_message (sock : socket .socket ) -> dict [str , Any ]:
@@ -66,12 +48,8 @@ def receive_api_message(sock: socket.socket) -> dict[str, Any]:
6648 Returns:
6749 Received message as a dictionary.
6850 """
69- if sock .type == socket .SOCK_STREAM :
70- data = sock .recv (BUFFER_SIZE )
71- return json .loads (data .decode ().strip ())
72- else :
73- data , _ = sock .recvfrom (BUFFER_SIZE )
74- return json .loads (data .decode ().strip ())
51+ data = sock .recv (BUFFER_SIZE )
52+ return json .loads (data .decode ().strip ())
7553
7654
7755def send_and_receive_api_message (
0 commit comments