summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDavid Sklar <177495+davidsklar@users.noreply.github.com>2023-01-14 14:28:09 -0500
committerJohn Wiegley <johnw@newartisans.com>2023-01-27 12:49:17 -0800
commit723dd41df17d3c4730ebbe8d1b10e4cb577870c7 (patch)
tree4ae8b6e696f6ce8d79a209acffe81605fede66f3 /test
parentb4445d99f15089d760a7dea874cac6ad2c11e4ff (diff)
downloadfork-ledger-723dd41df17d3c4730ebbe8d1b10e4cb577870c7.tar.gz
fork-ledger-723dd41df17d3c4730ebbe8d1b10e4cb577870c7.tar.bz2
fork-ledger-723dd41df17d3c4730ebbe8d1b10e4cb577870c7.zip
Fix python/c++ conversion for boost::optional<T>
Setters for types wrapped in boost::optional, such as item_t::note were broken, e.g. setting a note on a transaction resulted in garbled data that would cause Python to throw utf-8 errors when retrieving the note. (But setters that accessed strings directly, e.g. "payee" on a transaction worked fine.) This change alters the from-python conversion for optional-wrapped types based on the example at https://stackoverflow.com/questions/36485840/wrap-boostoptional-using-boostpython and a test case to verify the behavior.
Diffstat (limited to 'test')
-rw-r--r--test/python/TransactionTest.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/test/python/TransactionTest.py b/test/python/TransactionTest.py
index 6827720d..c87f8c4b 100644
--- a/test/python/TransactionTest.py
+++ b/test/python/TransactionTest.py
@@ -10,6 +10,7 @@ class TransactionTestCase(unittest.TestCase):
def setUp(self):
self.journal = read_journal_from_string("""
2012-03-01 KFC
+ ;this is a note
Expenses:Food $21.34
Assets:Cash
2012-03-02 MJT
@@ -31,6 +32,14 @@ class TransactionTestCase(unittest.TestCase):
self.assertEqual(len(x0_posts), 4)
self.assertEqual(len(x1_posts), 0)
+ def testSetNote(self):
+ xacts = [xact for xact in self.journal]
+ self.assertEqual(xacts[0].note, 'this is a note')
+ xacts[0].note = 'this is also a note'
+ self.assertEqual(xacts[0].note, 'this is also a note')
+ xacts[0].note += 'so is this'
+ self.assertEqual(xacts[0].note, 'this is also a noteso is this')
+
def suite():
return unittest.TestLoader().loadTestsFromTestCase(TransactionTestCase)