diff options
Diffstat (limited to 'Mailman/testing/test_bounces.py')
| -rw-r--r-- | Mailman/testing/test_bounces.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/Mailman/testing/test_bounces.py b/Mailman/testing/test_bounces.py index 54c82ff68..f09c671f4 100644 --- a/Mailman/testing/test_bounces.py +++ b/Mailman/testing/test_bounces.py @@ -17,14 +17,18 @@ """Test the bounce detection modules.""" +from __future__ import with_statement + import os import sys import email import unittest -from paths import prefix +import Mailman.testing.bounces from Mailman.Bouncers.BouncerAPI import Stop +MSGDIR = os.path.dirname(Mailman.testing.bounces.__file__) + class BounceTest(unittest.TestCase): @@ -157,15 +161,13 @@ class BounceTest(unittest.TestCase): ) def test_bounce(self): - for modname, file, addrs in self.DATA: + for modname, filename, addrs in self.DATA: module = 'Mailman.Bouncers.' + modname __import__(module) - fp = open(os.path.join(prefix, 'Mailman', 'testing', 'bounces', - file)) - try: + # XXX Convert this tousing package resources + path = os.path.join(MSGDIR, filename) + with open(path) as fp: msg = email.message_from_file(fp) - finally: - fp.close() foundaddrs = sys.modules[module].process(msg) # Some modules return None instead of [] for failure if foundaddrs is None: @@ -181,12 +183,8 @@ class BounceTest(unittest.TestCase): def test_SMTP32_failure(self): from Mailman.Bouncers import SMTP32 # This file has no X-Mailer: header - fp = open(os.path.join(prefix, 'Mailman', 'testing', 'bounces', - 'postfix_01.txt')) - try: + with open(os.path.join(MSGDIR, 'postfix_01.txt')) as fp: msg = email.message_from_file(fp) - finally: - fp.close() self.failIf(msg['x-mailer'] is not None) self.failIf(SMTP32.process(msg)) |
