summaryrefslogtreecommitdiff
path: root/tests/test_init.py
blob: c824c21fa303ef3f5e036d5f1e623c58265905ea (plain)
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
import unittest


class Test_serve(unittest.TestCase):
    def _callFUT(self, app, **kw):
        from waitress import serve

        return serve(app, **kw)

    def test_it(self):
        server = DummyServerFactory()
        app = object()
        result = self._callFUT(app, _server=server, _quiet=True)
        self.assertEqual(server.app, app)
        self.assertEqual(result, None)
        self.assertEqual(server.ran, True)


class Test_serve_paste(unittest.TestCase):
    def _callFUT(self, app, **kw):
        from waitress import serve_paste

        return serve_paste(app, None, **kw)

    def test_it(self):
        server = DummyServerFactory()
        app = object()
        result = self._callFUT(app, _server=server, _quiet=True)
        self.assertEqual(server.app, app)
        self.assertEqual(result, 0)
        self.assertEqual(server.ran, True)


class DummyServerFactory:
    ran = False

    def __call__(self, app, **kw):
        self.adj = DummyAdj(kw)
        self.app = app
        self.kw = kw
        return self

    def run(self):
        self.ran = True


class DummyAdj:
    verbose = False

    def __init__(self, kw):
        self.__dict__.update(kw)