1 #!/usr/bin/python 2 3 import unittest 4 5 import statsd_mock as statsd 6 7 class statsd_mock_test(unittest.TestCase): 8 """Test statsd_mock""" 9 def test_average_mock(self): 10 """Test mock class Average""" 11 statsd.Average('average').send('name', 1) 12 13 14 def test_connection_mock(self): 15 """Test mock class Connection""" 16 connection = statsd.Connection(host='host', port=1) 17 statsd.Connection.set_defaults(host='host', port=1) 18 19 20 def test_counter_mock(self): 21 """Test mock class Counter""" 22 counter = statsd.Counter('counter') 23 counter.increment(subname='name', delta=1) 24 counter.decrement(subname='name', delta=1) 25 26 27 def test_gauge_mock(self): 28 """Test mock class Gauge""" 29 statsd.Gauge('gauge').send('name', 1) 30 31 32 def test_raw_mock(self): 33 """Test mock class Raw""" 34 statsd.Raw('raw').send(subname='name', value=1, timestamp=None) 35 36 37 def test_timer_mock(self): 38 """Test mock class Timer""" 39 timer = statsd.Timer('timer') 40 timer.start() 41 timer.stop() 42 43 class decorate_test(object): 44 """Test class to test timer decorator.""" 45 test_timer = statsd.Timer('test') 46 47 @test_timer.decorate 48 def f(self): 49 """Test function to apply timer decorator to.""" 50 return True 51 52 dt = decorate_test() 53 self.assertTrue(dt.f(), 'timer decorator failed.') 54 55 if __name__ == '__main__': 56 unittest.main() 57