gnucash master: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Wed May 17 04:41:33 EDT 2017


Updated	 via  https://github.com/Gnucash/gnucash/commit/34bab999 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/3cd2a655 (commit)
	from  https://github.com/Gnucash/gnucash/commit/e0af43d4 (commit)



commit 34bab999a556c4bafb9c63f8a180f3ac1278fe01
Author: Guy Taylor <thebigguy.co.uk at gmail.com>
Date:   Tue May 16 17:11:28 2017 +0100

    Fix coredump in Python when using "get_namespaces"
    
    The Python API incorectly had GncCommodityTable.get_namespaces() defined
    as a list of GncCommodityNamespace over the correct list of String. This
    fixes the issue and adds a test for GncCommodityTable.get_namespaces()
    and GncCommodityTable.get_namespaces_list().
    
    Note: This is not a direct fix as I could not get SWIG to detect/convert
    "GList *" to a "gchar *" to a Python str list.

diff --git a/src/optional/python-bindings/gnucash_core.py b/src/optional/python-bindings/gnucash_core.py
index f917c40..b72ecb1 100644
--- a/src/optional/python-bindings/gnucash_core.py
+++ b/src/optional/python-bindings/gnucash_core.py
@@ -367,7 +367,8 @@ class GncCommodityTable(GnuCashCoreClass):
     which includes most of the world's currencies.
     """
 
-    pass
+    def _get_namespaces_py(self):
+        return [ns.get_name() for ns in self.get_namespaces_list()]
 
 class GncCommodityNamespace(GnuCashCoreClass):
     pass
@@ -547,12 +548,12 @@ commoditytable_dict =   {
 methods_return_instance(GncCommodityTable, commoditytable_dict)
 
 methods_return_instance_lists(
-    GncCommodityTable, { 'get_namespaces': GncCommodityNamespace,
-                         'get_namespaces_list': GncCommodityNamespace,
+    GncCommodityTable, { 'get_namespaces_list': GncCommodityNamespace,
                          'get_commodities': GncCommodity,
                          'get_quotable_commodities': GncCommodity,
                          
                        } )
+setattr(GncCommodityTable, 'get_namespaces', getattr(GncCommodityTable, '_get_namespaces_py'))
 
 # GncCommodityNamespace
 GncCommodityNamespace.add_methods_with_prefix('gnc_commodity_namespace_')
diff --git a/src/optional/python-bindings/tests/runTests.py.in b/src/optional/python-bindings/tests/runTests.py.in
index 7da6b7d..0a1d269 100755
--- a/src/optional/python-bindings/tests/runTests.py.in
+++ b/src/optional/python-bindings/tests/runTests.py.in
@@ -12,9 +12,10 @@ from test_account import TestAccount
 from test_split import TestSplit
 from test_transaction import TestTransaction
 from test_business import TestBusiness
+from test_commodity import TestCommodity, TestCommodityNamespace
 
 def test_main():
-    test_support.run_unittest(TestBook, TestAccount, TestSplit, TestTransaction, TestBusiness)
+    test_support.run_unittest(TestBook, TestAccount, TestSplit, TestTransaction, TestBusiness, TestCommodity, TestCommodityNamespace)
 
 if __name__ == '__main__':
     test_main()
diff --git a/src/optional/python-bindings/tests/test_commodity.py b/src/optional/python-bindings/tests/test_commodity.py
new file mode 100644
index 0000000..c8dabd4
--- /dev/null
+++ b/src/optional/python-bindings/tests/test_commodity.py
@@ -0,0 +1,32 @@
+from unittest import TestCase, main
+
+from gnucash import Session
+
+class CommoditySession( TestCase ):
+    def setUp(self):
+        self.ses = Session()
+        self.book = self.ses.get_book()
+        self.table = self.book.get_table()
+
+    def tearDown(self):
+        self.ses.end()
+
+class TestCommodity( CommoditySession ):
+    def test_iso_currency(self):
+        eur = self.table.lookup('CURRENCY', 'EUR')
+        self.assertIsNotNone(eur)
+
+class TestCommodityNamespace( CommoditySession ):
+    def test_namespaces(self):
+        print(self.table.__class__)
+        namespace_names = self.table.get_namespaces()
+        print(namespace_names)
+        self.assertEqual(namespace_names, ['AMEX', 'NYSE', 'NASDAQ', 'EUREX', 'FUND', 'template', 'CURRENCY'])
+
+    def test_namespaces_list(self):
+        namespaces = self.table.get_namespaces_list()
+        namespace_names = [ns.get_name() for ns in namespaces]
+        self.assertEqual(namespace_names, ['AMEX', 'NYSE', 'NASDAQ', 'EUREX', 'FUND', 'template', 'CURRENCY'])
+
+if __name__ == '__main__':
+    main()

commit 3cd2a6554c40b2df0aef3f091e115614fa12b93e
Author: Guy Taylor <thebigguy.co.uk at gmail.com>
Date:   Tue May 16 17:17:04 2017 +0100

    Enable Python tests in Travis CI

diff --git a/.travis.yml b/.travis.yml
index bda0de6..3a648bb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,4 +18,4 @@ install:
   - sudo apt-get install -qq libboost-all-dev
   - sudo apt-get --reinstall install -qq language-pack-en language-pack-fr
   - git clone https://github.com/google/googletest -b release-1.8.0 ~/gtest
-script: ./autogen.sh && ./configure GTEST_ROOT=~/gtest/googletest GMOCK_ROOT=~/gtest/googlemock && make && TZ="America/Los_Angeles" make check
+script: ./autogen.sh && ./configure --enable-python GTEST_ROOT=~/gtest/googletest GMOCK_ROOT=~/gtest/googlemock && make && TZ="America/Los_Angeles" make check



Summary of changes:
 .travis.yml                                        |  2 +-
 src/optional/python-bindings/gnucash_core.py       |  7 +++--
 src/optional/python-bindings/tests/runTests.py.in  |  3 +-
 .../python-bindings/tests/test_commodity.py        | 32 ++++++++++++++++++++++
 4 files changed, 39 insertions(+), 5 deletions(-)
 create mode 100644 src/optional/python-bindings/tests/test_commodity.py



More information about the gnucash-changes mailing list