diff options
author | Walter Dörwald <walter@livinglogic.de> | 2005-12-14 23:32:22 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2005-12-14 23:32:22 (GMT) |
commit | b1975436808898d7588a00adec33524bb561089f (patch) | |
tree | 7243222dfe7227a689f90500646178c0d214912e /Lib | |
parent | c97ba7064ed4d0ab0bbc2b8843e22eda6d666af5 (diff) | |
download | cpython-b1975436808898d7588a00adec33524bb561089f.zip cpython-b1975436808898d7588a00adec33524bb561089f.tar.gz cpython-b1975436808898d7588a00adec33524bb561089f.tar.bz2 |
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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_quopri.py | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/Lib/test/test_quopri.py b/Lib/test/test_quopri.py index dedda8d..dbda79d 100644 --- a/Lib/test/test_quopri.py +++ b/Lib/test/test_quopri.py @@ -2,7 +2,7 @@ from test import test_support import unittest from cStringIO import StringIO -from quopri import * +import quopri @@ -44,6 +44,23 @@ characters... have fun! """ +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 @@ zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz''') ('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) |