Exemple #1
0
def main() -> None:
    def shutdown(sig: int, frame_type: FrameType | None) -> None:
        if conn.websocket is not None and conn.loop is not None:
            for task in asyncio.all_tasks(conn.loop):
                task.cancel()
            coro = conn.websocket.close()
            asyncio.run_coroutine_threadsafe(coro, conn.loop)

    env = Env()
    env.read_env()

    host = env.str("SHOWDOWN_HOST")
    port = env.int("SHOWDOWN_PORT")
    protocol = "wss" if port == 443 else "ws"
    url = f"{protocol}://{host}:{port}/showdown/websocket"

    conn = Connection(
        url=url,
        username=env.str("USERNAME"),
        password=env.str("PASSWORD"),
        avatar=env.str("AVATAR", default=""),
        statustext=env.str("STATUSTEXT", default=""),
        rooms=env.list("ROOMS", default=[]),
        main_room=env.str("MAIN_ROOM"),
        command_character=env.str("COMMAND_CHARACTER"),
        administrators=env.list("ADMINISTRATORS", default=[]),
        webhooks=env.json("WEBHOOKS", default={}),
    )

    signal.signal(signal.SIGINT, shutdown)

    conn.open_connection()
Exemple #2
0
def test_read_env(env: Env):
    assert env.read_env("./tests/.env.test")
    assert env.str("A_STRING") == "blabla"
Exemple #3
0
def test_read_env__not_found(env: Env):
    assert not env.read_env("this-path-should-not-exist.test")
Exemple #4
0
from cerbottana.database import Database
from cerbottana.models.room import Room
from cerbottana.tasks.veekun import csv_to_sqlite

# pylint: disable=protected-access, redefined-outer-name


def pytest_collection_modifyitems(items):
    for item in items:
        # Mark tests using a real showdown instance with `pytest.mark.real_ps_instance`
        if "showdown_connection" in item.fixturenames:
            item.add_marker(pytest.mark.real_ps_instance)


env = Env()
env.read_env()


database_metadata: dict[str, Any] = {
    "database": d.Base.metadata,
}


class ControlMessage(bytes, Enum):
    # server to client
    PROCESS_MESSAGES = b"process_messages"
    PROCESS_AND_REPLY = b"process_and_reply"

    # client to server
    PROCESSING_DONE = b"processing_done"