adding test module

This commit is contained in:
BJ Dierkes 2012-07-15 15:11:38 -05:00
parent ea25fe8749
commit f63d1f34b0
2 changed files with 67 additions and 1 deletions

1
.gitignore vendored
View File

@ -61,5 +61,4 @@ tmtags
test.log
example.py
test.py
extensions

67
cement/utils/test.py Normal file
View File

@ -0,0 +1,67 @@
"""Cement testing utilities."""
import unittest
from ..core import backend, foundation
# shortcuts
from nose.tools import ok_ as ok
from nose.tools import eq_ as eq
from nose.tools import raises
from nose import SkipTest
class TestApp(foundation.CementApp):
"""
Basic CementApp for generic testing.
"""
class Meta:
label = 'test'
config_files = []
argv = []
class CementTestCase(unittest.TestCase):
"""
A sub-class of unittest.TestCase. Provides useful shortcuts including
the following:
self.ok
A shortcut to assert()
self.eq
A shortcut to assertEquals()
"""
def __init__(self, *args, **kw):
super(CementTestCase, self).__init__(*args, **kw)
self.ok = ok
self.eq = eq
def setUp(self):
"""
Sets up self.app with a generic TestApp(). Also resets the backend
hooks and handlers so that everytime an app is created it is setup
clean each time.
"""
self.app = self.make_app()
def make_app(self, *args, **kw):
"""
Create a generic app using TestApp. Arguments and Keyword Arguments
are passed to the app.
"""
self.reset_backend()
return TestApp(*args, **kw)
def reset_backend(self):
"""
Remove all registered hooks and handlers from the backend.
"""
for _handler in backend.handlers.copy():
del backend.handlers[_handler]
for _hook in backend.hooks.copy():
del backend.hooks[_hook]