diff options
author | Tarek Ziade <tarek@ziade.org> | 2012-03-12 12:51:33 -0700 |
---|---|---|
committer | Tarek Ziade <tarek@ziade.org> | 2012-03-12 12:51:33 -0700 |
commit | 9fd3561d32bf23fcfa8fed8ea49c8ade2e3b8597 (patch) | |
tree | 6b0096d4f559cb22f20d73f08315c8258d38b877 /distutils2 | |
parent | d44c91095d18d49af41cfd35eec3dc1dfc39b36d (diff) | |
download | disutils2-9fd3561d32bf23fcfa8fed8ea49c8ade2e3b8597.tar.gz |
Fixed a function name lookup in distutils2.pypi.wrapper (#14263)
Diffstat (limited to 'distutils2')
-rw-r--r-- | distutils2/pypi/wrapper.py | 5 | ||||
-rw-r--r-- | 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 index 699beaa..c884444 100644 --- a/distutils2/pypi/wrapper.py +++ b/distutils2/pypi/wrapper.py @@ -25,8 +25,9 @@ def switch_index_if_fails(func, wrapper): 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 index 0000000..4a9f8ca --- /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') |