rduplain/flask-testing — Issue #2: Metaprogrammatic PEP-8 compliance
Author: rduplain
Created: 2012-02-29 16:40:28+00:00
State: open
Labels: import, proposal

I add this to my base TestCase:

import re
from functools import partial

def __getattr__(self, name):
name = re.sub(r'_([a-z])', lambda m: m.group(1).upper(), name)
return partial(getattr(TestCase, name), self)
# ^ The parent class

Lets me do `self.assert_equals` etc. Adding it should also mean you can drop all the internal snake case aliases. Doesn't give you API documentation though you could add a note about this behaviour in the docs with some examples. Alternatively loop dir(TestCase) and dynamically alias any camel cased attributes, should take care of API docs.

I've tested that it avoids recursive stack exhaustion and that it properly raises an AttributeError when the camel case version doesn't exist. This is why we're doing getattr on the parent class and using partial to inject self.

---------------------------------------
- Bitbucket: https://bitbucket.org/danjac/flask-testing/issue/2
- Originally Reported By: [Dag Odenhall](http://bitbucket.org/dag)
- Originally Created At: 2010-10-19 14:51:09