changeset 2817:53adbd066e90

tests: convert PageEditor tests to py.test
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 10 Sep 2007 19:47:35 +0200
parents 50fcf4ba8374
children 7fceb3588211
files MoinMoin/_tests/test_PageEditor.py
diffstat 1 files changed, 25 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_PageEditor.py	Mon Sep 10 18:37:32 2007 +0200
+++ b/MoinMoin/_tests/test_PageEditor.py	Mon Sep 10 19:47:35 2007 +0200
@@ -2,43 +2,41 @@
 """
     MoinMoin - MoinMoin.PageEditor Tests
 
-    @copyright: 2003-2004 by Juergen Hermann <jh@web.de>
+    @copyright: 2003-2004 by Juergen Hermann <jh@web.de>,
+                2007 MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
-
 import py
 
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin._tests.common import gain_superuser_rights
 
-class TestExpandVars(unittest.TestCase):
+class TestExpandVars(object):
     """PageEditor: testing page editor"""
 
     pagename = u'AutoCreatedMoinMoinTemporaryTestPage'
 
     _tests = (
         # Variable,             Expanded
-        ("@PAGE@",              pagename),
-        ("em@PAGE@bedded",      "em%sbedded" % pagename),
-        ("@NOVAR@",             "@NOVAR@"),
+        ("@PAGE@", pagename),
+        ("em@PAGE@bedded", "em%sbedded" % pagename),
+        ("@NOVAR@", "@NOVAR@"),
         ("case@Page@sensitive", "case@Page@sensitive"),
         )
 
-    def setUp(self):
+    def setup_method(self, method):
         self.page = PageEditor(self.request, self.pagename)
 
     def testExpandVariables(self):
         """ PageEditor: expand general variables """
         for var, expected in self._tests:
             result = self.page._expand_variables(var)
-            self.assertEqual(result, expected,
-                'Expected "%(expected)s" but got "%(result)s"' % locals())
+            assert result == expected
 
 
-class TestExpandUserName(unittest.TestCase):
+class TestExpandUserName(object):
     """ Base class for user name tests
 
     Set user name during tests.
@@ -46,12 +44,12 @@
     pagename = u'AutoCreatedMoinMoinTemporaryTestPage'
     variable = u'@USERNAME@'
 
-    def setUp(self):
+    def setup_method(self, method):
         self.page = PageEditor(self.request, self.pagename)
         self.savedName = self.request.user.name
         self.request.user.name = self.name
 
-    def tearDown(self):
+    def teardown_method(self, method):
         self.request.user.name = self.savedName
 
     def expand(self):
@@ -64,7 +62,7 @@
 
     def testExpandCamelCaseUserName(self):
         """ PageEditor: expand @USERNAME@ CamelCase """
-        self.assertEqual(self.expand(), self.name)
+        assert self.expand() == self.name
 
 
 class TestExpandExtendedName(TestExpandUserName):
@@ -75,7 +73,7 @@
         """ PageEditor: expand @USERNAME@ extended name - enabled """
         try:
             config = self.TestConfig()
-            self.assertEqual(self.expand(), u'[[%s]]' % self.name)
+            assert self.expand() == u'[[%s]]' % self.name
         finally:
             del config
 
@@ -86,21 +84,21 @@
     name = u'user name'
     email = 'user@example.com'
 
-    def setUp(self):
-        TestExpandUserName.setUp(self)
+    def setup_method(self, method):
+        super(TestExpandMailto, self).setup_method(method)
         self.savedValid = self.request.user.valid
         self.request.user.valid = 1
         self.savedEmail = self.request.user.email
         self.request.user.email = self.email
 
-    def tearDown(self):
-        TestExpandUserName.tearDown(self)
+    def teardown_method(self, method):
+        super(TestExpandMailto, self).teardown_method(method)
         self.request.user.valid = self.savedValid
         self.request.user.email = self.savedEmail
 
     def testMailto(self):
         """ PageEditor: expand @MAILTO@ """
-        self.assertEqual(self.expand(), u'<<MailTo(%s)>>' % self.email)
+        assert self.expand() == u'<<MailTo(%s)>>' % self.email
 
 
 class TestExpandPrivateVariables(TestExpandUserName):
@@ -110,21 +108,21 @@
     dictPage = name + '/MyDict'
     shouldDeleteTestPage = True
 
-    def setUp(self):
-        TestExpandUserName.setUp(self)
+    def setup_method(self, method):
+        super(TestExpandPrivateVariables, self).setup_method(method)
         self.savedValid = self.request.user.valid
         self.request.user.valid = 1
         self.createTestPage()
         self.deleteCaches()
 
-    def tearDown(self):
-        TestExpandUserName.tearDown(self)
+    def teardown_method(self, method):
+        super(TestExpandPrivateVariables, self).teardown_method(method)
         self.request.user.valid = self.savedValid
         self.deleteTestPage()
 
     def testPrivateVariables(self):
         """ PageEditor: expand user variables """
-        self.assertEqual(self.expand(), self.name)
+        assert self.expand() == self.name
 
     def createTestPage(self):
         """ Create temporary page, bypass logs, notification and backups
@@ -170,7 +168,7 @@
         return page.getPagePath(use_underlay=0, check_create=0)
 
 
-class TestSave:
+class TestSave(object):
 
     def setup_method(self, method):
         self.old_handlers = self.request.cfg.event_handlers
@@ -205,3 +203,4 @@
 
 
 coverage_modules = ['MoinMoin.PageEditor']
+