<s> import unittest <EOL> from nose . tools import assert_equals , assert_raises , assert_true <EOL> from robotide . publish . messages import RideMessage , RideLogMessage , RideLogException <EOL> from robotide . publish . publisher import Publisher <EOL> class RideTestMessage ( RideMessage ) : <EOL> topic = '<STR_LIT>' <EOL> class RideTestMessageWithAttrs ( RideTestMessage ) : <EOL> data = [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] <EOL> class RideTestMessageWithLongName ( RideTestMessage ) : <EOL> pass <EOL> class TestMessage ( unittest . TestCase ) : <EOL> def test_topic ( self ) : <EOL> assert_equals ( RideMessage ( ) . topic , '<STR_LIT>' ) <EOL> assert_equals ( RideTestMessage ( ) . topic , '<STR_LIT>' ) <EOL> assert_equals ( RideTestMessageWithLongName ( ) . topic , <EOL> '<STR_LIT>' ) <EOL> def test_all_attributes_given ( self ) : <EOL> msg = RideTestMessageWithAttrs ( foo = '<STR_LIT:bar>' , bar = '<STR_LIT>' ) <EOL> assert_equals ( msg . foo , '<STR_LIT:bar>' ) <EOL> assert_equals ( msg . bar , '<STR_LIT>' ) <EOL> def test_missing_mandatory_attribute ( self ) : <EOL> assert_raises ( TypeError , RideTestMessageWithAttrs , foo = '<STR_LIT:bar>' ) <EOL> def test_missing_many_mandatory_attributes ( self ) : <EOL> assert_raises ( TypeError , RideTestMessageWithAttrs ) <EOL> def test_no_such_attribute_should_fail ( self ) : <EOL> assert_raises ( TypeError , RideTestMessageWithAttrs , foo = '<STR_LIT>' , bar = '<STR_LIT>' , <EOL> quux = '<STR_LIT>' ) <EOL> class TestRideLogMessage ( unittest . TestCase ) : <EOL> def test_log_message ( self ) : <EOL> msg = RideLogMessage ( message = '<STR_LIT>' , level = '<STR_LIT>' ) <EOL> assert_equals ( msg . message , '<STR_LIT>' ) <EOL> assert_equals ( msg . level , '<STR_LIT>' ) <EOL> assert_true ( msg . timestamp . startswith ( '<STR_LIT>' ) ) <EOL> def test_log_exception ( self ) : <EOL> try : <EOL> <NUM_LIT:1> / <NUM_LIT:0> <EOL> except Exception , err : <EOL> msg = RideLogException ( <EOL> message = '<STR_LIT>' , exception = err , level = '<STR_LIT>' ) <EOL> assert_true ( msg . message . startswith ( <EOL> '<STR_LIT>' ) ) <EOL> assert_equals ( msg . level , '<STR_LIT>' ) <EOL> assert_true ( msg . timestamp . startswith ( '<STR_LIT>' ) ) <EOL> class TestPublisher ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . _msg = '<STR_LIT>' <EOL> def test_publishing_string_message ( self ) : <EOL> pub = Publisher ( ) <EOL> pub . subscribe ( self . _listener , '<STR_LIT>' ) <EOL> pub . publish ( '<STR_LIT>' , '<STR_LIT:content>' ) <EOL> assert_equals ( self . _msg , '<STR_LIT:content>' ) <EOL> def test_broken_string_message_listener ( self ) : <EOL> pub = Publisher ( ) <EOL> pub . subscribe ( self . _broken_listener , '<STR_LIT>' ) <EOL> pub . publish ( '<STR_LIT>' , '<STR_LIT:content>' ) <EOL> assert_equals ( self . _msg , '<STR_LIT:content>' ) <EOL> def _listener ( self , data ) : <EOL> self . _msg = data <EOL> def _broken_listener ( self , data ) : <EOL> self . _msg = data <EOL> raise RuntimeError ( data ) </s>
