Skip to content

Instantly share code, notes, and snippets.

@dorkitude
Created October 27, 2011 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dorkitude/1321139 to your computer and use it in GitHub Desktop.
Save dorkitude/1321139 to your computer and use it in GitHub Desktop.
class BaseTestCase(unittest.TestCase):
"""
Extend this with your test cases to get some sweet shit!
- Provides:
- Instance methods:
- self.persist_item(item) # Use instead of item.save()
- self.set_up()
- a subclass's method *must* call super
- self.tear_down()
- a subclass's method *must* call super
- Classmethods:
- set_up_class()
- a subclass's method *must* call super
- tear_down_class()
- a subclass's method *must* call super
- Assertion aliases:
- self.assert_equal() aliases self.assertEqual()
- self.assert_equal() aliases self.assertEqual()
"""
class __metaclass__(type):
def __getattr__(cls, name):
"""
This provides snake_case aliases for mixedCase classmethods.
For instance, if you were to ask for `cls.tear_down_class`, and it
didn't exist, you would transparently get a reference to
`cls.tearDownClass` instead.
"""
name = utils.to_mixed(name)
return type.__getattribute__(cls, name)
def __getattr__(self, name):
"""
This provides snake_case aliases for mixedCase instance methods.
For instance, if you were to ask for `self.assert_equal`, and it
didn't exist, you would transparently get a reference to
`self.assertEqual` instead.
"""
mixed_name = utils.to_mixed(name)
mixed_attr = None
try:
mixed_attr = object.__getattribute__(self, mixed_name)
except:
pass
if mixed_attr:
return mixed_attr
return self.__getattribute__(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment