[Python-checkins] commit of r41691 - python/trunk/Lib/test/test_quopri.py

walter.doerwald python-checkins at python.org
Thu Dec 15 00:32:25 CET 2005


Author: walter.doerwald
Date: Thu Dec 15 00:32:22 2005
New Revision: 41691

Modified:
   python/trunk/Lib/test/test_quopri.py
Log:
If quopri uses the implementations from binascii do the tests a second time
using the Python implementations of the functions. This imcreases code
coverage and makes sure that both implementations do the same thing.


Modified: python/trunk/Lib/test/test_quopri.py
==============================================================================
--- python/trunk/Lib/test/test_quopri.py	(original)
+++ python/trunk/Lib/test/test_quopri.py	Thu Dec 15 00:32:22 2005
@@ -2,7 +2,7 @@
 import unittest
 
 from cStringIO import StringIO
-from quopri import *
+import quopri
 
 
 
@@ -44,6 +44,23 @@
 """
 
 
+def withpythonimplementation(testfunc):
+    def newtest(self):
+        # Test default implementation
+        testfunc(self)
+        # Test Python implementation
+        if quopri.b2a_qp is not None or quopri.a2b_qp is not None:
+            oldencode = quopri.b2a_qp
+            olddecode = quopri.a2b_qp
+            try:
+                quopri.b2a_qp = None
+                quopri.a2b_qp = None
+                testfunc(self)
+            finally:
+                quopri.b2a_qp = oldencode
+                quopri.a2b_qp = olddecode
+    newtest.__name__ = testfunc.__name__
+    return newtest
 
 class QuopriTestCase(unittest.TestCase):
     # Each entry is a tuple of (plaintext, encoded string).  These strings are
@@ -110,44 +127,52 @@
         ('hello_world', 'hello=5Fworld'),
         )
 
+    @withpythonimplementation
     def test_encodestring(self):
         for p, e in self.STRINGS:
-            self.assert_(encodestring(p) == e)
+            self.assert_(quopri.encodestring(p) == e)
 
+    @withpythonimplementation
     def test_decodestring(self):
         for p, e in self.STRINGS:
-            self.assert_(decodestring(e) == p)
+            self.assert_(quopri.decodestring(e) == p)
 
+    @withpythonimplementation
     def test_idempotent_string(self):
         for p, e in self.STRINGS:
-            self.assert_(decodestring(encodestring(e)) == e)
+            self.assert_(quopri.decodestring(quopri.encodestring(e)) == e)
 
+    @withpythonimplementation
     def test_encode(self):
         for p, e in self.STRINGS:
             infp = StringIO(p)
             outfp = StringIO()
-            encode(infp, outfp, quotetabs=0)
+            quopri.encode(infp, outfp, quotetabs=False)
             self.assert_(outfp.getvalue() == e)
 
+    @withpythonimplementation
     def test_decode(self):
         for p, e in self.STRINGS:
             infp = StringIO(e)
             outfp = StringIO()
-            decode(infp, outfp)
+            quopri.decode(infp, outfp)
             self.assert_(outfp.getvalue() == p)
 
+    @withpythonimplementation
     def test_embedded_ws(self):
         for p, e in self.ESTRINGS:
-            self.assert_(encodestring(p, quotetabs=1) == e)
-            self.assert_(decodestring(e) == p)
+            self.assert_(quopri.encodestring(p, quotetabs=True) == e)
+            self.assert_(quopri.decodestring(e) == p)
 
+    @withpythonimplementation
     def test_encode_header(self):
         for p, e in self.HSTRINGS:
-            self.assert_(encodestring(p, header = 1) == e)
+            self.assert_(quopri.encodestring(p, header=True) == e)
 
+    @withpythonimplementation
     def test_decode_header(self):
         for p, e in self.HSTRINGS:
-            self.assert_(decodestring(e, header = 1) == p)
+            self.assert_(quopri.decodestring(e, header=True) == p)
 
 def test_main():
     test_support.run_unittest(QuopriTestCase)


More information about the Python-checkins mailing list