<s> from twisted . trial . unittest import TestCase <EOL> from twisted . internet . task import Clock <EOL> from txstatsd . report import ReportingService <EOL> class TestReportingService ( TestCase ) : <EOL> def test_start_stop_with_no_tasks ( self ) : <EOL> """<STR_LIT>""" <EOL> service = ReportingService ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( service . tasks ) ) <EOL> service . startService ( ) <EOL> self . assertTrue ( service . running ) <EOL> service . stopService ( ) <EOL> self . assertFalse ( service . running ) <EOL> def test_schedule_with_report_function ( self ) : <EOL> """<STR_LIT>""" <EOL> clock = Clock ( ) <EOL> service = ReportingService ( clock = clock ) <EOL> def foo ( ) : <EOL> return { "<STR_LIT:foo>" : <NUM_LIT:1> } <EOL> called = [ ] <EOL> def report ( name , value ) : <EOL> called . append ( ( name , value ) ) <EOL> service . schedule ( foo , <NUM_LIT:1> , report ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( service . tasks ) ) <EOL> service . startService ( ) <EOL> clock . advance ( <NUM_LIT:1> ) <EOL> self . assertEquals ( [ ( "<STR_LIT:foo>" , <NUM_LIT:1> ) ] , called ) <EOL> def test_schedule_without_report_function ( self ) : <EOL> """<STR_LIT>""" <EOL> clock = Clock ( ) <EOL> service = ReportingService ( clock = clock ) <EOL> called = [ ] <EOL> def foo ( ) : <EOL> called . append ( ( "<STR_LIT:foo>" , <NUM_LIT:1> ) ) <EOL> service . schedule ( foo , <NUM_LIT:1> , None ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( service . tasks ) ) <EOL> service . startService ( ) <EOL> clock . advance ( <NUM_LIT:1> ) <EOL> self . assertEquals ( [ ( "<STR_LIT:foo>" , <NUM_LIT:1> ) ] , called ) <EOL> def test_schedule_when_running ( self ) : <EOL> """<STR_LIT>""" <EOL> clock = Clock ( ) <EOL> service = ReportingService ( clock = clock ) <EOL> service . startService ( ) <EOL> called = [ ] <EOL> def foo ( ) : <EOL> called . append ( ( "<STR_LIT:foo>" , <NUM_LIT:1> ) ) <EOL> service . schedule ( foo , <NUM_LIT:1> , None ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( service . tasks ) ) <EOL> self . assertEquals ( [ ( "<STR_LIT:foo>" , <NUM_LIT:1> ) ] , called ) <EOL> def test_report_with_instance_name ( self ) : <EOL> """<STR_LIT>""" <EOL> clock = Clock ( ) <EOL> service = ReportingService ( instance_name = "<STR_LIT>" , clock = clock ) <EOL> def foo ( ) : <EOL> return { "<STR_LIT:foo>" : <NUM_LIT:1> } <EOL> called = [ ] <EOL> def report ( name , value ) : <EOL> called . append ( ( name , value ) ) <EOL> service . schedule ( foo , <NUM_LIT:1> , report ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( service . tasks ) ) <EOL> service . startService ( ) <EOL> clock . advance ( <NUM_LIT:1> ) <EOL> self . assertEquals ( [ ( "<STR_LIT>" , <NUM_LIT:1> ) ] , called ) </s>
