<s> from test import CollectorTestCase <EOL> from test import get_collector_config <EOL> from mock import call , Mock , patch <EOL> from unittest import TestCase <EOL> from diamond . collector import Collector <EOL> from portstat import get_port_stats , PortStatCollector <EOL> class PortStatCollectorTestCase ( CollectorTestCase ) : <EOL> TEST_CONFIG = { <EOL> '<STR_LIT:port>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } <EOL> } <EOL> } <EOL> def setUp ( self ) : <EOL> config = get_collector_config ( '<STR_LIT>' , <EOL> self . TEST_CONFIG ) <EOL> self . collector = PortStatCollector ( config , None ) <EOL> def test_import ( self ) : <EOL> self . assertTrue ( PortStatCollector ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch . object ( Collector , '<STR_LIT>' ) <EOL> def test_collect ( self , publish_mock , get_port_stats_mock ) : <EOL> get_port_stats_mock . return_value = { '<STR_LIT:foo>' : <NUM_LIT:1> } <EOL> self . collector . collect ( ) <EOL> get_port_stats_mock . assert_has_calls ( [ call ( <NUM_LIT> ) , call ( <NUM_LIT> ) ] , <EOL> any_order = True ) <EOL> self . assertPublished ( publish_mock , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> self . assertPublished ( publish_mock , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> class GetPortStatsTestCase ( TestCase ) : <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_get_port_stats ( self , net_connections_mock ) : <EOL> ports = [ Mock ( ) for _ in range ( <NUM_LIT:5> ) ] <EOL> ports [ <NUM_LIT:0> ] . laddr = ( None , <NUM_LIT> ) <EOL> ports [ <NUM_LIT:0> ] . status = '<STR_LIT>' <EOL> ports [ <NUM_LIT:1> ] . laddr = ports [ <NUM_LIT:2> ] . laddr = ports [ <NUM_LIT:3> ] . laddr = ( None , <NUM_LIT> ) <EOL> ports [ <NUM_LIT:1> ] . status = '<STR_LIT>' <EOL> ports [ <NUM_LIT:2> ] . status = '<STR_LIT:OK>' <EOL> ports [ <NUM_LIT:3> ] . status = '<STR_LIT>' <EOL> ports [ <NUM_LIT:4> ] . laddr = ( None , <NUM_LIT> ) <EOL> net_connections_mock . return_value = ports <EOL> cnts = get_port_stats ( <NUM_LIT> ) <EOL> net_connections_mock . assert_called_once ( ) <EOL> self . assertEqual ( cnts , { '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> cnts = get_port_stats ( <NUM_LIT> ) <EOL> net_connections_mock . assert_called_once ( ) <EOL> self . assertEqual ( cnts , { '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:1> } ) </s>
