[Python-checkins] python/dist/src/Lib/test test_functional.py, 1.1, 1.2

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Tue Mar 8 07:14:53 CET 2005


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23159/Lib/test

Modified Files:
	test_functional.py 
Log Message:
Make functional.partial() more closely match the spec by emulating
some useful features of regular functions:

* Made weak referencable.
* Allow attribute access so a user can set __name__, __doc__, etc.



Index: test_functional.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_functional.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- test_functional.py	28 Feb 2005 19:39:23 -0000	1.1
+++ test_functional.py	8 Mar 2005 06:14:51 -0000	1.2
@@ -1,6 +1,7 @@
 import functional
 import unittest
 from test import test_support
+from weakref import proxy
 
 @staticmethod
 def PythonPartial(func, *args, **keywords):
@@ -116,6 +117,22 @@
         self.assertRaises(ZeroDivisionError, self.thetype(f), 1, 0)
         self.assertRaises(ZeroDivisionError, self.thetype(f, y=0), 1)
 
+    def test_attributes(self):
+        p = self.thetype(hex)
+        try:
+            del p.__dict__
+        except TypeError:
+            pass
+        else:
+            self.fail('partial object allowed __dict__ to be deleted')
+
+    def test_weakref(self):
+        f = self.thetype(int, base=16)
+        p = proxy(f)
+        self.assertEqual(f.func, p.func)
+        f = None
+        self.assertRaises(ReferenceError, getattr, p, 'func')
+
 
 class PartialSubclass(functional.partial):
     pass



More information about the Python-checkins mailing list