You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2020/09/02 12:01:30 UTC
[incubator-ponymail-unit-tests] branch master updated: Allow for
multiple mboxes with same tests
This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-unit-tests.git
The following commit(s) were added to refs/heads/master by this push:
new b0bd551 Allow for multiple mboxes with same tests
b0bd551 is described below
commit b0bd551741b18a305fa0178a0c177846132384e4
Author: Sebb <se...@apache.org>
AuthorDate: Wed Sep 2 13:01:11 2020 +0100
Allow for multiple mboxes with same tests
If a pathname is not followed by any tests, then run the same
tests as for the first following pathname with at least one test
---
tests/test-generators.py | 60 +++++++++++++++++++++-----------------
tests/test-parsing.py | 76 ++++++++++++++++++++++++++----------------------
2 files changed, 76 insertions(+), 60 deletions(-)
diff --git a/tests/test-generators.py b/tests/test-generators.py
index bc1e4d3..9b3bff0 100755
--- a/tests/test-generators.py
+++ b/tests/test-generators.py
@@ -87,38 +87,46 @@ def run_tests(args):
tests_run = 0
yml = yaml.safe_load(open(args.load, 'r'))
generator_names = generators.generator_names() if hasattr(generators, 'generator_names') else ['full', 'medium', 'cluster', 'legacy']
- for mboxfile, run in yml['generators'].items():
+ mboxfiles = []
+ for file, run in yml['generators'].items():
+ mboxfiles.append(file)
+ if not run: # No tests under this filename, run same tests as next
+ continue
for gen_type, tests in run.items():
if gen_type not in generator_names:
sys.stderr.write("Warning: generators.py does not have the '%s' generator, skipping tests\n" % gen_type)
continue
test_args = collections.namedtuple('testargs', ['parse_html', 'generator'])(parse_html, gen_type)
archie = interfacer.Archiver(archiver, test_args)
- mbox = mailbox.mbox(mboxfile, None if args.nomboxo else MboxoFactory, create=False)
- no_messages = len(mbox.keys())
- no_tests = len(tests)
- if no_messages != no_tests:
- sys.stderr.write("Warning: %s run for %s contains %u tests, but mbox file has %u emails!\n" %
- (gen_type, mboxfile, no_tests, no_messages))
- for test in tests:
- tests_run += 1
- key = test['index']
- message_raw = _raw(args, mbox, key)
- message = mbox.get(key)
- msgid =(message.get('message-id') or '').strip()
- if msgid != test['message-id']:
- sys.stderr.write("""[SEQ?] %s, index %2u: Expected '%s', got '%s'!\n""" %
- (gen_type, key, test['message-id'], msgid))
- continue # no point continuing
- lid = args.lid or archiver.normalize_lid(message.get('list-id', '??'))
- json = archie.compute_updates(fake_args, lid, False, message, message_raw)
-
- if json['mid'] != test['generated']:
- errors += 1
- sys.stderr.write("""[FAIL] %s, index %2u: Expected '%s', got '%s'!\n""" %
- (gen_type, key, test['generated'], json['mid']))
- else:
- print("[PASS] %s index %u" % (gen_type, key))
+ while len(mboxfiles) > 0:
+ mboxfile = mboxfiles.pop(0)
+ sys.stderr.write("Starting to process %s\n" % mboxfile)
+ mbox = mailbox.mbox(mboxfile, None if args.nomboxo else MboxoFactory, create=False)
+ no_messages = len(mbox.keys())
+ no_tests = len(tests)
+ if no_messages != no_tests:
+ sys.stderr.write("Warning: %s run for %s contains %u tests, but mbox file has %u emails!\n" %
+ (gen_type, mboxfile, no_tests, no_messages))
+ for test in tests:
+ tests_run += 1
+ key = test['index']
+ message_raw = _raw(args, mbox, key)
+ message = mbox.get(key)
+ msgid =(message.get('message-id') or '').strip()
+ if msgid != test['message-id']:
+ sys.stderr.write("""[SEQ?] %s, index %2u: Expected '%s', got '%s'!\n""" %
+ (gen_type, key, test['message-id'], msgid))
+ continue # no point continuing
+ lid = args.lid or archiver.normalize_lid(message.get('list-id', '??'))
+ json = archie.compute_updates(fake_args, lid, False, message, message_raw)
+
+ if json['mid'] != test['generated']:
+ errors += 1
+ sys.stderr.write("""[FAIL] %s, index %2u: Expected '%s', got '%s'!\n""" %
+ (gen_type, key, test['generated'], json['mid']))
+ else:
+ print("[PASS] %s index %u" % (gen_type, key))
+ mboxfiles = [] # reset for the next set of tests
print("[DONE] %u tests run, %u failed." % (tests_run, errors))
if errors:
sys.exit(-1)
diff --git a/tests/test-parsing.py b/tests/test-parsing.py
index 7c1fbb1..b95a46c 100755
--- a/tests/test-parsing.py
+++ b/tests/test-parsing.py
@@ -80,40 +80,48 @@ def run_tests(args):
test_args = collections.namedtuple('testargs', ['parse_html'])(parse_html)
archie = interfacer.Archiver(archiver, test_args)
- for mboxfile, tests in yml['parsing'].items():
- mbox = mailbox.mbox(mboxfile, None if args.nomboxo else MboxoFactory, create=False)
- no_messages = len(mbox.keys())
- no_tests = len(tests)
- if no_messages != no_tests:
- sys.stderr.write("Warning: %s run for parsing test of %s contains %u tests, but mbox file has %u emails!\n" %
- ('TBA', mboxfile, no_tests, no_messages))
- for test in tests:
- tests_run += 1
- key = test['index']
- message_raw = _raw(args, mbox, key)
- message = mbox.get(key)
- msgid =(message.get('message-id') or '').strip()
- if msgid != test['message-id']:
- sys.stderr.write("""[SEQ?] index %2u: Expected '%s', got '%s'!\n""" %
- (key, test['message-id'], msgid))
- continue # no point continuing
- lid = archiver.normalize_lid(message.get('list-id', '??'))
- json = archie.compute_updates(fake_args, lid, False, message, message_raw)
- body_sha3_256 = None
- if json and json.get('body') is not None:
- body_sha3_256 = hashlib.sha3_256(json['body'].encode('utf-8')).hexdigest()
- if body_sha3_256 != test['body_sha3_256']:
- errors += 1
- sys.stderr.write("""[FAIL] parsing index %2u: Expected: %s Got: %s\n""" %
- (key, test['body_sha3_256'], body_sha3_256))
- att = json['attachments'] if json else []
- att_expected = test['attachments'] or []
- if att != att_expected:
- errors += 1
- sys.stderr.write("""[FAIL] attachments index %2u: Expected: %s Got: %s\n""" %
- (key, att_expected, att))
- else:
- print("[PASS] index %u" % (key))
+ mboxfiles = []
+
+ for file, tests in yml['parsing'].items():
+ mboxfiles.append(file)
+ if not tests: # No tests under this filename, run same tests as next
+ continue
+ for mboxfile in mboxfiles:
+ sys.stderr.write("Starting to process %s\n" % mboxfile)
+ mbox = mailbox.mbox(mboxfile, None if args.nomboxo else MboxoFactory, create=False)
+ no_messages = len(mbox.keys())
+ no_tests = len(tests)
+ if no_messages != no_tests:
+ sys.stderr.write("Warning: %s run for parsing test of %s contains %u tests, but mbox file has %u emails!\n" %
+ ('TBA', mboxfile, no_tests, no_messages))
+ for test in tests:
+ tests_run += 1
+ key = test['index']
+ message_raw = _raw(args, mbox, key)
+ message = mbox.get(key)
+ msgid =(message.get('message-id') or '').strip()
+ if msgid != test['message-id']:
+ sys.stderr.write("""[SEQ?] index %2u: Expected '%s', got '%s'!\n""" %
+ (key, test['message-id'], msgid))
+ continue # no point continuing
+ lid = archiver.normalize_lid(message.get('list-id', '??'))
+ json = archie.compute_updates(fake_args, lid, False, message, message_raw)
+ body_sha3_256 = None
+ if json and json.get('body') is not None:
+ body_sha3_256 = hashlib.sha3_256(json['body'].encode('utf-8')).hexdigest()
+ if body_sha3_256 != test['body_sha3_256']:
+ errors += 1
+ sys.stderr.write("""[FAIL] parsing index %2u: Expected: %s Got: %s\n""" %
+ (key, test['body_sha3_256'], body_sha3_256))
+ att = json['attachments'] if json else []
+ att_expected = test['attachments'] or []
+ if att != att_expected:
+ errors += 1
+ sys.stderr.write("""[FAIL] attachments index %2u: Expected: %s Got: %s\n""" %
+ (key, att_expected, att))
+ else:
+ print("[PASS] index %u" % (key))
+ mboxfiles = []
print("[DONE] %u tests run, %u failed." % (tests_run, errors))
if errors:
sys.exit(-1)