changeset 2047:e5526f9c2113

Fixed test_template, streamlined reimars last test.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Sat, 05 May 2007 16:06:06 +0200
parents a63c473a100d
children 8ac1efc21728
files MoinMoin/_tests/_test_template.py MoinMoin/_tests/test_security.py
diffstat 2 files changed, 34 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/_test_template.py	Sat May 05 15:26:15 2007 +0200
+++ b/MoinMoin/_tests/_test_template.py	Sat May 05 16:06:06 2007 +0200
@@ -4,38 +4,37 @@
 
     Module names must start with 'test_' to be included in the tests.
 
-    @copyright: 2003-2004 by Juergen Hermann <jh@web.de>
+    @copyright: 2003-2004 by Juergen Hermann <jh@web.de>,
+                2007 MoinMoin:AlexanderSchremmer
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest
+# include here the module that you want to test:
 from MoinMoin import module_tested
 
 
-class SimplestTestCase(unittest.TestCase):
+class TestSimpleStuff:
     """ The simplest MoinMoin test class
 
-    Class name must ends with 'TestCase' to be included in
+    Class name must start with 'Test' to be included in
     the tests.
+
+    See http://codespeak.net/py/dist/test.html for reference.
     """
     def testSimplest(self):
         """ module_tested: test description... 
         
         Function name MUST start with 'test' to be included in the
         tests. 
-        
-        The first line of this docstring will show on the test output:
-           module_tested: test description ... ok
         """
         # You can access the current request with self.request. It is
         # injected for you into the test class by moin test framework.
         result = module_tested.some_function(self.request, 'test_value')
         expected = 'expected value'
-        self.assertEqual(result, expected,
-                         ('Expected "%(expected)s" but got "%(result)s"') % locals())
+        assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()
 
 
-class ComplexTestCase(unittest.TestCase):
+class TestComplexStuff:
     """ Describe these tests here...
 
     Some tests may have a list of tests related to this test case. You
@@ -43,31 +42,29 @@
     """
     _tests = (
         # description,  test,            expected
-        ('Line brake',  '[[BR]]',        '<br>'),
+        ('Line break',  '[[BR]]',        '<br>'),
     )
 
-    def setUp(self):
-        """ Stuff that should run before each test
+    def setup_class(cls):
+        """ Stuff that should be run to init the state of this test class
 
         Some test needs specific config values, or they will fail.
         """
         self.config = self.TestConfig(defaults=['this option', 'that option'],
                                       another_option='non default value')
 
-    def tearDown(self):
-        """ Stuff that should run after each test
+    def teardown_class(cls):
+        """ Stuff that should run to clean up the state of this test class
 
-        Delete TestConfig, if used.
         """
-        del self.config
+        self.config.reset()
 
     def testFunction(self):
         """ module_tested: function should... """
         for description, test, expected in self._tests:
             result = self._helper_function(test)
-            self.assertEqual(result, expected,
-                             ('%(description)s: expected "%(expected)s" '
-                              'but got "%(result)s"') % locals())
+            assert result == expected, ('%(description)s: expected "%(expected)s" '
+                              'but got "%(result)s"') % locals()
 
     def _helper_fuction(self, test):
         """ Some tests needs extra  work to run
--- a/MoinMoin/_tests/test_security.py	Sat May 05 15:26:15 2007 +0200
+++ b/MoinMoin/_tests/test_security.py	Sat May 05 16:06:06 2007 +0200
@@ -254,24 +254,22 @@
         path = page.getPagePath(use_underlay=0, check_create=0)
         if os.path.exists(path):
             py.test.skip("%s exists. Won't overwrite exiting page" % self.dictPage)
+
         try:
-            os.mkdir(path)
-            revisionsDir = os.path.join(path, 'revisions')
-            os.mkdir(revisionsDir)
-            current = '00000001'
-            file(os.path.join(path, 'current'), 'w').write('%s\n' % current)
-            text = u'#acl All: \n'
-            file(os.path.join(revisionsDir, current), 'w').write(text)
-        except Exception, err:
-            py.test.skip("Can not be create test page: %s" % err)
+            try:
+                os.mkdir(path)
+                revisionsDir = os.path.join(path, 'revisions')
+                os.mkdir(revisionsDir)
+                current = '00000001'
+                file(os.path.join(path, 'current'), 'w').write('%s\n' % current)
+                text = u'#acl All: \n'
+                file(os.path.join(revisionsDir, current), 'w').write(text)
+            except Exception, err:
+                py.test.skip("Can not be create test page: %s" % err)
+    
+            assert not self.request.user.may.write(pagename)
+        finally:
+            if os.path.exists(path):
+                import shutil
+                shutil.rmtree(path, True)
 
-        result = self.request.user.may.write(pagename)
-        expected = False
-
-        if os.path.exists(path):
-            import shutil
-            shutil.rmtree(path, True)
-
-        self.assertEqual(result, expected,
-                         ('Expected "%(expected)s" but got "%(result)s"') % locals())
-