示例#1
0
 def test_bound_method_ids_are_stable(self):
     b = self.bound_tester()
     b2 = self.bound_tester()
     wr = events.WeakMethod(b.example)
     wr2 = events.WeakMethod(b.example)
     wr3 = events.WeakMethod(b2.example)
     wr4 = events.WeakMethod(b2.example)
     assert wr.ID == wr2.ID
     assert wr3.ID == wr4.ID
     assert wr.ID != wr4.ID
示例#2
0
    def test_free_method_ids_are_stable(self):
        def example(*args, **kwargs):
            return -99

        def example2(*args, **kwargs):
            return -99

        wr = events.WeakMethod(example)
        wr2 = events.WeakMethod(example)
        wr3 = events.WeakMethod(example2)
        wr4 = events.WeakMethod(example2)
        assert wr.ID == wr2.ID
        assert wr3.ID == wr4.ID
        assert wr.ID != wr4.ID
示例#3
0
    def test_free_method_excepts_on_dead_ref(self):
        def example(*args, **kwargs):
            return -99

        wr = events.WeakMethod(example)
        del (example)
        self.assertRaises(events.DeadReferenceError, wr)
示例#4
0
 def test_bound_method_DOES_NOT_except_on_dead_method_ref(self):
     '''
     you can't 'delete' a bound method, even if you overwrite it's name
     in a particular instance. bound methods work like descriptors under
     the hood.
     '''
     b = self.bound_tester()
     wr = events.WeakMethod(b.example)
     b.example = lambda x: 121
     try:
         wr()
     except events.DeadReferenceError:
         self.fail('this should not raise')
示例#5
0
 def test_bound_method_excepts_on_dead_ref(self):
     b = self.bound_tester()
     wr = events.WeakMethod(b.example)
     del (b)
     self.assertRaises(events.DeadReferenceError, wr)
示例#6
0
 def test_bound_method_works(self):
     b = self.bound_tester()
     wr = events.WeakMethod(b.example)
     assert wr() == 111
示例#7
0
    def test_bound_method(self):
        b = self.bound_tester()

        wr = events.WeakMethod(b.example)
        assert isinstance(wr, events.WeakMethodBound)
示例#8
0
    def test_free_method_works(self):
        def example(*args, **kwargs):
            return -99

        wr = events.WeakMethod(example)
        assert wr() == -99
示例#9
0
    def test_free_method(self):
        def example(*args, **kwargs):
            return -99

        wr = events.WeakMethod(example)
        assert isinstance(wr, events.WeakMethodFree)