Created
October 27, 2011 22:51
-
-
Save dorkitude/1321139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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