def test_exception_in_send(self): def mock_sendto_raise_error(data, addr): mock_sendto_raise_error.exception_raised = True raise socket.gaierror statsd._statsd._socket.sendto = mock_sendto_raise_error statsd.decrement('counted') self.assertTrue(mock_sendto_raise_error.exception_raised)
def test_decrement(self): with mock.patch('statsd.Client') as mock_client: self.counter.decrement('') mock_client._send.assert_called_with(mock.ANY, {'testing': '-1|c'}) self.counter.decrement('', 2) mock_client._send.assert_called_with(mock.ANY, {'testing': '-2|c'}) self.counter -= 3 mock_client._send.assert_called_with(mock.ANY, {'testing': '-3|c'}) statsd.decrement('testing', 4) mock_client._send.assert_called_with(mock.ANY, {'testing': '-4|c'}) statsd.decrement('testing') mock_client._send.assert_called_with(mock.ANY, {'testing': '-1|c'})
def test_decrement(self): statsd.decrement('counted') self.assertEqual(statsd._statsd._socket.data, b'counted:-1|c') statsd.decrement('counted', 5) self.assertEqual(statsd._statsd._socket.data, b'counted:-5|c') statsd.decrement('counted', 5, 0.99) self.assertTrue(statsd._statsd._socket.data.startswith(b'counted:-5|c')) if statsd._statsd._socket.data != b'counted:-5|c': self.assertTrue(statsd._statsd._socket.data.endswith(b'|@0.99'))