Back to index

moin  1.9.0~rc2
_test_template.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 """
00003     MoinMoin - MoinMoin.module_tested Tests
00004 
00005     Module names must start with 'test_' to be included in the tests.
00006 
00007     @copyright: 2003-2004 by Juergen Hermann <jh@web.de>,
00008                 2007 MoinMoin:AlexanderSchremmer
00009                 2009 MoinMoin:ReimarBauer
00010     @license: GNU GPL, see COPYING for details.
00011 """
00012 
00013 # include here the module that you want to test:
00014 from MoinMoin import module_tested
00015 
00016 
00017 class TestSimpleStuff(object):
00018     """ The simplest MoinMoin test class
00019 
00020     Class name must start with 'Test' to be included in
00021     the tests.
00022 
00023     See http://codespeak.net/py/dist/test.html for reference.
00024     """
00025     def testSimplest(self):
00026         """ module_tested: test description...
00027 
00028         Function name MUST start with 'test' to be included in the
00029         tests.
00030         """
00031         # You can access the current request with self.request. It is
00032         # injected for you into the test class by moin test framework.
00033         result = module_tested.some_function(self.request, 'test_value')
00034         expected = 'expected value'
00035         assert result == expected
00036 
00037 
00038 class TestComplexStuff(object):
00039     """ Describe these tests here...
00040 
00041     Some tests may have a list of tests related to this test case. You
00042     can add a test by adding another line to this list
00043     """
00044     _tests = (
00045         # description,  test,            expected
00046         ('Line break',  '<<BR>>',        '<br>'),
00047     )
00048 
00049     from MoinMoin._tests import wikiconfig
00050     class Config(wikiconfig.Config):
00051         foo = 'bar'  # we want to have this non-default setting
00052 
00053     def setup_class(self):
00054         """ Stuff that should be run to init the state of this test class
00055         """
00056 
00057     def teardown_class(self):
00058         """ Stuff that should run to clean up the state of this test class
00059         """
00060 
00061     def testFunction(self):
00062         """ module_tested: function should... """
00063         for description, test, expected in self._tests:
00064             result = self._helper_function(test)
00065             assert result == expected
00066 
00067     def _helper_fuction(self, test):
00068         """ Some tests needs extra  work to run
00069 
00070         Keep the test non interesting details out of the way.
00071         """
00072         module_tested.do_this(self.request)
00073         module_tested.do_that()
00074         result = None
00075         return result
00076