account.py (1377B)
1 import logging 2 import datetime 3 import unittest 4 import os 5 6 from usawa import UnitIndex 7 from usawa.account import AccountIndex 8 from usawa.error import AccountError 9 10 logging.basicConfig(level=logging.DEBUG) 11 logg = logging.getLogger() 12 13 testdir = os.path.realpath(os.path.dirname(__file__)) 14 15 class TestAccount(unittest.TestCase): 16 17 def setUp(self): 18 self.uidx = UnitIndex('FOO') 19 self.uidx.add('BAR') 20 21 def test_account_lock(self): 22 idx = AccountIndex(self.uidx) 23 # missing account type 24 with self.assertRaises(AttributeError): 25 idx.add('bar/baz', sym='FOO') 26 idx.add('liability/bar/baz', sym='FOO') 27 idx.add('liability/bar/baz', sym='FOO') 28 with self.assertRaises(AccountError): 29 idx.add('asset/bar/baz-', sym='FOO') 30 with self.assertRaises(AccountError): 31 idx.add('asset/foo/bar', sym='BAZ') 32 self.assertFalse(idx.check('BAR', 'liability/foo/baz')) 33 self.assertTrue(idx.check('FOO', 'liability/bar/baz')) 34 35 36 def test_account_list(self): 37 idx = AccountIndex(self.uidx) 38 idx.add('asset/bar/bar', sym='FOO') 39 idx.add('liability/bar/baz', sym='FOO') 40 idx.add('asset/foo/baz', sym='BAR') 41 v = list(idx) 42 logg.debug('results {}'.format(v)) 43 self.assertEqual(len(v), 3) 44 45 46 if __name__ == '__main__': 47 unittest.main()