def test_transaction_decimal(self): t = Transaction("2000/01/01", "title", self.root) t.addItem("Assets", "$103.020406") t.addItem("Assets", "$20.103050") t.addItem("Expenses", "$-123.123456") t.commit() self.assertEqual( self.root.getAccount("Assets").getValue("$"), 123.123456)
def test_conversion_total(self): t = Transaction("2000/01/01", "title", self.root) t.addItem("Assets", "10 STOCK @@ $100") t.addItem("Assets") t.commit() self.assertEqual(self.root.getAccount("Assets").getValue("STOCK"), 10) self.assertEqual(self.root.getAccount("Assets").getValue("$"), -100)
def test_transaction(self): for i in range(1, 10): with self.subTest(i=i): t = Transaction("2000/01/01", "title", self.root) t.addItem("Assets", "$123") t.addItem("Expenses") t.commit() self.assertEqual( self.root.getAccount("Assets").getValue("$"), 123 * i) self.assertEqual( self.root.getAccount("Expenses").getValue("$"), -123 * i)
def test_validation_imblanced(self): accountName = "Assets" for value in (-10, 10): with self.subTest(value=value): t = Transaction("2000/01/01", "Test", Account()) t.addItem(accountName, str(value)) t.addItem("Dummy", "=0") self.assertRaises(ValueError, t.commit)
def test_quantity(self): q = 2 N = 10 for op in ["*", "-", "+", "/"]: t = Transaction("2000/01/01", "title", self.root) name = "Assets:" + op expr = "({} {} ${})".format(q, op, N) t.addItem(name, expr) t.addItem("Expenses") t.commit() self.assertEqual( self.root.getAccount(name).getValue("$"), eval(expr.replace("$", "")))
def test_validation_assert_equal_fail(self): t = Transaction("2000/01/01", "Test", self.root) t.addItem("Assets", "$1") t.addItem("Expenses", "$1") self.assertRaises(ValueError, t.commit)
def dummyAdd(self, accountName, valueStr): t = Transaction("2000/01/01", "Test", self.root) t.addItem(accountName, valueStr) t.addItem("Dummy") t.commit()
def test_init(self): t = Transaction("2000/01/01", "*", self.root) t.addItem("Assets", "$100") t.commit() self.assertEqual(self.root.getAccount("Assets").getValue("$"), 100)
def test_post_validation(self): t = Transaction("2000/01/01", "Test", self.root) t.addItem("Assets", "$100") t.addItem("Expenses") t.commit() t = Transaction("2000/01/01", "Test", self.root) t.addItem("Assets", "=$200") t.addItem("Expenses", "$10") try: t.commit() assert False except: pass