GnuCash  5.6-150-g038405b370+
test_split.py
1 from unittest import main
2 
3 from gnucash import Book, Account, Split, Transaction
4 from unittest_support import *
5 
6 from test_book import BookSession
7 
9  def setUp(self):
10 
11  BookSession.setUp(self)
12  self.split = Split(self.book)
13 
14  def tearDown(self):
15  pass
16 
17 class TestSplit(SplitSession):
18  def test_memo(self):
19  MEMO = "cookie monster"
20  self.assertEqual( '', self.split.GetMemo() )
21  self.split.SetMemo(MEMO)
22  self.assertEqual( MEMO, self.split.GetMemo() )
23 
24  def test_account(self):
25  ACCT = Account(self.book)
26  ACCT.SetCommodity(self.currency)
27  self.split.SetAccount(ACCT)
28  self.assertTrue( ACCT.Equal(self.split.GetAccount(), True) )
29 
30  def test_transaction(self):
31  domain1 = "gnc.engine.scrub"
32  msg1 = "[xaccScrubUtilityGetOrMakeAccount()] No currency specified!"
33  level = G_LOG_LEVEL_CRITICAL
34  check1 = TestErrorStruct()
35  check1.log_domain = domain1
36  check1.log_level = level
37  check1.msg = msg1
38  hdlr1 = test_set_checked_handler(domain1, level, check1)
39  domain2 = "gnc.engine"
40  msg2 = "[xaccTransScrubSplits()] Transaction doesn't have a currency!"
41  level = G_LOG_LEVEL_CRITICAL
42  check2 = TestErrorStruct()
43  check2.log_domain = domain2
44  check2.log_level = level
45  check2.msg = msg2
46  hdlr2 = test_set_checked_handler(domain2, level, check2)
47 
48  TRANS = Transaction(self.book)
49  self.split.SetParent(TRANS)
50  TRANS.SetCurrency(self.currency)
51  TRANS.SetDescription("Foo")
52  self.assertEqual( TRANS.GetDescription(), self.split.GetParent().GetDescription() )
53 
54  g_log_remove_handler(domain2, hdlr2)
55  g_log_remove_handler(domain1, hdlr1)
56 
57  def test_equal(self):
58  COPY = self.split
59  self.assertTrue( self.split.Equal(COPY, True, False, False) )
60  # test __eq__ implementation
61  TRANS = Transaction(self.book)
62  self.split.SetParent(TRANS)
63  self.assertTrue( self.split == TRANS.GetSplitList()[0] )
64  self.assertTrue( self.split != Split(self.book) )
65 
66 if __name__ == '__main__':
67  main()
Struct to pass as user_data for the handlers.