mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
context manager examples
This commit is contained in:
@@ -19,18 +19,13 @@ except GnuCashBackendException as backend_exception:
|
||||
|
||||
|
||||
# create a new file, this requires a file type specification
|
||||
session = Session("xml://%s" % FILE_2, is_new=True)
|
||||
session.save()
|
||||
session.end()
|
||||
session.destroy()
|
||||
with Session("xml://%s" % FILE_2, is_new=True) as session:
|
||||
book = session.book
|
||||
root = book.get_root_account()
|
||||
|
||||
# open the new file, try to open it a second time, detect the lock
|
||||
session = Session(FILE_2)
|
||||
try:
|
||||
session_2 = Session(FILE_2)
|
||||
except GnuCashBackendException as backend_exception:
|
||||
assert( ERR_BACKEND_LOCKED in backend_exception.errors )
|
||||
session.end()
|
||||
session.destroy()
|
||||
|
||||
|
||||
with Session(FILE_2) as session:
|
||||
try:
|
||||
session_2 = Session(FILE_2)
|
||||
except GnuCashBackendException as backend_exception:
|
||||
assert( ERR_BACKEND_LOCKED in backend_exception.errors )
|
||||
|
||||
Reference in New Issue
Block a user