1. Dan Jacob
  2. flask-testing
  3. Issues
Issue #2 new

Metaprogrammatic PEP-8 compliance

Dag Odenhall
created an issue

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.

Comments (0)

  1. Log in to comment