MCPcopy
hub / github.com/benoitc/gunicorn / FakeSocket

Class FakeSocket

tests/test_gthread.py:23–57  ·  view source on GitHub ↗

Mock socket for testing.

Source from the content-addressed store, hash-verified

21
22
23class FakeSocket:
24 """Mock socket for testing."""
25
26 def __init__(self, data=b''):
27 self.data = data
28 self.closed = False
29 self.blocking = True
30 self._fileno = id(self) % 65536
31
32 def fileno(self):
33 return self._fileno
34
35 def setblocking(self, blocking):
36 self.blocking = blocking
37
38 def recv(self, size):
39 if self.closed:
40 raise OSError(errno.EBADF, "Bad file descriptor")
41 result = self.data[:size]
42 self.data = self.data[size:]
43 return result
44
45 def send(self, data):
46 if self.closed:
47 raise OSError(errno.EPIPE, "Broken pipe")
48 return len(data)
49
50 def close(self):
51 self.closed = True
52
53 def getsockname(self):
54 return ('127.0.0.1', 8000)
55
56 def getpeername(self):
57 return ('127.0.0.1', 12345)
58
59
60class TestTConn:

Calls

no outgoing calls