2011-03-21 18:17:06 -03:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
import test.support
|
2011-03-31 13:20:23 -03:00
|
|
|
import email
|
|
|
|
from test.test_email import __file__ as landmark
|
2011-03-21 18:17:06 -03:00
|
|
|
|
|
|
|
# used by regrtest and __main__.
|
|
|
|
def test_main():
|
|
|
|
here = os.path.dirname(__file__)
|
|
|
|
# Unittest mucks with the path, so we have to save and restore
|
|
|
|
# it to keep regrtest happy.
|
|
|
|
savepath = sys.path[:]
|
|
|
|
test.support._run_suite(unittest.defaultTestLoader.discover(here))
|
|
|
|
sys.path[:] = savepath
|
2011-03-31 13:20:23 -03:00
|
|
|
|
|
|
|
|
|
|
|
# helper code used by a number of test modules.
|
|
|
|
|
|
|
|
def openfile(filename, *args, **kws):
|
|
|
|
path = os.path.join(os.path.dirname(landmark), 'data', filename)
|
|
|
|
return open(path, *args, **kws)
|
|
|
|
|
|
|
|
|
|
|
|
# Base test class
|
|
|
|
class TestEmailBase(unittest.TestCase):
|
|
|
|
|
2011-04-18 14:59:37 -03:00
|
|
|
maxDiff = None
|
|
|
|
|
2011-03-31 14:11:40 -03:00
|
|
|
def __init__(self, *args, **kw):
|
|
|
|
super().__init__(*args, **kw)
|
|
|
|
self.addTypeEqualityFunc(bytes, self.assertBytesEqual)
|
|
|
|
|
2011-04-10 16:28:29 -03:00
|
|
|
ndiffAssertEqual = unittest.TestCase.assertEqual
|
2011-03-31 13:20:23 -03:00
|
|
|
|
|
|
|
def _msgobj(self, filename):
|
|
|
|
with openfile(filename) as fp:
|
|
|
|
return email.message_from_file(fp)
|
2011-03-31 14:11:40 -03:00
|
|
|
|
|
|
|
def _bytes_repr(self, b):
|
|
|
|
return [repr(x) for x in b.splitlines(True)]
|
|
|
|
|
|
|
|
def assertBytesEqual(self, first, second, msg):
|
|
|
|
"""Our byte strings are really encoded strings; improve diff output"""
|
|
|
|
self.assertEqual(self._bytes_repr(first), self._bytes_repr(second))
|