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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
import os
import sys
import unittest
if not sys.platform.startswith("win"):
class Test_trigger(unittest.TestCase):
def _makeOne(self, map):
from waitress.trigger import trigger
self.inst = trigger(map)
return self.inst
def tearDown(self):
self.inst.close() # prevent __del__ warning from file_dispatcher
def test__close(self):
map = {}
inst = self._makeOne(map)
fd1, fd2 = inst._fds
inst.close()
self.assertRaises(OSError, os.read, fd1, 1)
self.assertRaises(OSError, os.read, fd2, 1)
def test__physical_pull(self):
map = {}
inst = self._makeOne(map)
inst._physical_pull()
r = os.read(inst._fds[0], 1)
self.assertEqual(r, b"x")
def test_readable(self):
map = {}
inst = self._makeOne(map)
self.assertEqual(inst.readable(), True)
def test_writable(self):
map = {}
inst = self._makeOne(map)
self.assertEqual(inst.writable(), False)
def test_handle_connect(self):
map = {}
inst = self._makeOne(map)
self.assertEqual(inst.handle_connect(), None)
def test_close(self):
map = {}
inst = self._makeOne(map)
self.assertEqual(inst.close(), None)
self.assertEqual(inst._closed, True)
def test_handle_close(self):
map = {}
inst = self._makeOne(map)
self.assertEqual(inst.handle_close(), None)
self.assertEqual(inst._closed, True)
def test_pull_trigger_nothunk(self):
map = {}
inst = self._makeOne(map)
self.assertEqual(inst.pull_trigger(), None)
r = os.read(inst._fds[0], 1)
self.assertEqual(r, b"x")
def test_pull_trigger_thunk(self):
map = {}
inst = self._makeOne(map)
self.assertEqual(inst.pull_trigger(True), None)
self.assertEqual(len(inst.thunks), 1)
r = os.read(inst._fds[0], 1)
self.assertEqual(r, b"x")
def test_handle_read_socket_error(self):
map = {}
inst = self._makeOne(map)
result = inst.handle_read()
self.assertEqual(result, None)
def test_handle_read_no_socket_error(self):
map = {}
inst = self._makeOne(map)
inst.pull_trigger()
result = inst.handle_read()
self.assertEqual(result, None)
def test_handle_read_thunk(self):
map = {}
inst = self._makeOne(map)
inst.pull_trigger()
L = []
inst.thunks = [lambda: L.append(True)]
result = inst.handle_read()
self.assertEqual(result, None)
self.assertEqual(L, [True])
self.assertEqual(inst.thunks, [])
def test_handle_read_thunk_error(self):
map = {}
inst = self._makeOne(map)
def errorthunk():
raise ValueError
inst.pull_trigger(errorthunk)
L = []
inst.log_info = lambda *arg: L.append(arg)
result = inst.handle_read()
self.assertEqual(result, None)
self.assertEqual(len(L), 1)
self.assertEqual(inst.thunks, [])
|