xfstestsdb: Add a sqlite.Connection instance to the root Command
And take some extra steps to make sure we clean it up when the Command is finished. Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
This commit is contained in:
parent
929c1dd5eb
commit
e3cf7e7017
|
@ -18,6 +18,13 @@ class TestXfstestsdb(unittest.TestCase):
|
||||||
"""Test that the xfstestsdb instance is set up properly."""
|
"""Test that the xfstestsdb instance is set up properly."""
|
||||||
self.assertIsInstance(self.xfstestsdb.parser, argparse.ArgumentParser)
|
self.assertIsInstance(self.xfstestsdb.parser, argparse.ArgumentParser)
|
||||||
self.assertIsInstance(self.xfstestsdb.subparser, argparse.Action)
|
self.assertIsInstance(self.xfstestsdb.subparser, argparse.Action)
|
||||||
|
self.assertIsInstance(self.xfstestsdb.sql,
|
||||||
|
xfstestsdb.sqlite.Connection)
|
||||||
|
|
||||||
|
def test_close(self):
|
||||||
|
"""Test that the xfstestsdb instance closes the database."""
|
||||||
|
self.xfstestsdb.__del__()
|
||||||
|
self.assertFalse(self.xfstestsdb.sql.connected)
|
||||||
|
|
||||||
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
||||||
def test_run_empty(self, mock_stdout: io.StringIO):
|
def test_run_empty(self, mock_stdout: io.StringIO):
|
||||||
|
@ -34,6 +41,7 @@ class TestXfstestsdb(unittest.TestCase):
|
||||||
|
|
||||||
def test_func(args: argparse.Namespace) -> None:
|
def test_func(args: argparse.Namespace) -> None:
|
||||||
nonlocal test_passed
|
nonlocal test_passed
|
||||||
|
self.assertTrue(self.xfstestsdb.sql.sql.in_transaction)
|
||||||
test_passed = True
|
test_passed = True
|
||||||
parser.set_defaults(function=test_func)
|
parser.set_defaults(function=test_func)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# Copyright 2023 (c) Anna Schumaker
|
# Copyright 2023 (c) Anna Schumaker
|
||||||
"""Implements the toplevel xfstestsdb command."""
|
"""Implements the toplevel xfstestsdb command."""
|
||||||
import argparse
|
import argparse
|
||||||
|
from . import sqlite
|
||||||
|
|
||||||
MAJOR = 1
|
MAJOR = 1
|
||||||
MINOR = 0
|
MINOR = 0
|
||||||
|
@ -16,8 +17,13 @@ class Command:
|
||||||
self.parser.add_argument("--version", action="store_true",
|
self.parser.add_argument("--version", action="store_true",
|
||||||
help="show version number and exit")
|
help="show version number and exit")
|
||||||
self.subparser = self.parser.add_subparsers(title="commands")
|
self.subparser = self.parser.add_subparsers(title="commands")
|
||||||
|
self.sql = sqlite.Connection()
|
||||||
self.commands = {}
|
self.commands = {}
|
||||||
|
|
||||||
|
def __del__(self) -> None:
|
||||||
|
"""Clean up."""
|
||||||
|
self.sql.close()
|
||||||
|
|
||||||
def run(self, args: list = None) -> None:
|
def run(self, args: list = None) -> None:
|
||||||
"""Run the xfstestsdb command."""
|
"""Run the xfstestsdb command."""
|
||||||
parsed = self.parser.parse_args(args)
|
parsed = self.parser.parse_args(args)
|
||||||
|
@ -25,4 +31,5 @@ class Command:
|
||||||
print(f"xfstestsdb v{MAJOR}.{MINOR}"
|
print(f"xfstestsdb v{MAJOR}.{MINOR}"
|
||||||
f"{'-debug' if __debug__ else ''}")
|
f"{'-debug' if __debug__ else ''}")
|
||||||
else:
|
else:
|
||||||
parsed.function(parsed)
|
with self.sql:
|
||||||
|
parsed.function(parsed)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user