Пример #1
0
def on_test3(param1):
    global EVENTS
    
    EVENTS.append(("test3", param1))
    
    ## the next one goes on the queue, at the end, as normal
    pub("test5",  param1)
    
    ## but this one would be queued in front of the previous
    upub("test4", param1)
Пример #2
0
 def test_zc_no_sub(self):
     """
     No subscribers
     """
     global EVENTS, EVENTS_ALL
     
     clear_all_subs()
     
     pub("notopic1")
     pub("notopic2", "param2")
     
     self.assertEqual(len(EVENTS), 0)
     self.assertEqual(len(EVENTS_ALL), 0)
Пример #3
0
    def test_z3_toall(self):
        """
        Subscribe to all
        """
        global EVENTS_ALL
        
        #print
        #print "begin: ", EVENTS_ALL
        
        import test3
        
        reset_event_all()
        
        pub("test99", "value_all")
        
        #print
        #print "end: ",EVENTS_ALL
                
        self.assertEqual(len(EVENTS_ALL), 2)
        
        context, msg=EVENTS_ALL.pop(0)
        topic, params=msg
        
        ctx_bits=context.split("/")
        ## test*  all
        is_test1=ctx_bits[0]=="test1"
        is_test3=ctx_bits[0]=="test3"
        
        self.assertEqual(is_test1, not is_test3)
        
        self.assertEqual(ctx_bits[1], "all")
        self.assertEqual(topic, "test99")
        self.assertEqual(params[0], "value_all")

        #
        #
        #
                
        context, msg=EVENTS_ALL.pop(0)
        topic, params=msg
        
        ctx_bits=context.split("/")
        ## test*  all
        is_test1=ctx_bits[0]=="test1"
        is_test3=ctx_bits[0]=="test3"
        
        self.assertEqual(is_test1, not is_test3)
        
        self.assertEqual(ctx_bits[1], "all")
        self.assertEqual(topic, "test99")
        self.assertEqual(params[0], "value_all")
Пример #4
0
    def test_a1_simple(self):
        """
        Simple 1 topic, 2 msgs
        """
        global EVENTS
        
        pub("test1", "value1")
        pub("test1", "value2")

        self.assertEqual(len(EVENTS), 2)
        
        topic1, val1=EVENTS.pop(0)
        self.assertEqual(topic1, "test1")
        self.assertEqual(val1, "value1")
        
        topic2, val2=EVENTS.pop(0)
        self.assertEqual(topic2, "test1")
        self.assertEqual(val2, "value2")
Пример #5
0
    def test_a4_2modules(self):
        """
        Simple 2 modules, 1 msg
        """
        global EVENTS
        import test2
        
        pub("test99", "a4")

        self.assertEqual(len(EVENTS), 2)
        
        topic1, val1=EVENTS.pop(0)
        self.assertEqual(topic1.split("/")[1], "test99")
        self.assertEqual(val1,   "a4")
        
        topic2, val2=EVENTS.pop(0)
        self.assertEqual(topic2.split("/")[1], "test99")
        self.assertEqual(val2,   "a4")
Пример #6
0
 def test_a3_simple_urgent(self):
     """
     Simple urgent, 1 topics, 3msgs
     """
     global EVENTS
     
     pub("test3", "value3")
     
     self.assertEqual(len(EVENTS), 3)
     
     topic1, val1=EVENTS.pop(0)
     self.assertEqual(topic1, "test3")
     self.assertEqual(val1,   "value3")
     
     topic2, val2=EVENTS.pop(0)
     self.assertEqual(topic2, "test4")
     self.assertEqual(val2,   "value3")
             
     topic3, val3=EVENTS.pop(0)
     self.assertEqual(topic3, "test5")
     self.assertEqual(val3,   "value3")
Пример #7
0
    def test_a2_two_topics(self):
        """
        Two topics, 2 msgs
        """
        global EVENTS
        
        pub("test1", "value1")
        pub("test2", "param1", "param2")
        self.assertEqual(len(EVENTS), 2)

        topic1, val1=EVENTS.pop(0)
        self.assertEqual(topic1, "test1")
        self.assertEqual(val1, "value1")
        
        topic2, val2=EVENTS.pop(0)
        self.assertEqual(len(val2), 2)
        
        self.assertEqual(topic2, "test2")
        
        a,b=val2
        self.assertEqual(a, "param1")
        self.assertEqual(b, "param2")
Пример #8
0
 def test_za_raise(self):
     """
     Raise an exception
     """
     with self.assertRaises(Exception) as _context:
         pub("raise")