# Copyright 2023 (c) Anna Schumaker. """Tests the generic Command class.""" import argparse import unittest import xfstestsdb.commands class TestCommand(unittest.TestCase): """Tests the xfstestsdb Command class.""" def setUp(self): """Set up common variables.""" self.sql = xfstestsdb.sqlite.Connection() self.parser = argparse.ArgumentParser() self.subparser = self.parser.add_subparsers(title="commands") self.command = xfstestsdb.commands.Command(self.subparser, self.sql, "test", "help text", description="description") def test_init(self): """Test that the Command was initialized properly.""" self.assertIsInstance(self.command.parser, argparse.ArgumentParser) self.assertEqual(self.subparser.choices["test"], self.command.parser) self.assertEqual(self.command.parser.description, "description") self.assertEqual(self.command.parser._defaults["function"], self.command.do_command) self.assertEqual(self.command.parser._defaults["done"], self.command.do_done) self.assertEqual(self.command.sql, self.sql) def test_do_command(self): """Test the do_command() function.""" with self.assertRaises(NotImplementedError): self.command.do_command(argparse.Namespace()) def test_do_done(self): """Test the do_done() function.""" self.command.do_done(argparse.Namespace())