import unittest
from reconcile import DEMO, reconcile


class ReconcileTests(unittest.TestCase):
    def test_demo(self):
        result = reconcile(DEMO + [DEMO[0]], "paper-17")
        self.assertEqual([r["amount"] for r in result["attributed_costs"]], ["40.00", "25.00"])
        self.assertEqual(len(result["needs_review"]), 2)
        self.assertEqual(len(result["excluded"]), 1)

    def test_conflicting_duplicate(self):
        with self.assertRaises(ValueError):
            reconcile([DEMO[0], {**DEMO[0], "amount": "41"}], "paper-17")

    def test_currency_and_other_paper(self):
        rows = [DEMO[0], {**DEMO[0], "line_id": "eur", "currency": "EUR"}, {**DEMO[0], "line_id": "other", "paper": "paper-18"}]
        self.assertEqual(len(reconcile(rows, "paper-17")["attributed_costs"]), 2)

    def test_reject_nonfinite(self):
        with self.assertRaises(ValueError):
            reconcile([{**DEMO[0], "amount": "NaN"}], "paper-17")


if __name__ == "__main__":
    unittest.main()
