GnuCash fec5643+
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 148 of file test_price_and_wrapping.py.

Member Function Documentation

◆ setUp()

test_price_and_wrapping.TestGncLotSplitList.setUp (   self)

Definition at line 155 of file test_price_and_wrapping.py.

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

◆ tearDown()

test_price_and_wrapping.TestGncLotSplitList.tearDown (   self)

Definition at line 208 of file test_price_and_wrapping.py.

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

◆ test_get_split_list_returns_splits()

test_price_and_wrapping.TestGncLotSplitList.test_get_split_list_returns_splits (   self)

Definition at line 218 of file test_price_and_wrapping.py.

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

◆ test_lot_exists()

test_price_and_wrapping.TestGncLotSplitList.test_lot_exists (   self)

Definition at line 211 of file test_price_and_wrapping.py.

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

Field Documentation

◆ book

test_price_and_wrapping.TestGncLotSplitList.book

Definition at line 157 of file test_price_and_wrapping.py.

◆ ses

test_price_and_wrapping.TestGncLotSplitList.ses

Definition at line 156 of file test_price_and_wrapping.py.

◆ stock_acct

test_price_and_wrapping.TestGncLotSplitList.stock_acct

Definition at line 164 of file test_price_and_wrapping.py.


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