def testSimpleReport(self): ledger = self.parser.parse_ledger(fixture_path("simple.dat")) sorting = Sorting(lambda x: x) report = self.report_factory(ledger, RuleCollection(), Filter.null, sorting) self.assertEqual( [(u'Assets:Bank', Value.parse("1465 EUR")), (u'Equity:Capital', Value.parse("-1500 EUR")), (u'Expenses:Books', Value.parse("35 EUR"))], [(record.account, record.amount) for record in report.generate() if record.account])
def testCompact(self): ledger = self.parser.parse_ledger(fixture_path("simple.dat")) processor = LedgerProcessor(ledger, self.rules) entry = ledger.transactions[1].entries[0] self.assertEqual(Value.parse("35 EUR"), entry.amount) # add entry entry2 = Entry(entry.account, Value.parse("-5 EUR")) ledger.transactions[1].entries.append(entry2) # rebalance transaction ledger.transactions[1].entries[1].amount += Value.parse("5 EUR") collector = TransactionCollector() processor.add_listener(collector) processor.run() self.assertEqual(2, len(collector.transactions)) _, entries = collector.transactions[1] self.assertEqual(2, len(entries)) self.assertEqual(Value.parse("30 EUR"), entries[0].amount)
def testSimpleReport(self): ledger = self.parser.parse_ledger(fixture_path("simple.dat")) sorting = MapSorting(lambda x: x.date) report = self.report_factory(ledger, RuleCollection(), Filter.null, sorting) records = list(report.generate()) self.assertEqual(4, len(records)) self.assertEqual( [(u'Assets:Bank', Value.parse('1500 EUR'), Value.parse('1500 EUR')), (u'Equity:Capital', Value.parse('-1500 EUR'), ZERO), (u'Expenses:Books', Value.parse('35 EUR'), Value.parse('35 EUR')), (u'Assets:Bank', Value.parse('-35 EUR'), ZERO)], [(record.entry.account.name, record.entry.amount, record.total) for record in records])
def parse_value(self, str): return Value.parse(str)
def testPrintNegativeValue(self): value = Value.parse("-44 EUR") self.assertRegexpMatches(self.template.print_value(value), r'^ *\S+-44.00 EUR\S+$')
def testPrintValue(self): value = Value.parse("44 EUR") self.assertRegexpMatches(self.template.print_value(value), r'^ *44.00 EUR$')
def testParsePrecision(self): value = Value.parse("1.4123 GBP") self.assertEqual(4, value.precision)
def testParsing(self): value = Value({ "EUR": Decimal("35.1") }) self.assertEqual(value, Value.parse("35.1 EUR"))
def testParsePositive(self): value = Value.parse("3819 USD") self.assertEqual(2, value.precision)
def testNegative(self): value = Value({ "EUR": Decimal("31.99") }) self.assertFalse(value.negative()) self.assertTrue((-value).negative())
def testComponents(self): value = Value({ "EUR": Decimal("31.99") }) self.assertEqual([value], list(value.components())) self.assertEqual([value], list(value.components(["EUR"]))) self.assertEqual([ZERO], list(value.components(["USD"]))) self.assertEqual([ZERO], list(value.components([])))
def testCurrencies(self): value = Value({ "EUR": Decimal("21.36") }) self.assertEqual(["EUR"], list(value.currencies()))
def testParseInvalidDecimal(self): self.assertRaises(ValueError, Value.parse("12.1.1 EUR"))
def testParseNoCurrency(self): self.assertRaises(InvalidOperation, Value.parse("35.1"))
def testEntryParser(self): entry = self.parser.parse_entry(" Expenses:Books 61 EUR ; :gift:") self.assertEqual("Expenses:Books", entry.account.name) self.assertEqual(Value.parse("61 EUR"), entry.amount) self.assertItemsEqual(["gift"], entry.tags.keys())
def testParseNegative(self): value = Value.parse("-440 EUR") self.assertEqual(2, value.precision)
def testComponents(self): value1 = Value({ "EUR" : Decimal("81.45") }) value2 = Value({ "USD" : Decimal("-12.44") }) value = Value({"EUR" : Decimal("81.45"), "USD" : Decimal("-12.44") }) self.assertItemsEqual([value1, value2], value.components())