def testClone(self): value = self.parser.parse_value("40 EUR") entry1 = Entry(self.bank, value) entry2 = Entry(self.expenses, None) tr = Transaction([entry1, entry2]) tr2 = tr.clone() self.assertFalse(id(tr) == id(tr2)) self.assertItemsEqual(tr.entries, tr2.entries) self.assertEqual(tr.date, tr2.date) self.assertEqual(tr.label, tr2.label)
def parse_transaction(self, lines): if hasattr(lines, "split"): lines = list(itertools.izip(itertools.count(1), iter(lines.split("\n")))) tags = { } # discard initial comments while lines and re.match(r'\s*;', lines[0][1]): lines = lines[1:] if len(lines) == 0: return None n, header = lines[0] lines = lines[1:] # skip rules if len(header) == 0 or header[0] == "=": return None directive = self.parse_directive(header) if directive: return directive # parse transaction tags if lines: n, line = lines[0] tags = self.parse_tags(line, begin=True) if tags: lines = lines[1:] try: date, label, cleared = self.parse_header(header) date = self.parse_date(date) if date is None: raise MalformedHeader() entries = [self.parse_entry(line) for n, line in lines] entries = [e for e in entries if e is not None] line_numbers = [n for n, line in lines] transaction = Transaction(entries, date, label) if tags: transaction.tags = tags if cleared: transaction.tags["cleared"] = True return transaction except UnbalancedTransaction, e: e.line_number = n raise
def testTransactionAccountFilter(self): filter = Transaction.account_tag_filter("foo", "bar") self.assertTrue(filter(self.tr, None))
def testTransactionTagFilterWrong(self): filter = Transaction.tag_filter("foo", None) self.assertFalse(filter(self.tr, self.bank)) self.assertFalse(filter(self.tr, self.books)) self.assertFalse(filter(self.tr, None))
def testTransactionTagFilterEmpty(self): filter = Transaction.tag_filter("baz", None) self.assertTrue(filter(self.tr, self.bank)) self.assertTrue(filter(self.tr, self.books)) self.assertTrue(filter(self.tr, None))
def testTransactionTagFilter(self): filter = Transaction.tag_filter("baz", "hello world") self.assertTrue(filter(self.tr, self.bank)) self.assertTrue(filter(self.tr, self.books)) self.assertTrue(filter(self.tr, None))