コード例 #1
0
 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)
コード例 #2
0
 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)
コード例 #3
0
 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)
コード例 #4
0
 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)
コード例 #5
0
 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("$", "")))
コード例 #6
0
 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)
コード例 #7
0
 def dummyAdd(self, accountName, valueStr):
     t = Transaction("2000/01/01", "Test", self.root)
     t.addItem(accountName, valueStr)
     t.addItem("Dummy")
     t.commit()
コード例 #8
0
 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)
コード例 #9
0
 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