diff options
Diffstat (limited to 'Lib/test/test_email/__init__.py')
-rw-r--r-- | Lib/test/test_email/__init__.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_email/__init__.py b/Lib/test/test_email/__init__.py index 5aae093..2ef21ba 100644 --- a/Lib/test/test_email/__init__.py +++ b/Lib/test/test_email/__init__.py @@ -2,6 +2,8 @@ import os import sys import unittest import test.support +import email +from test.test_email import __file__ as landmark # used by regrtest and __main__. def test_main(): @@ -11,3 +13,28 @@ def test_main(): savepath = sys.path[:] test.support._run_suite(unittest.defaultTestLoader.discover(here)) sys.path[:] = savepath + + +# 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): + + def ndiffAssertEqual(self, first, second): + """Like assertEqual except use ndiff for readable output.""" + if first != second: + sfirst = str(first) + ssecond = str(second) + rfirst = [repr(line) for line in sfirst.splitlines()] + rsecond = [repr(line) for line in ssecond.splitlines()] + diff = difflib.ndiff(rfirst, rsecond) + raise self.failureException(NL + NL.join(diff)) + + def _msgobj(self, filename): + with openfile(filename) as fp: + return email.message_from_file(fp) |