示例#1
0
 def test_add_pop_one(self):
     obj = Object()
     def callback(*args):
         pass
     add_callback(obj, callback)
     self.assertIsInstance(obj._callbacks, Node)
     self.assertIs(obj._callbacks.data, callback)
     self.assertEqual(obj._callbacks.extra, ())
     self.assertEqual(pop_callback(obj), (callback, ()))
     self.assertEqual(obj._callbacks, None)
     add_callback(obj, callback, (1, 2))
     self.assertIsInstance(obj._callbacks, Node)
     self.assertIs(obj._callbacks.data, callback)
     self.assertEqual(obj._callbacks.extra, (1, 2))
     self.assertEqual(pop_callback(obj), (callback, (1, 2)))
     self.assertEqual(obj._callbacks, None)
示例#2
0
def get_callbacks(obj):
    callbacks = []
    while True:
        callback = pop_callback(obj)
        if not callback:
            return
        callbacks.append(callback)
    return callbacks
示例#3
0
def get_callbacks(obj):
    callbacks = []
    while True:
        callback = pop_callback(obj)
        if not callback:
            return
        callbacks.append(callback)
    return callbacks
示例#4
0
 def test_add_pop_multiple(self):
     obj = Object()
     def callback(*args):
         pass
     for i in range(5):
         add_callback(obj, callback)
     self.assertIsInstance(obj._callbacks, dllist)
     for i in range(5):
         self.assertEqual(len(obj._callbacks), 5-i)
         self.assertEqual(pop_callback(obj), (callback, ()))
     self.assertIsNone(obj._callbacks)
     for i in range(5):
         add_callback(obj, callback, (1, 2))
     self.assertIsInstance(obj._callbacks, dllist)
     for i in range(5):
         self.assertEqual(len(obj._callbacks), 5-i)
         self.assertEqual(pop_callback(obj), (callback, (1, 2)))
     self.assertIsNone(obj._callbacks)
示例#5
0
    def test_add_pop_one(self):
        obj = Object()

        def callback(*args):
            pass

        add_callback(obj, callback)
        self.assertIsInstance(obj._callbacks, Node)
        self.assertIs(obj._callbacks.callback, callback)
        self.assertEqual(obj._callbacks.args, ())
        self.assertEqual(pop_callback(obj), (callback, ()))
        self.assertEqual(obj._callbacks, None)
        add_callback(obj, callback, (1, 2))
        self.assertIsInstance(obj._callbacks, Node)
        self.assertIs(obj._callbacks.callback, callback)
        self.assertEqual(obj._callbacks.args, (1, 2))
        self.assertEqual(pop_callback(obj), (callback, (1, 2)))
        self.assertEqual(obj._callbacks, None)
示例#6
0
    def test_add_pop_multiple(self):
        obj = Object()

        def callback(*args):
            pass

        for i in range(5):
            add_callback(obj, callback)
        self.assertIsInstance(obj._callbacks, dllist)
        for i in range(5):
            self.assertEqual(len(obj._callbacks), 5 - i)
            self.assertEqual(pop_callback(obj), (callback, ()))
        self.assertIsNone(obj._callbacks)
        for i in range(5):
            add_callback(obj, callback, (1, 2))
        self.assertIsInstance(obj._callbacks, dllist)
        for i in range(5):
            self.assertEqual(len(obj._callbacks), 5 - i)
            self.assertEqual(pop_callback(obj), (callback, (1, 2)))
        self.assertIsNone(obj._callbacks)