GnuCash fec5643+
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes
test_price_and_wrapping.TestSetSourceStringGuard Class Reference
Inheritance diagram for test_price_and_wrapping.TestSetSourceStringGuard:
test_price_and_wrapping.PriceSession

Public Member Functions

 setUp (self)
 
 tearDown (self)
 
 test_canonical_source_is_accepted (self)
 
 test_unknown_source_on_fresh_price_raises (self)
 
 test_unknown_source_does_not_clobber_existing (self)
 
 test_emits_deprecation_warning (self)
 

Protected Attributes

 _warn_ctx
 

Additional Inherited Members

- Data Fields inherited from test_price_and_wrapping.PriceSession
 ses
 
 book
 
 table
 
 usd
 
 test_comm
 
 pricedb
 
 price1
 
 price2
 

Detailed Description

set_source_string() is deprecated in favour of set_source(PriceSource.*),
but while it exists it must fail loud on an unrecognized source string
instead of silently leaving the source unchanged (the C setter no-ops).
These tests ignore the DeprecationWarning and check the guard behaviour;
the warning itself is covered by test_emits_deprecation_warning.

Definition at line 495 of file test_price_and_wrapping.py.

Member Function Documentation

◆ setUp()

test_price_and_wrapping.TestSetSourceStringGuard.setUp (   self)

Reimplemented from test_price_and_wrapping.PriceSession.

Definition at line 502 of file test_price_and_wrapping.py.

502 def setUp(self):
503 super().setUp()
504 # These tests deliberately call the deprecated method.
505 self._warn_ctx = warnings.catch_warnings()
506 self._warn_ctx.__enter__()
507 warnings.simplefilter("ignore", DeprecationWarning)
508

◆ tearDown()

test_price_and_wrapping.TestSetSourceStringGuard.tearDown (   self)

Reimplemented from test_price_and_wrapping.PriceSession.

Definition at line 509 of file test_price_and_wrapping.py.

509 def tearDown(self):
510 self._warn_ctx.__exit__(None, None, None)
511 super().tearDown()
512

◆ test_canonical_source_is_accepted()

test_price_and_wrapping.TestSetSourceStringGuard.test_canonical_source_is_accepted (   self)

Definition at line 513 of file test_price_and_wrapping.py.

513 def test_canonical_source_is_accepted(self):
514 self.price1.set_source_string("Finance::Quote")
515 self.assertEqual(self.price1.get_source_string(), "Finance::Quote")
516

◆ test_emits_deprecation_warning()

test_price_and_wrapping.TestSetSourceStringGuard.test_emits_deprecation_warning (   self)

Definition at line 531 of file test_price_and_wrapping.py.

531 def test_emits_deprecation_warning(self):
532 with warnings.catch_warnings():
533 warnings.simplefilter("error", DeprecationWarning)
534 with self.assertRaises(DeprecationWarning):
535 self.price1.set_source_string("Finance::Quote")
536
537

◆ test_unknown_source_does_not_clobber_existing()

test_price_and_wrapping.TestSetSourceStringGuard.test_unknown_source_does_not_clobber_existing (   self)

Definition at line 522 of file test_price_and_wrapping.py.

522 def test_unknown_source_does_not_clobber_existing(self):
523 # The C setter no-ops on an unknown string; on a price that already has
524 # a valid source that leaves the old value in place (so a bare "is the
525 # source INVALID now?" check would miss it). The guard must still raise.
526 self.price1.set_source_string("Finance::Quote")
527 with self.assertRaises(ValueError):
528 self.price1.set_source_string("totally-bogus")
529 self.assertEqual(self.price1.get_source_string(), "Finance::Quote")
530

◆ test_unknown_source_on_fresh_price_raises()

test_price_and_wrapping.TestSetSourceStringGuard.test_unknown_source_on_fresh_price_raises (   self)

Definition at line 517 of file test_price_and_wrapping.py.

517 def test_unknown_source_on_fresh_price_raises(self):
518 price = GncPrice(self.book)
519 with self.assertRaises(ValueError):
520 price.set_source_string("not-a-real-source")
521

Field Documentation

◆ _warn_ctx

test_price_and_wrapping.TestSetSourceStringGuard._warn_ctx
protected

Definition at line 505 of file test_price_and_wrapping.py.


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