[Python-checkins] distutils2: Fixed a function name lookup in distutils2.pypi.wrapper (#14263)

tarek.ziade python-checkins at python.org
Mon Mar 12 20:53:47 CET 2012


http://hg.python.org/distutils2/rev/32a95541829c
changeset:   1292:32a95541829c
parent:      1290:c82c97b2eae1
user:        Tarek Ziade <tarek at ziade.org>
date:        Mon Mar 12 12:51:33 2012 -0700
summary:
  Fixed a function name lookup in distutils2.pypi.wrapper (#14263)

files:
  distutils2/pypi/wrapper.py            |   5 +-
  distutils2/tests/test_pypi_wrapper.py |  37 +++++++++++++++
  2 files changed, 40 insertions(+), 2 deletions(-)


diff --git a/distutils2/pypi/wrapper.py b/distutils2/pypi/wrapper.py
--- a/distutils2/pypi/wrapper.py
+++ b/distutils2/pypi/wrapper.py
@@ -25,8 +25,9 @@
         exception = None
         methods = [func]
         for f in wrapper._indexes.values():
-            if f != func.im_self and hasattr(f, func.f_name):
-                methods.append(getattr(f, func.f_name))
+            func_name = func.im_func.func_name
+            if f != func.im_self and hasattr(f, func_name):
+                methods.append(getattr(f, func_name))
         for method in methods:
             try:
                 response = method(*args, **kwargs)
diff --git a/distutils2/tests/test_pypi_wrapper.py b/distutils2/tests/test_pypi_wrapper.py
new file mode 100644
--- /dev/null
+++ b/distutils2/tests/test_pypi_wrapper.py
@@ -0,0 +1,37 @@
+"""Tests for the distutils2.pypi.wrapper module."""
+
+
+from distutils2.tests import unittest
+from distutils2.pypi.wrapper import switch_index_if_fails
+
+
+class Index1(object):
+    def test(self):
+        raise Exception("boo")
+
+
+class Index2(object):
+    def test(self):
+        return 'OK'
+
+
+class Indexes(object):
+    _indexes = {'one': Index1(), 'two': Index2()}
+
+
+class TestPyPIWrapper(unittest.TestCase):
+
+    def test_wrapper(self):
+        index = Indexes._indexes['one']
+        func = switch_index_if_fails(getattr(index, 'test'), Indexes)
+        self.assertEqual(func(), 'OK')
+
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(TestPyPIWrapper))
+    return suite
+
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')

-- 
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list