GnuCash 7574033+
Loading...
Searching...
No Matches
test_price_and_wrapping.TestSwigTypemapCompat Class Reference
Inheritance diagram for test_price_and_wrapping.TestSwigTypemapCompat:
test_price_and_wrapping.PriceSession

Public Member Functions

 test_wrapper_triggers_deprecation_warning (self)
 test_raw_instance_no_warning (self)
Public Member Functions inherited from test_price_and_wrapping.PriceSession
 setUp (self)
 tearDown (self)

Additional Inherited Members

Data Fields inherited from test_price_and_wrapping.PriceSession
 ses = Session()
 book = self.ses.get_book()
 table = self.book.get_table()
 usd = self.table.lookup("CURRENCY", "USD")
 test_comm
 pricedb = self.book.get_price_db()
 price1 = GncPrice(self.book)
 price2 = GncPrice(self.book)

Detailed Description

Verify that passing a ClassFromFunctions wrapper to a C function
still works (via the SWIG typemap) and emits a DeprecationWarning.

Definition at line 345 of file test_price_and_wrapping.py.

Member Function Documentation

◆ test_raw_instance_no_warning()

test_price_and_wrapping.TestSwigTypemapCompat.test_raw_instance_no_warning ( self)
Passing price.instance directly should NOT emit a warning.

Definition at line 369 of file test_price_and_wrapping.py.

369 def test_raw_instance_no_warning(self):
370 """Passing price.instance directly should NOT emit a warning."""
371 from gnucash import gnucash_core_c as gc
372
373 price = self.pricedb.lookup_latest(self.test_comm, self.usd)
374 if price is None:
375 self.skipTest("No price data")
376
377 with warnings.catch_warnings(record=True) as w:
378 warnings.simplefilter("always")
379 comm_instance = gc.gnc_price_get_commodity(price.instance)
380 dep_warnings = [x for x in w
381 if issubclass(x.category, DeprecationWarning)]
382 self.assertEqual(len(dep_warnings), 0,
383 "Unexpected DeprecationWarning for .instance")
384
385
386# ---------------------------------------------------------------------------
387# Test: GncPriceDB.get_*_price returns GncNumeric
388# ---------------------------------------------------------------------------

◆ test_wrapper_triggers_deprecation_warning()

test_price_and_wrapping.TestSwigTypemapCompat.test_wrapper_triggers_deprecation_warning ( self)
Passing a GncPrice wrapper to gnucash_core_c should emit
DeprecationWarning and still return a valid result.

Definition at line 349 of file test_price_and_wrapping.py.

349 def test_wrapper_triggers_deprecation_warning(self):
350 """Passing a GncPrice wrapper to gnucash_core_c should emit
351 DeprecationWarning and still return a valid result."""
352 from gnucash import gnucash_core_c as gc
353
354 price = self.pricedb.lookup_latest(self.test_comm, self.usd)
355 if price is None:
356 self.skipTest("No price data")
357
358 self.assertIsInstance(price, GncPrice)
359
360 with warnings.catch_warnings(record=True) as w:
361 warnings.simplefilter("always")
362 # Pass the wrapper object directly — typemap should unwrap it
363 comm_instance = gc.gnc_price_get_commodity(price)
364 dep_warnings = [x for x in w
365 if issubclass(x.category, DeprecationWarning)]
366 self.assertGreater(len(dep_warnings), 0,
367 "Expected DeprecationWarning from typemap")
368

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