GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
test_price_and_wrapping.TestGncLotSplitList Class Reference
Inheritance diagram for test_price_and_wrapping.TestGncLotSplitList:

Public Member Functions

 setUp (self)
 
 tearDown (self)
 
 test_lot_exists (self)
 
 test_get_split_list_returns_splits (self)
 

Data Fields

 ses
 
 book
 
 stock_acct
 

Detailed Description

Verify that GncLot.get_split_list() returns wrapped Split objects.

Creates a buy+sell pair on an account then scrubs lots, matching the
pattern in test_account.py's test_assignlots.

Definition at line 147 of file test_price_and_wrapping.py.

Member Function Documentation

◆ setUp()

test_price_and_wrapping.TestGncLotSplitList.setUp (   self)

Definition at line 154 of file test_price_and_wrapping.py.

154 def setUp(self):
155 self.ses = Session()
156 self.book = self.ses.get_book()
157 table = self.book.get_table()
158 currency = table.lookup("CURRENCY", "USD")
159
160 stock = GncCommodity(self.book, "Lot Test", "COMMODITY", "LTX", "LTX", 100000)
161 table.insert(stock)
162
163 self.stock_acct = Account(self.book)
164 self.stock_acct.SetCommodity(stock)
165 root = self.book.get_root_account()
166 root.append_child(self.stock_acct)
167
168 cash_acct = Account(self.book)
169 cash_acct.SetCommodity(currency)
170 root.append_child(cash_acct)
171
172 tx = Transaction(self.book)
173 tx.BeginEdit()
174 tx.SetCurrency(currency)
175 tx.SetDateEnteredSecs(datetime.now())
176 tx.SetDatePostedSecs(datetime.now())
177
178 # Buy 1.3 shares
179 s1 = Split(self.book)
180 s1.SetParent(tx)
181 s1.SetAccount(self.stock_acct)
182 s1.SetAmount(GncNumeric(13, 10))
183 s1.SetValue(GncNumeric(100, 1))
184
185 s2 = Split(self.book)
186 s2.SetParent(tx)
187 s2.SetAccount(cash_acct)
188 s2.SetAmount(GncNumeric(-100, 1))
189 s2.SetValue(GncNumeric(-100, 1))
190
191 # Sell 1.3 shares
192 s3 = Split(self.book)
193 s3.SetParent(tx)
194 s3.SetAccount(self.stock_acct)
195 s3.SetAmount(GncNumeric(-13, 10))
196 s3.SetValue(GncNumeric(-100, 1))
197
198 s4 = Split(self.book)
199 s4.SetParent(tx)
200 s4.SetAccount(cash_acct)
201 s4.SetAmount(GncNumeric(100, 1))
202 s4.SetValue(GncNumeric(100, 1))
203
204 tx.CommitEdit()
205 self.stock_acct.ScrubLots()
206
The primary numeric class for representing amounts and values.
STRUCTS.

◆ tearDown()

test_price_and_wrapping.TestGncLotSplitList.tearDown (   self)

Definition at line 207 of file test_price_and_wrapping.py.

207 def tearDown(self):
208 self.ses.end()
209

◆ test_get_split_list_returns_splits()

test_price_and_wrapping.TestGncLotSplitList.test_get_split_list_returns_splits (   self)

Definition at line 217 of file test_price_and_wrapping.py.

217 def test_get_split_list_returns_splits(self):
218 lots = self.stock_acct.GetLotList()
219 self.assertGreater(len(lots), 0)
220 splits = lots[0].get_split_list()
221 self.assertIsInstance(splits, list)
222 self.assertGreater(len(splits), 0, "Lot has no splits")
223 for s in splits:
224 self.assertIsInstance(s, Split)
225
226
227# ---------------------------------------------------------------------------
228# Test: Split.GetNoclosingBalance and Split.GetCapGains return GncNumeric
229# ---------------------------------------------------------------------------

◆ test_lot_exists()

test_price_and_wrapping.TestGncLotSplitList.test_lot_exists (   self)

Definition at line 210 of file test_price_and_wrapping.py.

210 def test_lot_exists(self):
211 lots = self.stock_acct.GetLotList()
212 self.assertIsInstance(lots, list)
213 self.assertGreater(len(lots), 0, "ScrubLots should have created a lot")
214 for lot in lots:
215 self.assertIsInstance(lot, GncLot)
216

Field Documentation

◆ book

test_price_and_wrapping.TestGncLotSplitList.book

Definition at line 156 of file test_price_and_wrapping.py.

◆ ses

test_price_and_wrapping.TestGncLotSplitList.ses

Definition at line 155 of file test_price_and_wrapping.py.

◆ stock_acct

test_price_and_wrapping.TestGncLotSplitList.stock_acct

Definition at line 163 of file test_price_and_wrapping.py.


The documentation for this class was generated from the following file: