def test_abs(self): self.assertEqual(Amount(D('82.98'), 'CAD'), amount.abs(Amount(D('82.98'), 'CAD'))) self.assertEqual(Amount(D('0'), 'CAD'), amount.abs(Amount(D('0'), 'CAD'))) self.assertEqual(Amount(D('82.98'), 'CAD'), amount.abs(Amount(D('-82.98'), 'CAD')))
def main(): import argparse, logging logging.basicConfig(level=logging.INFO, format='%(levelname)-8s: %(message)s') parser = argparse.ArgumentParser(description=__doc__.strip()) parser.add_argument('filename_left', help='Left filename') parser.add_argument('regexp_left', help='Left account regexp') parser.add_argument('--tag', dest='tag_left', help='Tag to filter left file (optional)') parser.add_argument('filename_rght', help='Right filename') parser.add_argument('regexp_rght', help='Right account regexp') args = parser.parse_args() left_postings = get_postings(args.filename_left, args.regexp_left, args.tag_left) rght_postings = get_postings(args.filename_rght, args.regexp_rght) #print(len(left_postings), len(rght_postings)) # Progressively try different unique keys to match up postings to each other # unambiguously. for keyfun in [ lambda tp: amount.abs(tp.posting.units), lambda tp: tp.txn.links ]: _, (left_postings, rght_postings) = (match_postings(left_postings, rght_postings, keyfun)) print("Unmatched: {} left & {} right".format(len(left_postings), len(rght_postings))) print_unmatched(left_postings, args.filename_left, args.regexp_left) print_unmatched(rght_postings, args.filename_rght, args.regexp_rght)