11 from unittest
import TestCase, main
21 def test_create_empty_session(self):
25 """use deprecated arguments ignore_lock, is_new, force_new""" 26 self.
ses = Session(ignore_lock=
False, is_new=
True, force_new=
False)
29 """use mode argument""" 30 self.
ses = Session(mode=SessionOpenMode.SESSION_NORMAL_OPEN)
33 """create Session with new xml file""" 34 from tempfile
import TemporaryDirectory
35 from urllib.parse
import urlunparse
36 with TemporaryDirectory()
as tempdir:
37 uri = urlunparse((
"xml", tempdir,
"tempfile",
"",
"",
""))
38 with Session(uri, SessionOpenMode.SESSION_NEW_STORE)
as ses:
42 uri = urlunparse((
"xml", tempdir,
"tempfile2",
"",
"",
""))
43 with Session()
as ses:
44 with self.assertRaises(GnuCashBackendException):
45 ses.begin(uri, mode=SessionOpenMode.SESSION_NORMAL_OPEN)
49 uri = urlunparse((
"xml", tempdir,
"tempfile2",
"",
"",
""))
50 with Session()
as ses:
51 with self.assertRaises(GnuCashBackendException):
52 ses.begin(uri, is_new=
False)
54 uri = urlunparse((
"xml", tempdir,
"tempfile3",
"",
"",
""))
55 with Session()
as ses:
56 ses.begin(uri, mode=SessionOpenMode.SESSION_NEW_STORE)
59 uri = urlunparse((
"xml", tempdir,
"tempfile4",
"",
"",
""))
60 with Session()
as ses:
61 ses.begin(uri, is_new=
True)
64 def test_app_utils_get_current_session(self):
65 from gnucash
import _sw_app_utils
66 self.
ses_instance = _sw_app_utils.gnc_get_current_session()
68 self.assertIsInstance(obj = self.
ses, cls = Session)
70 def test_get_book_from_current_session(self):
71 from gnucash
import _sw_app_utils
72 from gnucash
import Book
73 self.
ses_instance = _sw_app_utils.gnc_get_current_session()
76 self.assertIsInstance(obj = self.
book, cls = Book)
78 if __name__ ==
'__main__':
def test_session_deprecated_arguments(self)
def test_session_mode(self)
def test_session_with_new_file(self)