From fa263e729c65e073950a15db11c149ebacba0937 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 15 Jun 2010 01:41:51 -0400 Subject: Tests run in parallel with using acprep -jX make This is done using the multiprocessing library in Python 2.6. If that's unavailable, this feature does nothing. --- test/GenerateTests.py | 43 ++++++++++++++++++++++++++++++----- test/LedgerHarness.py | 21 +++++++++++++++++ test/RegressTests.py | 63 +++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 104 insertions(+), 23 deletions(-) (limited to 'test') diff --git a/test/GenerateTests.py b/test/GenerateTests.py index d60e0581..70baee28 100755 --- a/test/GenerateTests.py +++ b/test/GenerateTests.py @@ -4,13 +4,30 @@ # final balance is the same as what the balance report shows. import sys -#import re +import re from difflib import ndiff +multiproc = False +try: + from multiprocessing import Pool + multiproc = True +except: + pass + +args = sys.argv +jobs = 1 +match = re.match('-j([0-9]+)?', args[1]) +if match: + args = [args[0]] + args[2:] + if match.group(1): + jobs = int(match.group(1)) +if jobs == 1: + multiproc = False + from LedgerHarness import LedgerHarness -harness = LedgerHarness(sys.argv) +harness = LedgerHarness(args) #def normalize(line): # match = re.match("((\s*)([A-Za-z]+)?(\s*)([-0-9.]+)(\s*)([A-Za-z]+)?)( (.+))?$", line) @@ -104,14 +121,28 @@ def generation_test(seed): beg_range = 1 end_range = 20 -if len(sys.argv) > 4: - beg_range = int(sys.argv[3]) - end_range = int(sys.argv[4]) +if len(args) > 4: + beg_range = int(args[3]) + end_range = int(args[4]) -for i in range(beg_range, end_range): +def run_gen_test(i): if generation_test(i): harness.success() else: harness.failure() +if multiproc: + pool = Pool(jobs*2) +else: + pool = None + +if pool: + pool.map(run_gen_test, range(beg_range, end_range)) +else: + for i in range(beg_range, end_range): + run_gen_test(i) + +if pool: + pool.close() + pool.join() harness.exit() diff --git a/test/LedgerHarness.py b/test/LedgerHarness.py index ea8290d4..44e4e61c 100755 --- a/test/LedgerHarness.py +++ b/test/LedgerHarness.py @@ -6,6 +6,27 @@ import re from subprocess import Popen, PIPE +import copy_reg +import types + +def _pickle_method(method): + func_name = method.im_func.__name__ + obj = method.im_self + cls = method.im_class + return _unpickle_method, (func_name, obj, cls) + +def _unpickle_method(func_name, obj, cls): + for cls in cls.mro(): + try: + func = cls.__dict__[func_name] + except KeyError: + pass + else: + break + return func.__get__(obj, cls) + +copy_reg.pickle(types.MethodType, _pickle_method, _unpickle_method) + class LedgerHarness: ledger = None sourcepath = None diff --git a/test/RegressTests.py b/test/RegressTests.py index a32bdb6b..0472ac90 100755 --- a/test/RegressTests.py +++ b/test/RegressTests.py @@ -5,18 +5,35 @@ import os import re import tempfile +multiproc = False +try: + from multiprocessing import Pool + multiproc = True +except: + pass + from string import join from difflib import unified_diff from LedgerHarness import LedgerHarness -harness = LedgerHarness(sys.argv) -tests = sys.argv[3] +args = sys.argv +jobs = 1 +match = re.match('-j([0-9]+)?', args[1]) +if match: + args = [args[0]] + args[2:] + if match.group(1): + jobs = int(match.group(1)) +if jobs == 1: + multiproc = False + +harness = LedgerHarness(args) +tests = args[3] if not os.path.isdir(tests) and not os.path.isfile(tests): sys.exit(1) -class RegressFile: +class RegressFile(object): def __init__(self, filename): self.filename = filename self.fd = open(self.filename) @@ -137,24 +154,36 @@ class RegressFile: if not use_stdin: os.remove(tempdata[1]) - def run_tests(self): + def run_tests(self, pool): test = self.read_test() while test: - self.run_test(test) + if pool: + pool.apply_async(RegressFile.run_test, (self, test,)) + else: + self.run_test(test) test = self.read_test(test) def close(self): self.fd.close() -if os.path.isdir(tests): - for test_file in os.listdir(tests): - if re.search('\.test$', test_file): - entry = RegressFile(os.path.join(tests, test_file)) - entry.run_tests() - entry.close() -else: - entry = RegressFile(tests) - entry.run_tests() - entry.close() - -harness.exit() +if __name__ == '__main__': + if multiproc: + pool = Pool(jobs*2) + else: + pool = None + + if os.path.isdir(tests): + for test_file in os.listdir(tests): + if re.search('\.test$', test_file): + entry = RegressFile(os.path.join(tests, test_file)) + entry.run_tests(pool) + entry.close() + else: + entry = RegressFile(tests) + entry.run_tests(pool) + entry.close() + + if pool: + pool.close() + pool.join() + harness.exit() -- cgit v1.2.3 From 34fcc62b4df50893f66f9fc7ffe64de9149ef534 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 15 Jun 2010 04:28:03 -0400 Subject: Removed unused --unsorted option --- src/chain.cc | 6 ------ src/report.cc | 1 - src/report.h | 3 --- test/baseline/opt-lot-dates.test | 2 +- test/baseline/opt-lot-prices.test | 2 +- test/baseline/opt-lots.test | 2 +- 6 files changed, 3 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/src/chain.cc b/src/chain.cc index 49e0e470..64550663 100644 --- a/src/chain.cc +++ b/src/chain.cc @@ -188,12 +188,6 @@ post_handler_ptr chain_post_handlers(post_handler_ptr base_handler, else handler.reset(new sort_posts(handler, report.HANDLER(sort_).str())); } -#if 0 - else if (! report.HANDLED(period_) && - ! report.HANDLED(unsorted)) { - handler.reset(new sort_posts(handler, "date")); - } -#endif // collapse_posts causes xacts with multiple posts to appear as xacts // with a subtotaled post for each commodity used. diff --git a/src/report.cc b/src/report.cc index f7455440..9626283a 100644 --- a/src/report.cc +++ b/src/report.cc @@ -1040,7 +1040,6 @@ option_t * report_t::lookup_option(const char * p) else OPT(unrealized_gains_); else OPT(unrealized_losses_); else OPT(unround); - else OPT(unsorted); break; case 'w': OPT(weekly); diff --git a/src/report.h b/src/report.h index 6176c19b..eff375cc 100644 --- a/src/report.h +++ b/src/report.h @@ -315,7 +315,6 @@ public: HANDLER(unrealized_gains_).report(out); HANDLER(unrealized_losses_).report(out); HANDLER(unround).report(out); - HANDLER(unsorted).report(out); HANDLER(weekly).report(out); HANDLER(wide).report(out); HANDLER(yearly).report(out); @@ -914,8 +913,6 @@ public: .set_expr(string("--unround"), "unrounded(total_expr)"); }); - OPTION(report_t, unsorted); - OPTION_(report_t, weekly, DO() { // -W parent->HANDLER(period_).on(string("--weekly"), "weekly"); }); diff --git a/test/baseline/opt-lot-dates.test b/test/baseline/opt-lot-dates.test index 2415fb27..bf6dee0b 100644 --- a/test/baseline/opt-lot-dates.test +++ b/test/baseline/opt-lot-dates.test @@ -1,4 +1,4 @@ -reg -F '%(justify(scrub(total_expr), 80, 80, true))\n' --lot-dates --unsorted +reg -F '%(justify(scrub(total_expr), 80, 80, true))\n' --lot-dates <<< C 1.00s = 100c C 1.00G = 100s diff --git a/test/baseline/opt-lot-prices.test b/test/baseline/opt-lot-prices.test index 2fcc79f7..d5d7d11a 100644 --- a/test/baseline/opt-lot-prices.test +++ b/test/baseline/opt-lot-prices.test @@ -1,4 +1,4 @@ -reg -F '%(justify(scrub(total_expr), 80, 80, true))\n' --lot-prices --unsorted +reg -F '%(justify(scrub(total_expr), 80, 80, true))\n' --lot-prices <<< C 1.00s = 100c C 1.00G = 100s diff --git a/test/baseline/opt-lots.test b/test/baseline/opt-lots.test index 8e54e576..808afcc0 100644 --- a/test/baseline/opt-lots.test +++ b/test/baseline/opt-lots.test @@ -1,4 +1,4 @@ -reg -F '%(justify(scrub(total_expr), 80, 80, true))\n' --lots --unsorted +reg -F '%(justify(scrub(total_expr), 80, 80, true))\n' --lots <<< C 1.00s = 100c C 1.00G = 100s -- cgit v1.2.3