File: fixtures.py

package info (click to toggle)
pydle 0.9.4-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 456 kB
  • sloc: python: 3,037; makefile: 3
file content (29 lines) | stat: -rw-r--r-- 894 bytes parent folder | download | duplicates (2)
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
import pydle
from .mocks import MockServer, MockClient, MockEventLoop


def with_client(*features, connected=True, **options):
    if not features:
        features = (pydle.client.BasicClient,)
    if features not in with_client.classes:
        with_client.classes[features] = pydle.featurize(MockClient, *features)

    def inner(f):
        def run():
            server = MockServer()
            client = with_client.classes[features]('TestcaseRunner', mock_server=server, **options)
            if connected:
                client.connect('mock://local', 1337, eventloop=MockEventLoop())

            try:
                ret = f(client=client, server=server)
                return ret
            finally:
                if client.eventloop:
                    client.eventloop.stop()

        run.__name__ = f.__name__
        return run
    return inner

with_client.classes = {}