<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> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> from diamond . collector import Collector <EOL> from soft import SoftInterruptCollector <EOL> class TestSoftInterruptCollector ( CollectorTestCase ) : <EOL> def setUp ( self ) : <EOL> config = get_collector_config ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> <EOL> } ) <EOL> self . collector = SoftInterruptCollector ( config , None ) <EOL> def test_import ( self ) : <EOL> self . assertTrue ( SoftInterruptCollector ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' , Mock ( return_value = True ) ) <EOL> @ patch . object ( Collector , '<STR_LIT>' ) <EOL> def test_should_open_proc_stat ( self , publish_mock , open_mock ) : <EOL> open_mock . return_value = StringIO ( '<STR_LIT>' ) <EOL> self . collector . collect ( ) <EOL> open_mock . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT:r>' ) <EOL> @ patch . object ( Collector , '<STR_LIT>' ) <EOL> def test_should_work_with_synthetic_data ( self , publish_mock ) : <EOL> patch_open = patch ( '<STR_LIT>' , Mock ( return_value = StringIO ( <EOL> '<STR_LIT>' <EOL> ) ) ) <EOL> patch_open . start ( ) <EOL> self . collector . collect ( ) <EOL> patch_open . stop ( ) <EOL> self . assertPublishedMany ( publish_mock , { } ) <EOL> patch_open = patch ( '<STR_LIT>' , Mock ( return_value = StringIO ( <EOL> '<STR_LIT>' <EOL> ) ) ) <EOL> patch_open . start ( ) <EOL> self . collector . collect ( ) <EOL> patch_open . stop ( ) <EOL> self . assertPublishedMany ( publish_mock , { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT:0>' : <NUM_LIT:1> , <EOL> '<STR_LIT:1>' : <NUM_LIT:2> , <EOL> '<STR_LIT:2>' : <NUM_LIT:3> , <EOL> '<STR_LIT:3>' : <NUM_LIT:4> , <EOL> '<STR_LIT:4>' : <NUM_LIT:5> , <EOL> '<STR_LIT:5>' : <NUM_LIT:6> , <EOL> '<STR_LIT>' : <NUM_LIT:7> , <EOL> '<STR_LIT>' : <NUM_LIT:8> , <EOL> '<STR_LIT>' : <NUM_LIT:9> , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> } ) <EOL> @ patch . object ( Collector , '<STR_LIT>' ) <EOL> def test_should_work_with_real_data ( self , publish_mock ) : <EOL> SoftInterruptCollector . PROC = self . getFixturePath ( '<STR_LIT>' ) <EOL> self . collector . collect ( ) <EOL> self . assertPublishedMany ( publish_mock , { } ) <EOL> SoftInterruptCollector . PROC = self . getFixturePath ( '<STR_LIT>' ) <EOL> self . collector . collect ( ) <EOL> metrics = { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT:0>' : <NUM_LIT:0> , <EOL> '<STR_LIT:1>' : <NUM_LIT> , <EOL> '<STR_LIT:2>' : <NUM_LIT:2> , <EOL> '<STR_LIT:3>' : <NUM_LIT> , <EOL> '<STR_LIT:4>' : <NUM_LIT> , <EOL> '<STR_LIT:5>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <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> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
