<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 ntpd import NtpdCollector <EOL> class TestNtpdCollector ( CollectorTestCase ) : <EOL> def setUp ( self ) : <EOL> config = get_collector_config ( '<STR_LIT>' , { } ) <EOL> self . collector = NtpdCollector ( config , None ) <EOL> def test_import ( self ) : <EOL> self . assertTrue ( NtpdCollector ) <EOL> @ patch . object ( Collector , '<STR_LIT>' ) <EOL> def test_should_work_wtih_real_data ( self , publish_mock ) : <EOL> ntpq_data = Mock ( <EOL> return_value = self . getFixture ( '<STR_LIT>' ) . getvalue ( ) ) <EOL> ntpdc_kerninfo_data = Mock ( <EOL> return_value = self . getFixture ( '<STR_LIT>' ) . getvalue ( ) ) <EOL> ntpdc_sysinfo_data = Mock ( <EOL> return_value = self . getFixture ( '<STR_LIT>' ) . getvalue ( ) ) <EOL> collector_mock = patch . multiple ( <EOL> NtpdCollector , <EOL> get_ntpq_output = ntpq_data , <EOL> get_ntpdc_kerninfo_output = ntpdc_kerninfo_data , <EOL> get_ntpdc_sysinfo_output = ntpdc_sysinfo_data ) <EOL> collector_mock . start ( ) <EOL> self . collector . collect ( ) <EOL> collector_mock . stop ( ) <EOL> metrics = { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : - <NUM_LIT> , <EOL> '<STR_LIT>' : - <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> <EOL> } <EOL> self . setDocExample ( collector = self . collector . __class__ . __name__ , <EOL> metrics = metrics , <EOL> defaultpath = self . collector . config [ '<STR_LIT:path>' ] ) <EOL> self . assertPublishedMany ( publish_mock , metrics ) <EOL> @ patch . object ( Collector , '<STR_LIT>' ) <EOL> def test_should_fail_gracefully ( self , publish_mock ) : <EOL> ntpq_data = Mock ( return_value = '<STR_LIT>' ) <EOL> ntpdc_kerninfo_data = Mock ( return_value = '<STR_LIT>' ) <EOL> ntpdc_sysinfo_data = Mock ( return_value = '<STR_LIT>' ) <EOL> collector_mock = patch . multiple ( <EOL> NtpdCollector , <EOL> get_ntpq_output = ntpq_data , <EOL> get_ntpdc_kerninfo_output = ntpdc_kerninfo_data , <EOL> get_ntpdc_sysinfo_output = ntpdc_sysinfo_data ) <EOL> collector_mock . start ( ) <EOL> self . collector . collect ( ) <EOL> collector_mock . stop ( ) <EOL> self . assertPublishedMany ( publish_mock , { } ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
