[Python-checkins] cpython: Move infrastructure into __init__ to lay groundwork for splitting test_email.

r.david.murray python-checkins at python.org
Thu Mar 31 18:20:39 CEST 2011


http://hg.python.org/cpython/rev/976a07bdcd64
changeset: 69084:976a07bdcd64
user: R David Murray <rdmurray at bitdance.com>
date: Thu Mar 31 12:20:23 2011 -0400
summary:
 Move infrastructure into __init__ to lay groundwork for splitting test_email.
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.
files:
 Lib/test/test_email/__init__.py | 27 ++++++++++++++++++
 Lib/test/test_email/test_email.py | 28 +------------------
 2 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/Lib/test/test_email/__init__.py b/Lib/test/test_email/__init__.py
--- a/Lib/test/test_email/__init__.py
+++ b/Lib/test/test_email/__init__.py
@@ -2,6 +2,8 @@
 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 @@
 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)
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -37,39 +37,13 @@
 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):
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /