예제 #1
0
파일: tests.py 프로젝트: davidalber/SBTools
class TestSBToolsMethods(unittest.TestCase):
    """
    Unit tests for the SBTools class.
    """
    def setUp(self):
        self.sbtools = SBTools()

    def test001_init(self):
        self.assertEqual(self.sbtools.tcmdlist, [])
        self.assertEqual(self.sbtools.cmdmap, {})
        self.assertEqual(self.sbtools.namemap, {})

    def test002_init_parser(self):
        self.assertEqual(self.sbtools.parser.get_version(), "sbtools 0.5")
        self.assertEqual(self.sbtools.parser.get_usage().strip(), "Usage: sbtools <subcommand> [options] [args]")

    def test003_parse_options_no_subcommand(self):
        saved_argv = sys.argv
        sys.argv = ['sbtools']
        # Make sure the expected exception is raised.
        self.assertRaises(sbtools.NoSubcommandError, self.sbtools.parse_options)
        sys.argv = saved_argv

    def test004_parse_options_unknown_subcommand(self):
        saved_argv = sys.argv
        sys.argv = ['sbtools', 'unknown-sc']
        # Make sure the expected exception is raised.
        self.assertRaises(sbtools.UnknownSubcommandError, self.sbtools.parse_options)

        # Make sure the expected message is included with the exception.
        try:
            self.sbtools.parse_options()
        except sbtools.UnknownSubcommandError, msg:
            self.assertEqual(str(msg), 'unknown-sc')
        sys.argv = saved_argv
예제 #2
0
파일: tests.py 프로젝트: davidalber/SBTools
class TestSBToolsOptionParserMethods(unittest.TestCase):
    """
    Unit tests for the SBToolsOptionParser class.
    """
    def setUp(self):
        self.sbtools = SBTools()
        self.parser = self.sbtools.parser

    def test001_init(self):
        self.assertEqual(self.parser.sbtools, self.sbtools)

    def test002_get_help(self):
        helpstr = self.parser.get_help()
        exptstr = """Usage: sbtools <subcommand> [options] [args]

Type 'sbtools help <subcommand>' for help on a specific subcommand.
Type 'sbtools --version' to see the program version.
Type 'sbtools --verbose-load' to see the packages and plug-ins detected, and
if plug-ins are successfully loaded.

Subcommands consist of built-in subcommands and subcommands provided by
installed plug-ins.

Available subcommands:
%s""" % (self.sbtools.get_subcommands())
        self.assertEqual(helpstr, exptstr)

    def test003_get_unknown_argument_error(self):
        errmsg = self.parser.get_unknown_argument_error('unknown-sc')
        self.assertEqual(errmsg, "Unknown command: 'unknown-sc'.\nType 'sbtools help' for usage information.")

    def test004_get_usage_command(self):
        usagecomm = self.parser.get_usage_command()
        self.assertEqual(usagecomm, "Type 'sbtools help' for usage information.")
예제 #3
0
파일: tests.py 프로젝트: davidalber/SBTools
 def setUp(self):
     self.sbtools = SBTools()
예제 #4
0
파일: tests.py 프로젝트: davidalber/SBTools
 def setUp(self):
     self.sbtools = SBTools()
     self.parser = self.sbtools.parser