diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-15 06:28:30 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-15 06:28:30 -0400 |
commit | be91f38ab4ccdba6006106d45fd7061db2110470 (patch) | |
tree | 25874de7e90c34224c842e6b716ca9e82fe01028 /test/RegressTests.py | |
parent | f3bedb88b24ae8b2047ad86e57b161265c2812f5 (diff) | |
parent | 968a6f3c0ac4690a6fc74e8d84058bce91019c2e (diff) | |
download | ledger-be91f38ab4ccdba6006106d45fd7061db2110470.tar.gz ledger-be91f38ab4ccdba6006106d45fd7061db2110470.tar.bz2 ledger-be91f38ab4ccdba6006106d45fd7061db2110470.zip |
Merge branch 'next'
Diffstat (limited to 'test/RegressTests.py')
-rwxr-xr-x | test/RegressTests.py | 63 |
1 files changed, 46 insertions, 17 deletions
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() |