changeset 2458:01f2921e5fa4

tests: convert some more tests to py.test
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 22 Jul 2007 02:00:15 +0200
parents e0b1fc786797
children d9e112066a9e
files MoinMoin/macro/_tests/test_macro.py MoinMoin/mail/_tests/test_sendmail.py MoinMoin/search/_tests/test_search.py MoinMoin/util/_tests/test_web.py MoinMoin/widget/_tests/test_html.py
diffstat 5 files changed, 35 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/macro/_tests/test_macro.py	Sun Jul 22 00:01:18 2007 +0200
+++ b/MoinMoin/macro/_tests/test_macro.py	Sun Jul 22 02:00:15 2007 +0200
@@ -7,21 +7,18 @@
     @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
-
 from MoinMoin import macro
 from MoinMoin.parser.text import Parser
 from MoinMoin.formatter.text_html import Formatter
 
 
-class TestMacro(unittest.TestCase):
+class TestMacro:
     def testTrivialMacro(self):
         """macro: trivial macro works"""
         m = self._make_macro()
         expected = m.formatter.linebreak(0)
         result = m.execute("BR", "")
-        self.assertEqual(result, expected,
-            'Expected "%(expected)s" but got "%(result)s"' % locals())
+        assert result == expected
 
     def _make_macro(self):
         """Test helper"""
--- a/MoinMoin/mail/_tests/test_sendmail.py	Sun Jul 22 00:01:18 2007 +0200
+++ b/MoinMoin/mail/_tests/test_sendmail.py	Sun Jul 22 02:00:15 2007 +0200
@@ -6,14 +6,13 @@
     @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
 from email.Charset import Charset, QP
 from email.Header import Header
 from MoinMoin.mail import sendmail
 from MoinMoin import config
 
 
