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.
This commit is contained in:
parent
c97ba7064e
commit
b197543680
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue