def test_open_and_close(self):
# ConfigurationDatabase.open() returns a context manager that closes
# the database on exit.
config_file = os.path.join(self.make_dir(), "config")
config = ConfigurationDatabase.open_for_update(config_file)
self.assertIsInstance(config, contextlib._GeneratorContextManager)
with config as config:
self.assertIsInstance(config, ConfigurationDatabase)
with config.cursor() as cursor:
self.assertEqual(
(1,), cursor.execute("SELECT 1").fetchone())
self.assertRaises(sqlite3.ProgrammingError, config.cursor)
评论列表
文章目录