<s> from test import CollectorTestCase <EOL> from test import get_collector_config <EOL> from mock import patch <EOL> from diamond . collector import Collector <EOL> from lmsensors import LMSensorsCollector <EOL> class FeatureMock : <EOL> def __init__ ( self , label , value = None ) : <EOL> self . label = label <EOL> self . value = value <EOL> def get_value ( self ) : <EOL> if self . value is not None : <EOL> return self . value <EOL> raise Exception ( "<STR_LIT>" ) <EOL> class ChipMock : <EOL> def __init__ ( self , label , features ) : <EOL> self . label = label <EOL> self . features = features <EOL> def __iter__ ( self ) : <EOL> for feature in self . features : <EOL> yield feature <EOL> def __str__ ( self ) : <EOL> return self . label <EOL> class TestLMSensorsCollector ( CollectorTestCase ) : <EOL> def setUp ( self ) : <EOL> config = get_collector_config ( '<STR_LIT>' , { } ) <EOL> self . collector = LMSensorsCollector ( config , None ) <EOL> def test_import ( self ) : <EOL> self . assertTrue ( LMSensorsCollector ) <EOL> @ patch . object ( Collector , '<STR_LIT>' ) <EOL> def test_simple_sensor ( self , publish_mock ) : <EOL> feature = FeatureMock ( '<STR_LIT>' , <NUM_LIT:10> ) <EOL> chip = ChipMock ( "<STR_LIT>" , [ feature ] ) <EOL> patch_detected_chips_iter = patch ( '<STR_LIT>' , <EOL> return_value = [ chip ] ) <EOL> patch_detected_chips_iter . start ( ) <EOL> self . collector . collect ( ) <EOL> patch_detected_chips_iter . stop ( ) <EOL> self . assertPublished ( publish_mock , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> @ patch . object ( Collector , '<STR_LIT>' ) <EOL> def test_empty_sensor ( self , publish_mock ) : <EOL> feature = FeatureMock ( '<STR_LIT>' ) <EOL> chip = ChipMock ( '<STR_LIT>' , [ feature ] ) <EOL> patch_detected_chips_iter = patch ( '<STR_LIT>' , <EOL> return_value = [ chip ] ) <EOL> patch_detected_chips_iter . start ( ) <EOL> self . collector . collect ( ) <EOL> patch_detected_chips_iter . stop ( ) <EOL> self . assertUnpublished ( publish_mock , '<STR_LIT>' , None ) <EOL> @ patch . object ( Collector , '<STR_LIT>' ) <EOL> def test_empty_zero_sensor ( self , publish_mock ) : <EOL> self . collector . config [ '<STR_LIT>' ] = True <EOL> feature = FeatureMock ( '<STR_LIT>' ) <EOL> chip = ChipMock ( '<STR_LIT>' , [ feature ] ) <EOL> patch_detected_chips_iter = patch ( '<STR_LIT>' , <EOL> return_value = [ chip ] ) <EOL> patch_detected_chips_iter . start ( ) <EOL> self . collector . collect ( ) <EOL> patch_detected_chips_iter . stop ( ) <EOL> self . assertPublished ( publish_mock , '<STR_LIT>' , <NUM_LIT:0> ) </s>