-class TestdecodeSpamSafeEmail(unittest.TestCase):
+class TestdecodeSpamSafeEmail:
     """mail.sendmail: testing mail"""
 
     _tests = (
@@ -39,13 +38,10 @@
     def testDecodeSpamSafeMail(self):
         """mail.sendmail: decoding spam safe mail"""
         for coded, expected in self._tests:
-            result = sendmail.decodeSpamSafeEmail(coded)
-            self.assertEqual(result, expected,
-                             'Expected "%(expected)s" but got "%(result)s"' %
-                             locals())
+            assert sendmail.decodeSpamSafeEmail(coded) == expected
 
 
-class TestEncodeAddress(unittest.TestCase):
+class TestEncodeAddress:
     """ Address encoding tests
 
     See http://www.faqs.org/rfcs/rfc2822.html section 3.4.
@@ -63,31 +59,27 @@
         """ mail.sendmail: encode simple address: local@domain """
         address = u'local@domain'
         expected = address.encode(config.charset)
-        self.failUnlessEqual(sendmail.encodeAddress(address, self.charset),
-                             expected)
+        assert sendmail.encodeAddress(address, self.charset) == expected
 
     def testComposite(self):
         """ mail.sendmail: encode address: 'Phrase <local@domain>' """
         address = u'Phrase <local@domain>'
         phrase = str(Header(u'Phrase '.encode('utf-8'), self.charset))
         expected = phrase + '<local@domain>'
-        self.failUnlessEqual(sendmail.encodeAddress(address, self.charset),
-                             expected)
+        assert sendmail.encodeAddress(address, self.charset) == expected
 
     def testCompositeUnicode(self):
         """ mail.sendmail: encode Uncode address: 'ויקי <local@domain>' """
         address = u'ויקי <local@domain>'
         phrase = str(Header(u'ויקי '.encode('utf-8'), self.charset))
         expected = phrase + '<local@domain>'
-        self.failUnlessEqual(sendmail.encodeAddress(address, self.charset),
-                             expected)
+        assert sendmail.encodeAddress(address, self.charset) == expected
 
     def testEmptyPhrase(self):
         """ mail.sendmail: encode address with empty phrase: '<local@domain>' """
         address = u'<local@domain>'
         expected = address.encode(config.charset)
-        self.failUnlessEqual(sendmail.encodeAddress(address, self.charset),
-                             expected)
+        assert sendmail.encodeAddress(address, self.charset) == expected
 
     def testEmptyAddress(self):
         """ mail.sendmail: encode address with empty address: 'Phrase <>'
@@ -98,8 +90,7 @@
         address = u'Phrase <>'
         phrase = str(Header(u'Phrase '.encode('utf-8'), self.charset))
         expected = phrase + '<>'
-        self.failUnlessEqual(sendmail.encodeAddress(address, self.charset),
-                             expected)
+        assert sendmail.encodeAddress(address, self.charset) == expected
 
     def testInvalidAddress(self):
         """ mail.sendmail: encode invalid address 'Phrase <blah'
@@ -110,8 +101,7 @@
         """
         address = u'Phrase <blah'
         expected = address.encode(config.charset)
-        self.failUnlessEqual(sendmail.encodeAddress(address, self.charset),
-                             expected)
+        assert sendmail.encodeAddress(address, self.charset) == expected
 
 
 coverage_modules = ['MoinMoin.mail.sendmail']
--- a/MoinMoin/search/_tests/test_search.py	Sun Jul 22 00:01:18 2007 +0200
+++ b/MoinMoin/search/_tests/test_search.py	Sun Jul 22 02:00:15 2007 +0200
@@ -6,11 +6,10 @@
     @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
 from MoinMoin import search
 
 
-class TestQuotingBug(unittest.TestCase):
+class TestQuotingBug:
     """search: quoting bug tests
 
     http://moinmoin.wikiwikiweb.de/MoinMoinBugs/SearchOneCharString
@@ -19,20 +18,18 @@
     testing parsed queries is much more work.
     """
 
-    def setUp(self):
-        self.parser = search.QueryParser()
-
     def testIsQuoted(self):
         """ search: quoting bug - quoted terms """
+        parser = search.QueryParser()
         for case in ('"yes"', "'yes'"):
-            self.assertEqual(self.parser.isQuoted(case), True)
+            assert parser.isQuoted(case)
 
     def testIsNot(self):
         """ search: quoting bug - unquoted terms """
-        tests = ('', "'", '"', '""', "''", "'\"", '"no', 'no"', "'no",
-                 "no'", '"no\'')
+        tests = ('', "'", '"', '""', "''", "'\"", '"no', 'no"', "'no", "no'", '"no\'')
+        parser = search.QueryParser()
         for case in tests:
-            self.assertEqual(self.parser.isQuoted(case), False)
+            assert not parser.isQuoted(case)
 
 
 coverage_modules = ['MoinMoin.search']
--- a/MoinMoin/util/_tests/test_web.py	Sun Jul 22 00:01:18 2007 +0200
+++ b/MoinMoin/util/_tests/test_web.py	Sun Jul 22 02:00:15 2007 +0200
@@ -6,13 +6,12 @@
     @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
 from MoinMoin import wikiutil
 from MoinMoin.util import web
 from MoinMoin.widget import html
 
 
-class TestMakeQueryString(unittest.TestCase):
+class TestMakeQueryString:
     """util.web: making query string"""
 
     def testMakeQueryStringFromArgument(self):
@@ -26,17 +25,11 @@
             )
 
         for description, arg, expected in tests:
-            result = wikiutil.makeQueryString(arg)
-            self.assertEqual(result, expected,
-                             ('%(description)s: expected "%(expected)s" '
-                              'but got "%(result)s"') % locals())
+            assert wikiutil.makeQueryString(arg) == expected
 
     def testMakeQueryStringFromKeywords(self):
         """ util.web: make query sting from keywords """
