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

Class MockSocket

tests/test_statsd.py:22–51  ·  view source on GitHub ↗

Pretend to be a UDP socket

Source from the content-addressed store, hash-verified

20
21
22class MockSocket:
23 "Pretend to be a UDP socket"
24 def __init__(self, failp):
25 self.failp = failp
26 self.msgs = [] # accumulate messages for later inspection
27
28 def send(self, msg):
29 if self.failp:
30 raise StatsdTestException("Should not interrupt the logger")
31
32 sock_dir = tempfile.mkdtemp()
33 sock_file = os.path.join(sock_dir, "test.sock")
34
35 server = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
36 client = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
37
38 try:
39 server.bind(sock_file)
40 client.connect(sock_file)
41
42 client.send(msg)
43 self.msgs.append(server.recv(1024))
44
45 finally:
46 client.close()
47 server.close()
48 shutil.rmtree(sock_dir)
49
50 def reset(self):
51 self.msgs = []
52
53
54def test_statsd_fail():

Callers 7

test_statsd_failFunction · 0.70
test_dogstatsd_tagsFunction · 0.70
test_instrumentFunction · 0.70
test_prefixFunction · 0.70
test_prefix_no_dotFunction · 0.70
test_prefix_nestedFunction · 0.70

Calls

no outgoing calls

Tested by 7

test_statsd_failFunction · 0.56
test_dogstatsd_tagsFunction · 0.56
test_instrumentFunction · 0.56
test_prefixFunction · 0.56
test_prefix_no_dotFunction · 0.56
test_prefix_nestedFunction · 0.56