diff options
Diffstat (limited to 'test/ConfirmTests.py')
-rwxr-xr-x | test/ConfirmTests.py | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/test/ConfirmTests.py b/test/ConfirmTests.py index e82479ed..54187130 100755 --- a/test/ConfirmTests.py +++ b/test/ConfirmTests.py @@ -1,20 +1,24 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # This script confirms both that the register report "adds up", and that its # final balance is the same as what the balance report shows. +import argparse +import pathlib import sys import os import re from LedgerHarness import LedgerHarness -harness = LedgerHarness(sys.argv) -tests = sys.argv[3] +parser = argparse.ArgumentParser(prog='ConfirmTests', parents=[LedgerHarness.parser()]) +parser.add_argument('tests', type=pathlib.Path) +args = parser.parse_args() +harness = LedgerHarness(args.ledger, args.sourcepath, args.verify, args.gmalloc, args.python) -if not os.path.isdir(tests) and not os.path.isfile(tests): - sys.stderr.write("'%s' is not a directory or file (cwd %s)" % - (tests, os.getcwd())) +if not os.path.isdir(args.tests) and not os.path.isfile(args.tests): + print(f'{args.tests} is not a directory or file (cwd: {os.getcwd()})' + , file=sys.stderr) sys.exit(1) commands = [ @@ -56,8 +60,8 @@ def confirm_report(command): if re.search(' -[VGB] ', command) and diff < 0.015: diff = 0.0 if diff > 0.001: - print("DISCREPANCY: %.3f (%.3f - %.3f) at line %d:" % \) - (running_total - total, running_total, total, index) + print("DISCREPANCY: %.3f (%.3f - %.3f) at line %d:" % \ + (running_total - total, running_total, total, index)) print(line,) running_total = total failure = True @@ -78,15 +82,15 @@ def confirm_report(command): diff = 0.0 if diff > 0.001: print() - print("DISCREPANCY: %.3f (%.3f - %.3f) between register and balance" % \) - (balance_total - running_total, balance_total, running_total) + print("DISCREPANCY: %.3f (%.3f - %.3f) between register and balance" % \ + (balance_total - running_total, balance_total, running_total)) print(last_line,) failure = True return not failure for cmd in commands: - if confirm_report('$ledger --rounding $cmd ' + re.sub('\$tests', tests, cmd)): + if confirm_report('$ledger --rounding $cmd ' + re.sub('\$tests', str(args.tests), cmd)): harness.success() else: harness.failure() |