From a815464e1f91e8596bda35534afd0c4a402a5f9d Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 13 Nov 2012 09:01:40 -0500 Subject: [PATCH] test: fix tests to handle Message-IDs This should have happened in: commit 29f8b8813e1f464b7171ea1830b6ed40ec24dac2 Author: W. Trevor King Date: Sat Oct 27 11:09:45 2012 -0400 rss2email: add Message-IDs so I can link messages in Mutt --- test/allthingsrss/1.expected | 10 ++++++++++ test/test.py | 30 ++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/test/allthingsrss/1.expected b/test/allthingsrss/1.expected index 5bd9bb4..953979d 100644 --- a/test/allthingsrss/1.expected +++ b/test/allthingsrss/1.expected @@ -6,6 +6,7 @@ From: "rss2email: Lindsey Smith" To: a@b.com Subject: Version 2.67 Released Date: Tue, 21 Sep 2010 16:55:07 -0000 +Message-ID: <...@dev.null.invalid> User-Agent: rss2email X-RSS-Feed: allthingsrss/feed.atom X-RSS-ID: http://www.allthingsrss.com/rss2email/?p=62 @@ -49,6 +50,7 @@ From: "rss2email: Lindsey Smith" To: a@b.com Subject: Version 2.68 Released with Actual New Features Date: Fri, 01 Oct 2010 18:21:26 -0000 +Message-ID: <...@dev.null.invalid> User-Agent: rss2email X-RSS-Feed: allthingsrss/feed.atom X-RSS-ID: http://www.allthingsrss.com/rss2email/?p=72 @@ -105,6 +107,7 @@ From: "rss2email: Lindsey Smith" To: a@b.com Subject: How to Read RSS Feeds in Emacs Date: Fri, 05 Nov 2010 17:36:14 -0000 +Message-ID: <...@dev.null.invalid> User-Agent: rss2email X-RSS-Feed: allthingsrss/feed.atom X-RSS-ID: http://www.allthingsrss.com/rss2email/?p=79 @@ -136,6 +139,7 @@ From: "rss2email: Lindsey Smith" To: a@b.com Subject: Version 2.69 Released Date: Fri, 12 Nov 2010 18:45:08 -0000 +Message-ID: <...@dev.null.invalid> User-Agent: rss2email X-RSS-Feed: allthingsrss/feed.atom X-RSS-ID: http://www.allthingsrss.com/rss2email/?p=85 @@ -177,6 +181,7 @@ From: "rss2email: Lindsey Smith" To: a@b.com Subject: Minor Correction to v2.69 Packages Date: Fri, 10 Dec 2010 17:47:58 -0000 +Message-ID: <...@dev.null.invalid> User-Agent: rss2email X-RSS-Feed: allthingsrss/feed.atom X-RSS-ID: http://www.allthingsrss.com/rss2email/?p=88 @@ -210,6 +215,7 @@ From: "rss2email: Lindsey Smith" To: a@b.com Subject: Minor correction to the minor correction: v2.69a released Date: Mon, 13 Dec 2010 18:04:20 -0000 +Message-ID: <...@dev.null.invalid> User-Agent: rss2email X-RSS-Feed: allthingsrss/feed.atom X-RSS-ID: http://www.allthingsrss.com/rss2email/?p=95 @@ -252,6 +258,7 @@ From: "rss2email: Lindsey Smith" To: a@b.com Subject: Mac OS X and rss2email are Compatible Date: Fri, 17 Dec 2010 20:54:27 -0000 +Message-ID: <...@dev.null.invalid> User-Agent: rss2email X-RSS-Feed: allthingsrss/feed.atom X-RSS-ID: http://www.allthingsrss.com/rss2email/?p=99 @@ -288,6 +295,7 @@ From: "rss2email: Lindsey Smith" To: a@b.com Subject: Version 2.70 Released Date: Tue, 21 Dec 2010 20:00:49 -0000 +Message-ID: <...@dev.null.invalid> User-Agent: rss2email X-RSS-Feed: allthingsrss/feed.atom X-RSS-ID: http://www.allthingsrss.com/rss2email/?p=106 @@ -326,6 +334,7 @@ From: "rss2email: Lindsey Smith" To: a@b.com Subject: Version 2.71 Release plus Other Major Updates Date: Fri, 04 Mar 2011 18:03:11 -0000 +Message-ID: <...@dev.null.invalid> User-Agent: rss2email X-RSS-Feed: allthingsrss/feed.atom X-RSS-ID: http://www.allthingsrss.com/rss2email/?p=123 @@ -370,6 +379,7 @@ From: "rss2email: Lindsey Smith" To: a@b.com Subject: Mac OS, rss2email and scheduling with launchd Date: Tue, 23 Aug 2011 15:57:37 -0000 +Message-ID: <...@dev.null.invalid> User-Agent: rss2email X-RSS-Feed: allthingsrss/feed.atom X-RSS-ID: http://www.allthingsrss.com/rss2email/?p=131 diff --git a/test/test.py b/test/test.py index fc26fc7..085a842 100755 --- a/test/test.py +++ b/test/test.py @@ -8,16 +8,22 @@ import glob as _glob import io as _io import logging as _logging import os as _os +import re as _re import rss2email as _rss2email +import rss2email.config as _rss2email_config +import rss2email.feed as _rss2email_feed # Get a copy of the internal rss2email.CONFIG for copying _stringio = _io.StringIO() -_rss2email.CONFIG.write(_stringio) +_rss2email_config.CONFIG.write(_stringio) BASE_CONFIG_STRING = _stringio.getvalue() del _stringio +MESSAGE_ID_REGEXP = _re.compile( + '^Message-ID: <[^@]*@dev.null.invalid>$', _re.MULTILINE) + class Send (list): def __call__(self, sender, message): @@ -30,6 +36,21 @@ class Send (list): return '\n'.join(chunks) +def clean_result(text): + """Cleanup dynamic portions of the generated email headers + + >>> text = ( + ... 'Date: Tue, 23 Aug 2011 15:57:37 -0000\\n' + ... 'Message-ID: <9dff03db-f5a7@dev.null.invalid>\\n' + ... 'User-Agent: rss2email\\n' + ... ) + >>> print(clean_result(text).rstrip()) + Date: Tue, 23 Aug 2011 15:57:37 -0000 + Message-ID: <...@dev.null.invalid> + User-Agent: rss2email + """ + return MESSAGE_ID_REGEXP.sub('Message-ID: <...@dev.null.invalid>', text) + def test(dirname=None, config_path=None, force=False): if dirname is None: dirname = _os.path.dirname(config_path) @@ -40,19 +61,20 @@ def test(dirname=None, config_path=None, force=False): return feed_path = _glob.glob(_os.path.join(dirname, 'feed.*'))[0] _rss2email.LOG.info('testing {}'.format(config_path)) - config = _rss2email.Config() + config = _rss2email_config.Config() config.read_string(BASE_CONFIG_STRING) read_paths = config.read([config_path]) - feed = _rss2email.Feed(name='test', url=feed_path, config=config) + feed = _rss2email_feed.Feed(name='test', url=feed_path, config=config) expected_path = config_path.replace('config', 'expected') with open(expected_path, 'r') as f: - expected = f.read() + expected = clean_result(f.read()) feed._send = Send() feed.run() generated = feed._send.as_string() if force: with open(expected_path, 'w') as f: f.write(generated) + generated = clean_result(generated) if generated != expected: diff_lines = _difflib.unified_diff( expected.splitlines(), generated.splitlines(), -- 2.26.2