mirror of
https://github.com/datafolklabs/cement.git
synced 2026-02-06 14:26:55 +00:00
adding test module
This commit is contained in:
parent
ea25fe8749
commit
f63d1f34b0
1
.gitignore
vendored
1
.gitignore
vendored
@ -61,5 +61,4 @@ tmtags
|
||||
test.log
|
||||
|
||||
example.py
|
||||
test.py
|
||||
extensions
|
||||
|
||||
67
cement/utils/test.py
Normal file
67
cement/utils/test.py
Normal 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]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user