File size: 1,894 Bytes
02eac4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import asyncio

import pytest
import pytest_asyncio
from lerobot_arena_client import RoboticsConsumer, RoboticsProducer

# Default server URL for tests
TEST_SERVER_URL = "http://localhost:8000"


@pytest.fixture(scope="session")
def event_loop():
    """Create an instance of the default event loop for the test session."""
    loop = asyncio.get_event_loop_policy().new_event_loop()
    yield loop
    loop.close()


@pytest_asyncio.fixture
async def producer():
    """Create a RoboticsProducer instance for testing."""
    client = RoboticsProducer(TEST_SERVER_URL)
    yield client
    if client.is_connected():
        await client.disconnect()


@pytest_asyncio.fixture
async def consumer():
    """Create a RoboticsConsumer instance for testing."""
    client = RoboticsConsumer(TEST_SERVER_URL)
    yield client
    if client.is_connected():
        await client.disconnect()


@pytest_asyncio.fixture
async def test_room(producer):
    """Create a test room and clean up after test."""
    room_id = await producer.create_room()
    yield room_id
    # Cleanup: delete the room after test
    try:
        await producer.delete_room(room_id)
    except Exception:
        pass  # Room might already be deleted


@pytest_asyncio.fixture
async def connected_producer(producer, test_room):
    """Create a connected producer in a test room."""
    await producer.connect(test_room)
    yield producer, test_room


@pytest_asyncio.fixture
async def connected_consumer(consumer, test_room):
    """Create a connected consumer in a test room."""
    await consumer.connect(test_room)
    yield consumer, test_room


@pytest_asyncio.fixture
async def producer_consumer_pair(producer, consumer, test_room):
    """Create a connected producer-consumer pair in the same room."""
    await producer.connect(test_room)
    await consumer.connect(test_room)
    yield producer, consumer, test_room