<s> import json <EOL> import unittest <EOL> from . registry import Mease <EOL> from . backends . test import TestBackend <EOL> class MeaseTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . mease = Mease ( TestBackend ) <EOL> self . reset_return_namespace ( ) <EOL> def reset_return_namespace ( self ) : <EOL> self . ret = type ( "<STR_LIT>" , ( ) , { } ) ( ) <EOL> def test_opener ( self ) : <EOL> """<STR_LIT>""" <EOL> client = '<STR_LIT:a>' <EOL> clients_list = [ '<STR_LIT:d>' , '<STR_LIT:e>' , '<STR_LIT:f>' ] <EOL> @ self . mease . opener <EOL> def opener_func ( client , clients_list ) : <EOL> self . ret . client = client <EOL> self . ret . clients_list = clients_list <EOL> @ self . mease . opener <EOL> def otjer_opener_func ( client , clients_list ) : <EOL> self . ret . other_client = client <EOL> self . ret . other_clients_list = clients_list <EOL> self . mease . call_openers ( client , clients_list ) <EOL> self . assertEqual ( client , self . ret . client ) <EOL> self . assertListEqual ( clients_list , self . ret . clients_list ) <EOL> self . assertEqual ( client , self . ret . other_client ) <EOL> self . assertListEqual ( clients_list , self . ret . other_clients_list ) <EOL> def test_closer ( self ) : <EOL> """<STR_LIT>""" <EOL> client = '<STR_LIT:a>' <EOL> clients_list = [ '<STR_LIT:d>' , '<STR_LIT:e>' , '<STR_LIT:f>' ] <EOL> @ self . mease . closer <EOL> def closer_func ( client , clients_list ) : <EOL> self . ret . client = client <EOL> self . ret . clients_list = clients_list <EOL> @ self . mease . closer <EOL> def other_closer_func ( client , clients_list ) : <EOL> self . ret . other_client = client <EOL> self . ret . other_clients_list = clients_list <EOL> self . mease . call_closers ( client , clients_list ) <EOL> self . assertEqual ( client , self . ret . client ) <EOL> self . assertListEqual ( clients_list , self . ret . clients_list ) <EOL> self . assertEqual ( client , self . ret . other_client ) <EOL> self . assertListEqual ( clients_list , self . ret . other_clients_list ) <EOL> def test_receiver ( self ) : <EOL> """<STR_LIT>""" <EOL> client = '<STR_LIT:a>' <EOL> message = '<STR_LIT>' <EOL> clients_list = [ '<STR_LIT:d>' , '<STR_LIT:e>' , '<STR_LIT:f>' ] <EOL> @ self . mease . receiver ( json = True ) <EOL> def json_receiver_func ( client , clients_list , message ) : <EOL> self . ret . json_client = client <EOL> self . ret . json_message = message <EOL> self . ret . json_clients_list = clients_list <EOL> @ self . mease . receiver <EOL> def raw_receiver_func ( client , clients_list , message ) : <EOL> self . ret . raw_client = client <EOL> self . ret . raw_message = message <EOL> self . ret . raw_clients_list = clients_list <EOL> self . mease . call_receivers ( client , clients_list , message ) <EOL> json_message = json . loads ( message ) <EOL> self . assertEqual ( client , self . ret . json_client ) <EOL> self . assertEqual ( json_message , self . ret . json_message ) <EOL> self . assertListEqual ( clients_list , self . ret . json_clients_list ) <EOL> self . assertEqual ( client , self . ret . raw_client ) <EOL> self . assertEqual ( message , self . ret . raw_message ) <EOL> self . assertListEqual ( clients_list , self . ret . raw_clients_list ) <EOL> def test_sender ( self ) : <EOL> """<STR_LIT>""" <EOL> message = "<STR_LIT>" <EOL> routing = '<STR_LIT>' <EOL> @ self . mease . sender ( routing = '<STR_LIT>' ) <EOL> def sender_func ( routing , message ) : <EOL> self . ret . routing = routing <EOL> self . ret . message = message <EOL> @ self . mease . sender ( routing = '<STR_LIT>' ) <EOL> def other_sender_func ( routing , message ) : <EOL> self . ret . other_routing = routing <EOL> self . ret . other_message = message <EOL> @ self . mease . sender ( routing = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def more_sender_func ( routing , message ) : <EOL> self . ret . more_routing = routing <EOL> self . ret . more_message = message <EOL> self . mease . call_senders ( routing , message ) <EOL> self . assertEqual ( routing , self . ret . routing ) <EOL> self . assertEqual ( message , self . ret . message ) <EOL> self . assertFalse ( hasattr ( self . ret , '<STR_LIT>' ) ) <EOL> self . assertFalse ( hasattr ( self . ret , '<STR_LIT>' ) ) <EOL> self . assertEqual ( routing , self . ret . more_routing ) <EOL> self . assertEqual ( message , self . ret . more_message ) <EOL> self . reset_return_namespace ( ) <EOL> self . mease . call_senders ( None , message ) <EOL> self . assertIsNone ( self . ret . routing ) <EOL> self . assertEqual ( message , self . ret . message ) <EOL> self . assertIsNone ( self . ret . other_routing ) <EOL> self . assertEqual ( message , self . ret . other_message ) <EOL> self . assertIsNone ( self . ret . more_routing ) <EOL> self . assertEqual ( message , self . ret . more_message ) <EOL> self . reset_return_namespace ( ) <EOL> def test_regex_sender ( self ) : <EOL> """<STR_LIT>""" <EOL> message = "<STR_LIT>" <EOL> @ self . mease . sender ( routing_re = r'<STR_LIT>' ) <EOL> def first_sender_func ( routing , message ) : <EOL> self . ret . first_routing = routing <EOL> self . ret . first_message = message <EOL> @ self . mease . sender ( routing = '<STR_LIT>' , routing_re = r'<STR_LIT>' ) <EOL> def second_sender_func ( routing , message ) : <EOL> self . ret . second_routing = routing <EOL> self . ret . second_message = message <EOL> @ self . mease . sender ( routing = '<STR_LIT>' , routing_re = r'<STR_LIT>' ) <EOL> def third_sender_func ( routing , message ) : <EOL> self . ret . third_routing = routing <EOL> self . ret . third_message = message <EOL> routing = '<STR_LIT>' <EOL> self . mease . call_senders ( routing , message ) <EOL> self . assertEqual ( routing , self . ret . first_routing ) <EOL> self . assertEqual ( message , self . ret . first_message ) <EOL> self . assertFalse ( hasattr ( self . ret , '<STR_LIT>' ) ) <EOL> self . assertFalse ( hasattr ( self . ret , '<STR_LIT>' ) ) <EOL> self . assertEqual ( routing , self . ret . third_routing ) <EOL> self . assertEqual ( message , self . ret . third_message ) <EOL> self . reset_return_namespace ( ) <EOL> routing = '<STR_LIT>' <EOL> self . mease . call_senders ( routing , message ) <EOL> self . assertFalse ( hasattr ( self . ret , '<STR_LIT>' ) ) <EOL> self . assertFalse ( hasattr ( self . ret , '<STR_LIT>' ) ) <EOL> self . assertEqual ( routing , self . ret . second_routing ) <EOL> self . assertEqual ( message , self . ret . second_message ) <EOL> self . assertEqual ( routing , self . ret . third_routing ) <EOL> self . assertEqual ( message , self . ret . third_message ) <EOL> self . reset_return_namespace ( ) <EOL> routing = '<STR_LIT>' <EOL> self . mease . call_senders ( routing , message ) <EOL> self . assertFalse ( hasattr ( self . ret , '<STR_LIT>' ) ) <EOL> self . assertFalse ( hasattr ( self . ret , '<STR_LIT>' ) ) <EOL> self . assertFalse ( hasattr ( self . ret , '<STR_LIT>' ) ) <EOL> self . assertFalse ( hasattr ( self . ret , '<STR_LIT>' ) ) <EOL> self . assertFalse ( hasattr ( self . ret , '<STR_LIT>' ) ) <EOL> self . assertFalse ( hasattr ( self . ret , '<STR_LIT>' ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
