<s> from test import CollectorTestCase <EOL> from test import get_collector_config <EOL> from test import unittest <EOL> from mock import Mock <EOL> from mock import patch <EOL> from diamond . collector import Collector <EOL> from postfix import PostfixCollector <EOL> class TestYelpPostfixCollector ( CollectorTestCase ) : <EOL> def setUp ( self ) : <EOL> config = get_collector_config ( '<STR_LIT>' , { <EOL> '<STR_LIT:host>' : '<STR_LIT:localhost>' , <EOL> '<STR_LIT:port>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True , <EOL> } ) <EOL> self . collector = PostfixCollector ( config , None ) <EOL> def test_import ( self ) : <EOL> self . assertTrue ( PostfixCollector ) <EOL> @ patch . object ( Collector , '<STR_LIT>' ) <EOL> def test_should_work_with_synthetic_data ( self , publish_mock ) : <EOL> first_resp = self . getFixture ( '<STR_LIT>' ) . getvalue ( ) <EOL> patch_collector = patch . object ( <EOL> PostfixCollector , <EOL> '<STR_LIT>' , <EOL> Mock ( return_value = first_resp ) ) <EOL> patch_collector . start ( ) <EOL> self . collector . collect ( ) <EOL> patch_collector . stop ( ) <EOL> self . assertPublishedMany ( publish_mock , { } ) <EOL> second_resp = self . getFixture ( '<STR_LIT>' ) . getvalue ( ) <EOL> patch_collector = patch . object ( PostfixCollector , <EOL> '<STR_LIT>' , <EOL> Mock ( return_value = second_resp ) ) <EOL> patch_collector . start ( ) <EOL> self . collector . collect ( ) <EOL> patch_collector . stop ( ) <EOL> metrics = { <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> } <EOL> self . assertPublishedMany ( publish_mock , metrics ) <EOL> self . setDocExample ( collector = self . collector . __class__ . __name__ , <EOL> metrics = metrics , <EOL> defaultpath = self . collector . config [ '<STR_LIT:path>' ] ) <EOL> @ patch . object ( Collector , '<STR_LIT>' ) <EOL> def test_should_export_queue_metrics ( self , publish_mock ) : <EOL> first_resp = self . getFixture ( '<STR_LIT>' ) . getvalue ( ) <EOL> patch_collector = patch . object ( <EOL> PostfixCollector , <EOL> '<STR_LIT>' , <EOL> Mock ( return_value = first_resp ) ) <EOL> with patch_collector : <EOL> self . collector . config [ '<STR_LIT>' ] = True <EOL> self . collector . collect ( ) <EOL> self . collector . config [ '<STR_LIT>' ] = False <EOL> metrics = [ <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:10> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:20> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) <EOL> ] <EOL> for expected_metric in metrics : <EOL> k , v = expected_metric <EOL> message = "<STR_LIT>" . format ( k , v ) <EOL> self . assertTrue ( self . check_for_call ( publish_mock , k , v ) , message ) <EOL> def check_for_call ( self , mock , key , value ) : <EOL> call_found = False <EOL> for call in mock . call_args_list : <EOL> if call [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] == key and call [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] == value : <EOL> call_found = True <EOL> return call_found <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