-        expected = 'a=1&b=string'
-        result = wikiutil.makeQueryString(a=1, b='string')
-        self.assertEqual(result, expected,
-                         'Expected "%(expected)s" but got "%(result)s"' % locals())
+        assert wikiutil.makeQueryString(a=1, b='string') == 'a=1&b=string'
 
     def testMakeQueryStringFromArgumentAndKeywords(self):
         """ util.web: make query sting from argument and keywords """
@@ -50,48 +43,41 @@
 
         for description, arg, expected in tests:
             # Call makeQueryString with both arg and keyword
-            result = wikiutil.makeQueryString(arg, b='kw')
-            self.assertEqual(result, expected,
-                             ('%(description)s: expected "%(expected)s" '
-                              'but got "%(result)s"') % locals())
+            assert wikiutil.makeQueryString(arg, b='kw') == expected
 
 
-class TestMakeSelection(unittest.TestCase):
+class TestMakeSelection:
     """util.web: creating html select"""
 
     values = ('one', 'two', 'simple', ('complex', 'A tuple & <escaped text>'))
 
-    def setUp(self):
-        html._SORT_ATTRS = 1
-        self.expected = (
+    html._SORT_ATTRS = 1
+    expected = (
         u'<select name="test" size="1">'
         u'<option value="one">one</option>'
         u'<option value="two">two</option>'
         u'<option value="simple">simple</option>'
         u'<option value="complex">A tuple &amp; &lt;escaped text&gt;</option>'
         u'</select>'
-        )
+    )
 
     def testMakeSelectNoSelection(self):
         """util.web: creating html select with no selection"""
         expected = self.expected
         result = unicode(web.makeSelection('test', self.values, size=1))
-        self.assertEqual(result, expected,
-                         'Expected "%(expected)s" but got "%(result)s"' % locals())
+        assert result == expected
 
     def testMakeSelectNoSelection2(self):
         """util.web: creating html select with non existing selection"""
         expected = self.expected
         result = unicode(web.makeSelection('test', self.values, 'three', size=1))
-        self.assertEqual(result, expected,
-                         'Expected "%(expected)s" but got "%(result)s"' % locals())
+        assert result == expected
 
     def testMakeSelectWithSelectedItem(self):
         """util.web: creating html select with selected item"""
         expected = self.expected.replace('value="two"', 'selected value="two"')
         result = unicode(web.makeSelection('test', self.values, 'two', size=1))
-        self.assertEqual(result, expected,
-                         'Expected "%(expected)s" but got "%(result)s"' % locals())
+        assert result == expected
 
 
 coverage_modules = ['MoinMoin.util.web']
--- a/MoinMoin/widget/_tests/test_html.py	Sun Jul 22 00:01:18 2007 +0200
+++ b/MoinMoin/widget/_tests/test_html.py	Sun Jul 22 02:00:15 2007 +0200
@@ -6,10 +6,11 @@
     @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.widget import html
 
-class TestHTMLWidgets(unittest.TestCase):
+class TestHTMLWidgets:
     """widget.html: testing html widgets"""
 
     def testCreate(self):
@@ -28,16 +29,14 @@
 
         for description, obj, expected in tests:
             result = unicode(obj)
-            self.assertEqual(result, expected,
-                             ('%(description)s: expected "%(expected)s" '
-                              'but got "%(result)s"') % locals())
+            assert result == expected
 
     def testInvalidAttributes(self):
-        """widegt.html: invalid attributes raises exception
+        """widget.html: invalid attributes raises exception
 
         TO DO: add tests for all elements by HTML 4 spec.
         """
-        self.assertRaises(AttributeError, html.BR, name='foo')
+        py.test.raises(AttributeError, html.BR, name='foo')
 
 
     def testCompositeElements(self):
@@ -61,8 +60,7 @@
         for action, data, expected in actions:
             action(data)
             result = unicode(element)
-            self.assertEqual(result, expected,
-                             'Expected "%(expected)s" but got "%(result)s"' % locals())
+            assert result == expected
 
 coverage_modules = ['MoinMoin.widget.html']