Ejemplo n.º 1
0
 def test_balance_with_zero_posting(self):
     meta = data.new_metadata(__file__, 0)
     entry = data.Transaction(meta, None, None, None, None, None, None, [
         P(None, "Income:US:Anthem:InsurancePayments", "0", "USD"),
         P(None, "Income:US:Anthem:InsurancePayments", None, None),
         ])
     new_postings, has_inserted, errors, _, __ = interpolate.get_incomplete_postings(
         entry, OPTIONS_MAP)
     self.assertFalse(has_inserted)
     self.assertEqual(1, len(new_postings))
     self.assertEqual(0, len(errors))
Ejemplo n.º 2
0
    def test_get_incomplete_postings_residual(self):
        meta = data.new_metadata(__file__, 0)

        # Test with a single auto-posting with a residual.
        entry = data.Transaction(meta, None, None, None, None, None, None, [
            P(None, "Assets:Bank:Checking", "105.50", "USD"),
            P(None, "Assets:Bank:Savings", "-115.501", "USD"),
            P(None, "Assets:Bank:Balancing", "10.00", "USD"),
            ])
        _, __, ___, residual, ____ = interpolate.get_incomplete_postings(entry, OPTIONS_MAP)
        self.assertEqual(inventory.from_string('-0.001 USD'), residual)
Ejemplo n.º 3
0
    def test_balance_with_large_amount(self):
        meta = data.new_metadata(__file__, 0)

        # Test with a single auto-posting with a residual.
        entry = data.Transaction(meta, None, None, None, None, None, None, [
            P(None, "Income:US:Anthem:InsurancePayments", "-275.81", "USD"),
            P(None, "Income:US:Anthem:InsurancePayments", "-23738.54", "USD"),
            P(None, "Assets:Bank:Checking", "24014.45", "USD"),
            ])
        new_postings, has_inserted, errors, _, __ = interpolate.get_incomplete_postings(
            entry, OPTIONS_MAP)
        self.assertFalse(has_inserted)
        self.assertEqual(3, len(new_postings))
        self.assertEqual(1 if ERRORS_ON_RESIDUAL else 0, len(errors))
Ejemplo n.º 4
0
    def test_get_incomplete_postings_normal(self):
        meta = data.new_metadata(__file__, 0)

        # Test with a single auto-posting with a residual.
        entry = data.Transaction(meta, None, None, None, None, None, None, [
            P(None, "Assets:Bank:Checking", "105.50", "USD"),
            P(None, "Assets:Bank:Savings", "-115.50", "USD"),
            P(None, "Assets:Bank:Balancing", None, None),
            ])
        new_postings, has_inserted, errors, _, __ = interpolate.get_incomplete_postings(
            entry, OPTIONS_MAP)
        self.assertTrue(has_inserted)
        self.assertEqual(3, len(new_postings))
        self.assertEqual(0, len(errors))
        self.assertTrue(interpolate.AUTOMATIC_META in new_postings[2].meta)
Ejemplo n.º 5
0
    def test_get_incomplete_postings_pathological(self):
        meta = data.new_metadata(__file__, 0)

        # Test with no entries.
        entry = data.Transaction(meta, None, None, None, None, None, None, [])
        new_postings, has_inserted, errors, _, __ = interpolate.get_incomplete_postings(
            entry, OPTIONS_MAP)
        self.assertFalse(has_inserted)
        self.assertEqual(0, len(new_postings))
        self.assertEqual(0, len(errors))

        # Test with only a single leg (and check that it does not balance).
        entry = data.Transaction(meta, None, None, None, None, None, None, [
            P(None, "Assets:Bank:Checking", "105.50", "USD"),
            ])
        (new_postings, has_inserted, errors,
         residual, tolerances) = interpolate.get_incomplete_postings(
            entry, OPTIONS_MAP)
        self.assertFalse(has_inserted)
        self.assertEqual(1, len(new_postings))
        self.assertEqual(1 if ERRORS_ON_RESIDUAL else 0, len(errors))
        self.assertIsInstance(tolerances, dict)

        # Test with two legs that balance.
        entry = data.Transaction(meta, None, None, None, None, None, None, [
            P(None, "Assets:Bank:Checking", "105.50", "USD"),
            P(None, "Assets:Bank:Savings", "-105.50", "USD"),
            ])
        new_postings, has_inserted, errors, _, __ = interpolate.get_incomplete_postings(
            entry, OPTIONS_MAP)
        self.assertFalse(has_inserted)
        self.assertEqual(2, len(new_postings))
        self.assertEqual(0, len(errors))

        # Test with two legs that do not balance.
        entry = data.Transaction(meta, None, None, None, None, None, None, [
            P(None, "Assets:Bank:Checking", "105.50", "USD"),
            P(None, "Assets:Bank:Savings", "-115.50", "USD"),
            ])
        new_postings, has_inserted, errors, _, __ = interpolate.get_incomplete_postings(
            entry, OPTIONS_MAP)
        self.assertFalse(has_inserted)
        self.assertEqual(2, len(new_postings))
        self.assertEqual(1 if ERRORS_ON_RESIDUAL else 0, len(errors))

        # Test with only one auto-posting.
        entry = data.Transaction(meta, None, None, None, None, None, None, [
            P(None, "Assets:Bank:Checking", None, None),
            ])
        new_postings, has_inserted, errors, _, __ = interpolate.get_incomplete_postings(
            entry, OPTIONS_MAP)
        self.assertFalse(has_inserted)
        self.assertEqual(0, len(new_postings))
        self.assertEqual(1, len(errors))

        # Test with an auto-posting where there is no residual.
        entry = data.Transaction(meta, None, None, None, None, None, None, [
            P(None, "Assets:Bank:Checking", "105.50", "USD"),
            P(None, "Assets:Bank:Savings", "-105.50", "USD"),
            P(None, "Assets:Bank:Balancing", None, None),
            ])
        new_postings, has_inserted, errors, _, __ = interpolate.get_incomplete_postings(
            entry, OPTIONS_MAP)
        self.assertTrue(has_inserted)
        self.assertEqual(3, len(new_postings))
        self.assertEqual(1, len(errors))

        # Test with too many empty postings.
        entry = data.Transaction(meta, None, None, None, None, None, None, [
            P(None, "Assets:Bank:Checking", "105.50", "USD"),
            P(None, "Assets:Bank:Savings", "-106.50", "USD"),
            P(None, "Assets:Bank:BalancingA", None, None),
            P(None, "Assets:Bank:BalancingB", None, None),
            ])
        new_postings, has_inserted, errors, _, __ = interpolate.get_incomplete_postings(
            entry, OPTIONS_MAP)
        self.assertTrue(has_inserted)
        self.assertEqual(3, len(new_postings))
        self.assertEqual(1, len(errors))