Example #1
0
    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])
Example #2
0
    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)
Example #3
0
    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])
Example #4
0
 def parse_value(self, str):
     return Value.parse(str)
Example #5
0
 def testPrintNegativeValue(self):
     value = Value.parse("-44 EUR")
     self.assertRegexpMatches(self.template.print_value(value), r'^ *\S+-44.00 EUR\S+$')
Example #6
0
 def testPrintValue(self):
     value = Value.parse("44 EUR")
     self.assertRegexpMatches(self.template.print_value(value), r'^ *44.00 EUR$')
Example #7
0
 def testParsePrecision(self):
     value = Value.parse("1.4123 GBP")
     self.assertEqual(4, value.precision)
Example #8
0
 def testParsing(self):
     value = Value({ "EUR": Decimal("35.1") })
     self.assertEqual(value, Value.parse("35.1 EUR"))
Example #9
0
 def testParsePositive(self):
     value = Value.parse("3819 USD")
     self.assertEqual(2, value.precision)
Example #10
0
 def testNegative(self):
     value = Value({ "EUR": Decimal("31.99") })
     self.assertFalse(value.negative())
     self.assertTrue((-value).negative())
Example #11
0
 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([])))
Example #12
0
 def testCurrencies(self):
     value = Value({ "EUR": Decimal("21.36") })
     self.assertEqual(["EUR"], list(value.currencies()))
Example #13
0
 def testParseInvalidDecimal(self):
     self.assertRaises(ValueError, Value.parse("12.1.1 EUR"))
Example #14
0
 def testParseNoCurrency(self):
     self.assertRaises(InvalidOperation, Value.parse("35.1"))
Example #15
0
 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())
Example #16
0
 def testParseNegative(self):
     value = Value.parse("-440 EUR")
     self.assertEqual(2, value.precision)
Example #17
0
 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())