JournalTest.py 742 B

12345678910111213141516171819202122232425262728293031
  1. # -*- coding: utf-8 -*-
  2. import unittest
  3. from ledger import *
  4. class JournalTestCase(unittest.TestCase):
  5. def tearDown(self):
  6. session.close_journal_files()
  7. def testBasicRead(self):
  8. journal = read_journal_from_string("""
  9. 2012-03-01 KFC
  10. Expenses:Food $21.34
  11. Assets:Cash
  12. """)
  13. self.assertEqual(type(journal), Journal)
  14. for xact in journal:
  15. self.assertEqual(xact.payee, "KFC")
  16. for post in journal.query("food"):
  17. self.assertEqual(str(post.account), "Expenses:Food")
  18. self.assertEqual(post.amount, Amount("$21.34"))
  19. def suite():
  20. return unittest.TestLoader().loadTestsFromTestCase(JournalTestCase)
  21. if __name__ == '__main__':
  22. unittest.main()