コード例 #1
0
 def test_getBaseObject(self):
     spam = Spam()
     eggs = Spam.eggs
     listappend = [].append
     spamda = lambda: None
     values = (
         ('spam', 'spam', 0),
         (123, 123, 0),
         (12.3, 12.3, 0),
         ([], [], 0),
         ((), (), 0),
         ({}, {}, 0),
         # Builtin function.
         (len, len, 0),
         # Builtin method.
         (listappend, listappend, 0),
         # User function.
         (ham, ham, 0),
         # Byte-compiled code.
         (ham.func_code, ham.func_code, 0),
         # Lambda.
         (spamda, spamda, 0),
         # Class with init.
         (Foo, Foo.__init__.im_func, 1),
         # Class with no init.
         (Bar, Bar, 0),
         # Bound method.
         (spam.foo, spam.foo.im_func, 1),
         # Bound method with self named something else (spam).
         (spam.bar, spam.bar.im_func, 1),
         # Unbound method. (Do not drop the self argument.)
         (eggs, eggs.im_func, 0),
         # Callable instance.
         (spam, spam.__call__.im_func, 1),
     )
     for object, baseObject, dropSelf in values:
         result = introspect.getBaseObject(object)
         self.assertEqual(result, (baseObject, dropSelf))
コード例 #2
0
 def test_getBaseObject(self):
     spam = Spam()
     eggs = Spam.eggs
     listappend = [].append
     spamda = lambda: None
     values = (
         ('spam', 'spam', 0),
         (123, 123, 0),
         (12.3, 12.3, 0),
         ([], [], 0),
         ((), (), 0),
         ({}, {}, 0),
         # Builtin function.
         (len, len, 0),
         # Builtin method.
         (listappend, listappend, 0),
         # User function.
         (ham, ham, 0),
         # Byte-compiled code.
         (ham.func_code, ham.func_code, 0),
         # Lambda.
         (spamda, spamda, 0),
         # Class with init.
         (Foo, Foo.__init__.im_func, 1),
         # Class with no init.
         (Bar, Bar, 0),
         # Bound method.
         (spam.foo, spam.foo.im_func, 1),
         # Bound method with self named something else (spam).
         (spam.bar, spam.bar.im_func, 1),
         # Unbound method. (Do not drop the self argument.)
         (eggs, eggs.im_func, 0),
         # Callable instance.
         (spam, spam.__call__.im_func, 1),
     )
     for object, baseObject, dropSelf in values:
         result = introspect.getBaseObject(object)
         self.assertEqual(result, (baseObject, dropSelf))