diff options
author | John Wiegley <johnw@newartisans.com> | 2006-08-21 02:39:33 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 02:41:32 -0400 |
commit | db0ef2e25731a824aa728315f2f7f6e8a41a5ddf (patch) | |
tree | 073a4ffe44699413d97e56bae001e2f69a8b9a04 /tests/confirm.py | |
parent | bec5f1c07af7948eb26a7cbafc6d191cfbb77d97 (diff) | |
download | fork-ledger-db0ef2e25731a824aa728315f2f7f6e8a41a5ddf.tar.gz fork-ledger-db0ef2e25731a824aa728315f2f7f6e8a41a5ddf.tar.bz2 fork-ledger-db0ef2e25731a824aa728315f2f7f6e8a41a5ddf.zip |
*** empty log message ***
Diffstat (limited to 'tests/confirm.py')
-rwxr-xr-x | tests/confirm.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/confirm.py b/tests/confirm.py new file mode 100755 index 00000000..0881001b --- /dev/null +++ b/tests/confirm.py @@ -0,0 +1,55 @@ +#!/usr/bin/python + +# This script confirms what ledger tells you. + +import sys +import os +import re + +def clean(num): + return float(re.sub("(\s+|\$|,)","", num)) + +running_total = 0.0 +index = 1 +last_line = "" +errors = 0 + +report = sys.argv[1] +for line in os.popen("./ledger -f utils/standard.dat -e 2004/4 %s reg %s" % + (report, sys.argv[2])): + value = clean(line[55:67]) + total = clean(line[68:]) + + running_total += value + diff = abs(running_total - total) + if report == "-V" or report == "-G" and diff < 0.015: + diff = 0.0 + if diff > 0.001: + print "! discrepancy of %.2f (%.2f - %.2f) at line %d:" % \ + (running_total - total, running_total, total, index) + print line, + running_total = total + errors += 1 + + index += 1 + last_line = line + +balance_total = 0.0 + +for line in os.popen("./ledger -f utils/standard.dat -e 2004/4 %s bal %s" % + (report, sys.argv[2])): + if line[0] != '-': + balance_total = clean(line[:20]) + +diff = abs(balance_total - running_total) +if report == "-V" or report == "-G" and diff < 0.015: + diff = 0.0 +if diff > 0.001: + print + print "! discrepancy of %.2f (%.2f - %.2f) between register and balance" % \ + (balance_total - running_total, balance_total, running_total) + print last_line, + print line, + errors += 1 + +sys.exit(errors) |