GnuCash fec5643+
Loading...
Searching...
No Matches
Public Member Functions
test_price_and_wrapping.TestPriceSourceEnum Class Reference
Inheritance diagram for test_price_and_wrapping.TestPriceSourceEnum:

Public Member Functions

 test_values_match_c_enum (self)
 
 test_set_source_accepts_enum (self)
 

Detailed Description

PriceSource must cover the C PRICE_SOURCE_* enum exactly, so it can't
drift if a value is added, removed, or renumbered on the C side. Member
names are a Python-side choice (e.g. FINANCE_QUOTE spells out FQ), so the
check is on the set of values, which come straight from the C enum.

Definition at line 460 of file test_price_and_wrapping.py.

Member Function Documentation

◆ test_set_source_accepts_enum()

test_price_and_wrapping.TestPriceSourceEnum.test_set_source_accepts_enum (   self)

Definition at line 475 of file test_price_and_wrapping.py.

475 def test_set_source_accepts_enum(self):
476 ses = Session()
477 book = ses.get_book()
478 table = book.get_table()
479 usd = table.lookup("CURRENCY", "USD")
480 stock = GncCommodity(book, "Test Stock", "NASDAQ", "TSTK", "TSTK", 10000)
481 table.insert(stock)
482 price = GncPrice(book)
483 price.set_commodity(stock)
484 price.set_currency(usd)
485 price.set_source(PriceSource.FINANCE_QUOTE)
486 self.assertEqual(price.get_source(), PriceSource.FINANCE_QUOTE)
487 self.assertEqual(price.get_source_string(), "Finance::Quote")
488 ses.end()
489
490
491# ---------------------------------------------------------------------------
492# Test: GncPrice.set_source_string -- deprecated, but still guards (raises on
493# an unrecognized source) during the deprecation period
494# ---------------------------------------------------------------------------

◆ test_values_match_c_enum()

test_price_and_wrapping.TestPriceSourceEnum.test_values_match_c_enum (   self)

Definition at line 466 of file test_price_and_wrapping.py.

466 def test_values_match_c_enum(self):
467 from gnucash import gnucash_core_c as c
468 c_values = sorted(getattr(c, n) for n in dir(c)
469 if n.startswith("PRICE_SOURCE_"))
470 py_values = sorted(m.value for m in PriceSource)
471 self.assertEqual(py_values, c_values,
472 "PriceSource is out of sync with the C PRICE_SOURCE_* "
473 "enum -- add/remove members to match.")
474

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