Mercurial > p > roundup > code
changeset 7879:39c482e6a246
fix: fix code to make tests of session and otks databases pass on windows
The existing code had a few issues:
sessions_dbm.py:
detect dumbdbm when used on windows python and properly delete session/otks
databases so clear() works.
make sure the Session/Otks.cache_db_type() is called even when the database
is newly created.
test/session_common.py:
close session and otks database in teardown before deleting database
directory to prevent errors from deleting open files on windows.
test/test_sqlite.py:
close the session and otks databases opened by SessionTest.setUp(self)
so the salite session/otks database are closed before the new anydbm
sessions databases are opened for testing the sqlite main db and anydbm
as session/otks db. Again this causes deletion of database test directory
to fail on windows as you can't delete open files.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 18 Apr 2024 17:39:56 -0400 |
| parents | d4aef2b004a1 |
| children | a4923cec0afa |
| files | roundup/backends/sessions_dbm.py test/session_common.py test/test_sqlite.py |
| diffstat | 3 files changed, 14 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/roundup/backends/sessions_dbm.py Thu Apr 18 15:21:15 2024 -0400 +++ b/roundup/backends/sessions_dbm.py Thu Apr 18 17:39:56 2024 -0400 @@ -42,6 +42,9 @@ os.remove(path) elif os.path.exists(path+'.db'): # dbm appends .db os.remove(path+'.db') + elif os.path.exists(path+".dir"): # dumb dbm + os.remove(path+".dir") + os.remove(path+".dat") def cache_db_type(self, path): ''' determine which DB wrote the class file, and cache it as an @@ -142,7 +145,9 @@ # new database? let anydbm pick the best dbm if not db_type: - return anydbm.open(path, 'c') + db = anydbm.open(path, 'c') + self.cache_db_type(path) + return db # open the database with the correct module dbm = __import__(db_type)
--- a/test/session_common.py Thu Apr 18 15:21:15 2024 -0400 +++ b/test/session_common.py Thu Apr 18 17:39:56 2024 -0400 @@ -49,6 +49,10 @@ def tearDown(self): if hasattr(self, 'db'): self.db.close() + if hasattr(self, 'sessions'): + self.sessions.close() + if hasattr(self, 'otks'): + self.otks.close() if os.path.exists(config.DATABASE): shutil.rmtree(config.DATABASE)
--- a/test/test_sqlite.py Thu Apr 18 15:21:15 2024 -0400 +++ b/test/test_sqlite.py Thu Apr 18 17:39:56 2024 -0400 @@ -229,7 +229,10 @@ def setUp(self): SessionTest.setUp(self) - # redefine the session db's as redis. + # redefine the session db's as anydbm + # close the existing session databases before opening new ones. + self.db.Session.close() + self.db.Otk.close() self.db.config.SESSIONDB_BACKEND = "anydbm" self.db.Session = None self.db.Otk = None
