Beispiel #1
0
    def test_wrap_with_keywords_1 (self):
        callable = lambda **keywords: None
        keywords = { 'a': 1, 'b': 2 }

        self.assert_(Binding           .wrap (callable, keywords = keywords) is not callable)
        self.assert_(WeakBinding       .wrap (callable, keywords = keywords) is not callable)
        self.assert_(RaisingWeakBinding.wrap (callable, keywords = keywords) is not callable)
Beispiel #2
0
 def test_invocation(self):
     self.assertEqual(
         Binding(DUMMY.identity_function)(33, 'test'), (33, 'test'))
     self.assertEqual(
         WeakBinding(DUMMY.identity_function)(33, 'test'), (33, 'test'))
     self.assertEqual(
         RaisingWeakBinding(DUMMY.identity_function)(33, 'test'),
         (33, 'test'))
Beispiel #3
0
 def test_creation_with_arguments(self):
     self.assertEqual(
         Binding(DUMMY.identity_function, (33, ))('test'), (33, 'test'))
     self.assertEqual(
         WeakBinding(DUMMY.identity_function, (33, ))('test'), (33, 'test'))
     self.assertEqual(
         RaisingWeakBinding(DUMMY.identity_function, (33, ))('test'),
         (33, 'test'))
Beispiel #4
0
 def test_invocation_keywords(self):
     keywords = {'a': 1, 'b': 2}
     self.assertEqual(
         Binding(DUMMY.keyword_dict_function)(**keywords), keywords)
     self.assertEqual(
         WeakBinding(DUMMY.keyword_dict_function)(**keywords), keywords)
     self.assertEqual(
         RaisingWeakBinding(DUMMY.keyword_dict_function)(**keywords),
         keywords)
Beispiel #5
0
    def test_garbage_collection_2(self):
        object = Dummy()
        method = RaisingWeakBinding(object.identity_function)

        self.assertEqual(method(15), 15)

        del object
        self.collect_garbage()

        self.assertRaises(GarbageCollectedError, method)
Beispiel #6
0
 def test_creation_with_keywords(self):
     keywords = {'a': 1, 'b': 2}
     self.assertEqual(
         Binding(DUMMY.keyword_dict_function, (), keywords)(), keywords)
     self.assertEqual(
         WeakBinding(DUMMY.keyword_dict_function, (), None, keywords)(),
         keywords)
     self.assertEqual(
         RaisingWeakBinding(DUMMY.keyword_dict_function, (), None,
                            keywords)(), keywords)
Beispiel #7
0
    def test_wrap_with_keywords_1(self):
        callable = lambda **keywords: None
        keywords = {'a': 1, 'b': 2}

        self.assert_(Binding.wrap(callable, keywords=keywords) is not callable)
        self.assert_(
            WeakBinding.wrap(callable, keywords=keywords) is not callable)
        self.assert_(
            RaisingWeakBinding.wrap(callable, keywords=keywords)
            is not callable)
Beispiel #8
0
    def test_unreferencable_object_method_failure(self):
        class Test(object):
            __slots__ = ()

            def test(self):
                pass

        self.assertRaises(CannotWeakReferenceError,
                          lambda: WeakBinding(Test().test))
        self.assertRaises(CannotWeakReferenceError,
                          lambda: RaisingWeakBinding(Test().test))
Beispiel #9
0
    def test_wrap_with_arguments_1 (self):
        callable = lambda a, b, c: None

        self.assert_(Binding           .wrap (callable, (1, 2)) is not callable)
        self.assert_(WeakBinding       .wrap (callable, (1, 2)) is not callable)
        self.assert_(RaisingWeakBinding.wrap (callable, (1, 2)) is not callable)
Beispiel #10
0
    def test_wrap_1(self):
        callable = lambda: None

        self.assert_(Binding.wrap(callable) is callable)
        self.assert_(WeakBinding.wrap(callable) is callable)
        self.assert_(RaisingWeakBinding.wrap(callable) is callable)
Beispiel #11
0
    def test_wrap_3 (self):
        callable = Dummy.identity_function

        self.assert_(Binding           .wrap (callable) is callable)
        self.assert_(WeakBinding       .wrap (callable) is callable)
        self.assert_(RaisingWeakBinding.wrap (callable) is callable)
Beispiel #12
0
    def test_wrap_4 (self):
        callable = Dummy.static_identity

        self.assert_(Binding           .wrap (callable) is callable)
        self.assert_(WeakBinding       .wrap (callable) is callable)
        self.assert_(RaisingWeakBinding.wrap (callable) is callable)
Beispiel #13
0
    def test_wrap_1 (self):
        callable = lambda: None

        self.assert_(Binding           .wrap (callable) is callable)
        self.assert_(WeakBinding       .wrap (callable) is callable)
        self.assert_(RaisingWeakBinding.wrap (callable) is callable)
Beispiel #14
0
    def test_wrap_2 (self):
        callable = open

        self.assert_(Binding           .wrap (callable) is callable)
        self.assert_(WeakBinding       .wrap (callable) is callable)
        self.assert_(RaisingWeakBinding.wrap (callable) is callable)
Beispiel #15
0
    def test_wrap_3(self):
        callable = Dummy.identity_function

        self.assert_(Binding.wrap(callable) is callable)
        self.assert_(WeakBinding.wrap(callable) is callable)
        self.assert_(RaisingWeakBinding.wrap(callable) is callable)
Beispiel #16
0
    def test_wrap_4(self):
        callable = Dummy.static_identity

        self.assert_(Binding.wrap(callable) is callable)
        self.assert_(WeakBinding.wrap(callable) is callable)
        self.assert_(RaisingWeakBinding.wrap(callable) is callable)
Beispiel #17
0
    def test_wrap_2(self):
        callable = open

        self.assert_(Binding.wrap(callable) is callable)
        self.assert_(WeakBinding.wrap(callable) is callable)
        self.assert_(RaisingWeakBinding.wrap(callable) is callable)
Beispiel #18
0
    def test_wrap_with_arguments_1(self):
        callable = lambda a, b, c: None

        self.assert_(Binding.wrap(callable, (1, 2)) is not callable)
        self.assert_(WeakBinding.wrap(callable, (1, 2)) is not callable)
        self.assert_(RaisingWeakBinding.wrap(callable, (1, 2)) is not callable)
Beispiel #19
0
 def test_creation(self):
     Binding(DUMMY.identity_function)
     WeakBinding(DUMMY.identity_function)
     RaisingWeakBinding(DUMMY.identity_function)