You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2020/08/15 05:45:00 UTC

[incubator-ponymail-unit-tests] branch master updated: Make master compatible with both Foal and Pony 0.12

This is an automated email from the ASF dual-hosted git repository.

humbedooh 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 d3bd5eb  Make master compatible with both Foal and Pony 0.12
d3bd5eb is described below

commit d3bd5ebcb09dad1b0c9889b9033b077c4dccd428
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Sat Aug 15 07:44:48 2020 +0200

    Make master compatible with both Foal and Pony 0.12
    
    Why not just be smart here... :)
---
 tests/test-generators.py | 29 ++++++++++++++++++++++++++---
 tests/test-parsing.py    | 17 +++++++++++++++--
 2 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/tests/test-generators.py b/tests/test-generators.py
index 1a8f362..a8f4e89 100644
--- a/tests/test-generators.py
+++ b/tests/test-generators.py
@@ -9,6 +9,7 @@ import mailbox
 import yaml
 import argparse
 import collections
+import inspect
 
 parse_html = False
 nonce = None
@@ -17,8 +18,12 @@ fake_args = collections.namedtuple('fakeargs', ['verbose', 'ibody'])(False, None
 
 def generate_specs(args):
     import archiver
-    import generators
+    try:
+        import generators
+    except:
+        import plugins.generators as generators
     archie = archiver.Archiver(parse_html=parse_html)
+    expected_parameters = inspect.signature(archie.compute_updates).parameters
     yml = {}
     for gen_type in generators.generator_names():
         sys.stderr.write("Generating specs for type '%s'...\n" % gen_type)
@@ -29,7 +34,12 @@ def generate_specs(args):
             message_raw = mbox.get_bytes(key)  # True raw format, as opposed to calling .as_bytes()
             message = mbox.get(key)
             lid = args.lid or archiver.normalize_lid(message.get('list-id', '??'))
-            json, _, _, _ = archie.compute_updates(fake_args, lid, False, message, message_raw)
+            # Foal parameters
+            if 'raw_msg' in expected_parameters:
+                json, _, _, _ = archie.compute_updates(fake_args, lid, False, message, message_raw)
+            # PM <= 0.12 parameters
+            else:
+                json, _, _, _ = archie.compute_updates(fake_args, lid, False, message)
             gen_spec.append({
                 'index': key,
                 'message-id': message.get('message-id').strip(),
@@ -43,12 +53,20 @@ def generate_specs(args):
 
 def run_tests(args):
     import archiver
+    try:
+        import generators
+    except:
+        import plugins.generators as generators
     errors = 0
     tests_run = 0
     yml = yaml.safe_load(open(args.load, 'r'))
     for mboxfile, run in yml['generators'].items():
         for gen_type, tests in run.items():
+            if gen_type not in generators.generator_names():
+                sys.stderr.write("Warning: generators.py does not have the '%s' generator, skipping tests\n" % gen_type)
+                continue
             archie = archiver.Archiver(generator=gen_type, parse_html=parse_html)
+            expected_parameters = inspect.signature(archie.compute_updates).parameters
             mbox = mailbox.mbox(mboxfile, None, create=False)
             no_messages = len(mbox.keys())
             no_tests = len(tests)
@@ -60,7 +78,12 @@ def run_tests(args):
                 message_raw = mbox.get_bytes(test['index'])  # True raw format, as opposed to calling .as_bytes()
                 message = mbox.get(test['index'])
                 lid = args.lid or archiver.normalize_lid(message.get('list-id', '??'))
-                json, _, _, _ = archie.compute_updates(fake_args, lid, False, message, message_raw)
+                # Foal parameters
+                if 'raw_msg' in expected_parameters:
+                    json, _, _, _ = archie.compute_updates(fake_args, lid, False, message, message_raw)
+                # PM <= 0.12 parameters
+                else:
+                    json, _, _, _ = archie.compute_updates(fake_args, lid, False, message)
                 if json['mid'] != test['generated']:
                     errors += 1
                     sys.stderr.write("""[FAIL] %s, index %u: Expected '%s', got '%s'!\n""" %
diff --git a/tests/test-parsing.py b/tests/test-parsing.py
index 8c0e8b1..7a9a6b2 100644
--- a/tests/test-parsing.py
+++ b/tests/test-parsing.py
@@ -10,6 +10,7 @@ import yaml
 import argparse
 import collections
 import hashlib
+import inspect
 
 nonce = None
 fake_args = collections.namedtuple('fakeargs', ['verbose', 'ibody'])(False, None)
@@ -18,6 +19,7 @@ fake_args = collections.namedtuple('fakeargs', ['verbose', 'ibody'])(False, None
 def generate_specs(args):
     import archiver
     archie = archiver.Archiver(parse_html=args.html)
+    expected_parameters = inspect.signature(archie.compute_updates).parameters
     sys.stderr.write("Generating parsing specs for file '%s'...\n" % args.mboxfile)
     items = {}
     for mboxfile in args.mboxfile:
@@ -27,7 +29,12 @@ def generate_specs(args):
             message_raw = mbox.get_bytes(key)  # True raw format, as opposed to calling .as_bytes()
             message = mbox.get(key)
             lid = archiver.normalize_lid(message.get('list-id', '??'))
-            json, _, _, _ = archie.compute_updates(fake_args, lid, False, message, message_raw)
+            # Foal parameters
+            if 'raw_msg' in expected_parameters:
+                json, _, _, _ = archie.compute_updates(fake_args, lid, False, message, message_raw)
+            # PM <= 0.12 parameters
+            else:
+                json, _, _, _ = archie.compute_updates(fake_args, lid, False, message)
             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()
@@ -50,6 +57,7 @@ def run_tests(args):
     yml = yaml.safe_load(open(args.load, 'r'))
     parse_html = yml.get('args', {}).get('parse_html', False)
     archie = archiver.Archiver(parse_html=parse_html)
+    expected_parameters = inspect.signature(archie.compute_updates).parameters
     for mboxfile, tests in yml['parsing'].items():
         mbox = mailbox.mbox(mboxfile, None, create=False)
         no_messages = len(mbox.keys())
@@ -62,7 +70,12 @@ def run_tests(args):
             message_raw = mbox.get_bytes(test['index'])  # True raw format, as opposed to calling .as_bytes()
             message = mbox.get(test['index'])
             lid = archiver.normalize_lid(message.get('list-id', '??'))
-            json, _, _, _ = archie.compute_updates(fake_args, lid, False, message, message_raw)
+            # Foal parameters
+            if 'raw_msg' in expected_parameters:
+                json, _, _, _ = archie.compute_updates(fake_args, lid, False, message, message_raw)
+            # PM <= 0.12 parameters
+            else:
+                json, _, _, _ = archie.compute_updates(fake_args, lid, False, message)
             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()