<s> import unittest <EOL> from pyramid import testing <EOL> class TestStatsdHelper ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . config = testing . setUp ( ) <EOL> def tearDown ( self ) : <EOL> testing . tearDown ( ) <EOL> def _makeOne ( self ) : <EOL> from . . import StatsdHelper <EOL> return StatsdHelper ( ) <EOL> def test_get_client_with_registry ( self ) : <EOL> registry = { '<STR_LIT>' : True } <EOL> inst = self . _makeOne ( ) <EOL> self . assertEqual ( inst . get_client ( registry ) , True ) <EOL> def test_get_client_with_no_registry ( self ) : <EOL> self . config . registry [ '<STR_LIT>' ] = True <EOL> inst = self . _makeOne ( ) <EOL> self . assertEqual ( inst . get_client ( ) , True ) <EOL> def test_timer_no_client ( self ) : <EOL> self . config . registry [ '<STR_LIT>' ] = None <EOL> inst = self . _makeOne ( ) <EOL> timer = inst . timer ( '<STR_LIT>' ) <EOL> with timer as t : <EOL> self . assertEqual ( t , None ) <EOL> def test_timer_with_client ( self ) : <EOL> client = DummyClient ( True ) <EOL> self . config . registry [ '<STR_LIT>' ] = client <EOL> inst = self . _makeOne ( ) <EOL> timer = inst . timer ( '<STR_LIT>' , <NUM_LIT> ) <EOL> self . assertEqual ( timer , True ) <EOL> self . assertEqual ( client . timer_name , '<STR_LIT>' ) <EOL> self . assertEqual ( client . timer_rate , <NUM_LIT> ) <EOL> def test_gauge ( self ) : <EOL> client = DummyClient ( True ) <EOL> self . config . registry [ '<STR_LIT>' ] = client <EOL> inst = self . _makeOne ( ) <EOL> result = inst . gauge ( '<STR_LIT:name>' , '<STR_LIT:value>' ) <EOL> self . assertEqual ( result , True ) <EOL> self . assertEqual ( client . gauge_name , '<STR_LIT:name>' ) <EOL> self . assertEqual ( client . gauge_value , '<STR_LIT:value>' ) <EOL> self . assertEqual ( client . gauge_rate , <NUM_LIT:1> ) <EOL> def test_incr ( self ) : <EOL> client = DummyClient ( True ) <EOL> self . config . registry [ '<STR_LIT>' ] = client <EOL> inst = self . _makeOne ( ) <EOL> result = inst . incr ( '<STR_LIT:name>' , <NUM_LIT:5> ) <EOL> self . assertEqual ( result , True ) <EOL> self . assertEqual ( client . incr_name , '<STR_LIT:name>' ) <EOL> self . assertEqual ( client . incr_value , <NUM_LIT:5> ) <EOL> self . assertEqual ( client . incr_rate , <NUM_LIT:1> ) <EOL> class DummyClient ( object ) : <EOL> def __init__ ( self , result ) : <EOL> self . result = result <EOL> def timer ( self , timer_name , rate = <NUM_LIT:1> ) : <EOL> self . timer_name = timer_name <EOL> self . timer_rate = rate <EOL> return self . result <EOL> def gauge ( self , name , value , rate = <NUM_LIT:1> ) : <EOL> self . gauge_name = name <EOL> self . gauge_value = value <EOL> self . gauge_rate = rate <EOL> return self . result <EOL> def incr ( self , name , value = <NUM_LIT:1> , rate = <NUM_LIT:1> ) : <EOL> self . incr_name = name <EOL> self . incr_value = value <EOL> self . incr_rate = rate <EOL> return self . result </s>
