]> granicus.if.org Git - python/commitdiff
Move infrastructure into __init__ to lay groundwork for splitting test_email.
authorR David Murray <rdmurray@bitdance.com>
Thu, 31 Mar 2011 16:20:23 +0000 (12:20 -0400)
committerR David Murray <rdmurray@bitdance.com>
Thu, 31 Mar 2011 16:20:23 +0000 (12:20 -0400)
The split probably won't happen for a while, but I might as well lay the
groundwork now since I'll be adding new test modules before too long.

Lib/test/test_email/__init__.py
Lib/test/test_email/test_email.py

index 5aae093b4060dd2616d7359b2b044107e1139f27..2ef21bae5a6f08cc697d0f2e929d7e09c12af7c5 100644 (file)
@@ -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)
index 27356664ce5362f48dd5c4e98832faec1b6695a3..2519cc0800e326f8db9b2b0c80287074de6ac27d 100644 (file)
@@ -37,39 +37,13 @@ from email import base64mime
 from email import quoprimime
 
 from test.support import run_unittest, unlink
-from test.test_email import __file__ as landmark
-
+from test.test_email import openfile, TestEmailBase
 
 NL = '\n'
 EMPTYSTRING = ''
 SPACE = ' '
 
 
-
-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)
-
-
-
 # Test various aspects of the Message class's API
 class TestMessageAPI(TestEmailBase):
     def test_get_all(self):