Hello,

there is some bitrot in the tests and example_script directories in
python bindings: there are calls to Book() that doesn't seem directly
instantiable anymore and to the nonexisting Book.mark_closed() method.
Also the uri syntax xml:/some/file doesn't seem working anymore - an
xml:// prefix seems required before the absolute path name.

The attached patch fixes the issues I've found, at least allowing a
clean run of the tests and the example without errors. Apologize if I
broke their meaning - I think it's something people knowing better
than me how the bindings are supposed to work can easily check.

Regards,

-- Daniele
Index: src/optional/python-bindings/example_scripts/change_tax_code.py
===================================================================
--- src/optional/python-bindings/example_scripts/change_tax_code.py	(revision 19415)
+++ src/optional/python-bindings/example_scripts/change_tax_code.py	(working copy)
@@ -23,7 +23,7 @@
         return False
             
 # Change this path to your own
-gnucash_session = Session("xml:/home/mark/python-bindings-help/test.xac")
+gnucash_session = Session("xml:///home/mark/python-bindings-help/test.xac")
 
 mark_account_with_code_as_tax_related(
     gnucash_session.book.get_root_account(),
Index: src/optional/python-bindings/example_scripts/simple_session.py
===================================================================
--- src/optional/python-bindings/example_scripts/simple_session.py	(revision 19415)
+++ src/optional/python-bindings/example_scripts/simple_session.py	(working copy)
@@ -10,21 +10,21 @@
 # open a file that isn't there, detect the error
 session = None
 try:
-    session = Session("xml:%s" % FILE_1)
+    session = Session("xml://%s" % FILE_1)
 except GnuCashBackendException, backend_exception:
     assert( ERR_FILEIO_FILE_NOT_FOUND in backend_exception.errors)
 
 
 # create a new file
-session = Session("xml:%s" % FILE_2, True)
+session = Session("xml://%s" % FILE_2, True)
 session.save()
 session.end()
 session.destroy()
 
 # open the new file, try to open it a second time, detect the lock
-session = Session("xml:%s" % FILE_2)
+session = Session("xml://%s" % FILE_2)
 try:
-    session_2 = Session("xml:%s" % FILE_2)
+    session_2 = Session("xml://%s" % FILE_2)
 except GnuCashBackendException, backend_exception:
     assert( ERR_BACKEND_LOCKED in backend_exception.errors )
 session.end()
Index: src/optional/python-bindings/example_scripts/simple_book.py
===================================================================
--- src/optional/python-bindings/example_scripts/simple_book.py	(revision 19415)
+++ src/optional/python-bindings/example_scripts/simple_book.py	(working copy)
@@ -1,13 +1,19 @@
 #!/usr/bin/env python
-from gnucash import Book
+import sys
+from gnucash import Session
 
-book = Book()
+uri = "xml:///tmp/simple_book.gnucash"
 
+print "uri:", uri
+ses = Session(uri, is_new=True)
+book = ses.get_book()
+
 #Call some methods that produce output to show that Book works
-print "New book:"
-book.print_dirty()
-book.mark_saved()
-print "\nBook marked saved:"
-book.print_dirty()
+book.get_root_account().SetDescription("hello, book")
+print "Book is saved:", not book.not_saved()
 
-book.destroy()
+print "saving..."
+ses.save()
+
+print "Book is saved:", not book.not_saved()
+ses.end()
Index: src/optional/python-bindings/tests/test_book.py
===================================================================
--- src/optional/python-bindings/tests/test_book.py	(revision 19415)
+++ src/optional/python-bindings/tests/test_book.py	(working copy)
@@ -1,14 +1,15 @@
 from unittest import TestCase, main
 
-from gnucash import Book
+from gnucash import Session
 
 class BookSession( TestCase ):
     def setUp(self):
-        self.book = Book()
+        self.ses = Session()
+        self.book = self.ses.get_book()
 
 class TestBook( BookSession ):
     def test_markclosed(self):
-        self.book.mark_closed()
+        self.ses.end()
 
 if __name__ == '__main__':
     main()
_______________________________________________
gnucash-devel mailing list
[email protected]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Reply via email to