summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pyutils.h9
-rw-r--r--test/python/TransactionTest.py9
2 files changed, 14 insertions, 4 deletions
diff --git a/src/pyutils.h b/src/pyutils.h
index 6c9675b7..7bc0d0af 100644
--- a/src/pyutils.h
+++ b/src/pyutils.h
@@ -88,13 +88,14 @@ struct register_optional_to_python : public boost::noncopyable
{
using namespace boost::python::converter;
- void * const storage =
- reinterpret_cast<rvalue_from_python_storage<T> *>(data)->storage.bytes;
+ const T value = typename boost::python::extract<T>(source);
- if (data->convertible == source) // == None
+ void * storage = ((rvalue_from_python_storage<boost::optional<T>>*) data)->storage.bytes;
+
+ if (source == Py_None) // == None
new (storage) boost::optional<T>(); // A Boost uninitialized value
else
- new (storage) boost::optional<T>(*reinterpret_cast<T *>(data->convertible));
+ new (storage) boost::optional<T>(value);
data->convertible = storage;
}
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)