Attachment '_test_template.py'

Download

   1 # -*- coding: utf-8 -*-
   2 """
   3     MoinMoin - MoinMoin.module_tested Tests
   4 
   5     Module names must start with 'test_' to be included in the tests.
   6 
   7     @copyright: 2003-2004 by Jürgen Hermann <jh@web.de>
   8     @license: GNU GPL, see COPYING for details.
   9 """
  10 
  11 import unittest
  12 from MoinMoin import module_tested
  13 from MoinMoin._tests import TestConfig
  14 
  15 
  16 class SimplestTestCase(unittest.TestCase):
  17     """ The simplest MoinMoin test class
  18 
  19     Class name must ends with 'TestCase' to be included in
  20     the tests.
  21     """
  22     def testSimplest(self):
  23         """ module_tested: test description... 
  24         
  25         Function name MUST start with 'test' to be included in the
  26         tests. 
  27         
  28         The first line of this docstring will show on the test output:
  29            module_tested: test description ... ok
  30         """
  31         # You can access the current request with self.request. It is
  32         # injected for you into the test class when by moin test
  33         # framework.
  34         result = module_tested.some_function(self.request, 'test_value')
  35         expected = 'expected value'
  36         self.assertEqual(result, expected,
  37                          ('Expected "%(expected)s" but got "%(result)s"') % locals())
  38     
  39     
  40 class ComplexTestCase(unittest.TestCase):
  41     """ Describe these tests here...
  42 
  43     Some tests may have a list of tests related to this test case. You
  44     can add a test by adding another line to this list
  45     """
  46     _tests = (
  47         # description,  test,            expected
  48         ('Line brake',  '[[BR]]',        '<br>'),
  49     )
  50 
  51     def setUp(self):
  52         """ Stuff that should run before each test
  53 
  54         Some test needs specific config values, or they will fail.
  55         """
  56         self.config = TestConfig(self.request,
  57                                  defaults=['this option', 'that option'], 
  58                                  another_option='non default value')
  59     
  60     def tearDown(self):
  61         """ Stuff that should run after each test
  62 
  63         Delete TestConfig, if used.
  64         """       
  65         del self.config
  66     
  67     def testFunction(self):
  68         """ module_tested: function should... """
  69         for description, test, expected in self._tests:
  70             result = self._helper_function(test)
  71             self.assertEqual(result, expected,
  72                              ('%(description)s: expected "%(expected)s" '
  73                               'but got "%(result)s"') % locals())
  74 
  75     def _helper_fuction(self, test):
  76         """ Some tests needs extra  work to run
  77 
  78         Keep the test non interesting deatils out of the way.
  79         """
  80         module_tested.do_this(self.request)
  81         module_tested.do_that()
  82 
  83         return result

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2005-06-14 19:52:54, 2.6 KB) [[attachment:_test_template.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.