forked from wolph/python-statsd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_counter.py
More file actions
49 lines (35 loc) · 1.74 KB
/
test_counter.py
File metadata and controls
49 lines (35 loc) · 1.74 KB
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
from __future__ import with_statement
from unittest import TestCase
import mock
import statsd
class TestCounter(TestCase):
def setUp(self):
self.counter = statsd.Counter('testing')
def test_increment(self):
with mock.patch('statsd.Client') as mock_client:
self.counter.increment('')
mock_client._send.assert_called_with(mock.ANY, {'testing': '1|c'})
self.counter.increment('', 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.increment('testing', 4)
mock_client._send.assert_called_with(mock.ANY, {'testing': '4|c'})
statsd.increment('testing')
mock_client._send.assert_called_with(mock.ANY, {'testing': '1|c'})
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_with_an_int(self):
with mock.patch('statsd.Client') as mock_client:
self.counter.decrement('', 2)
mock_client._send.assert_called_with(mock.ANY, {'testing': '-2|c'})