class TestSBToolOptionParserMethods(unittest.TestCase): """ Unit tests for the SBToolOptionParser class. """ def setUp(self): class TestTool1(SBTool): def __init__(self, sbtools): self.sbtools = sbtools def get_command(self): return "TestTool1" def get_alt_commands(self): return [] self.sbtools = SBTools() self.tool = TestTool1(self.sbtools) self.usage = "TestTool1 [options]" self.version = "0.1" self.description = "The test tool does something." self.parser = SBToolOptionParser(self.tool, self.sbtools, self.usage, self.version, self.description) def test001_get_usage_command(self): usagecomm = self.parser.get_usage_command() self.assertEqual(usagecomm, "Type 'sbtools help %s' for usage." % (self.tool.get_command())) def test002_error(self): # Make sure the expected exception is raised. self.assertRaises(SBToolError, self.parser.error, "unknown option --blah") # Make sure the expecte message is passed with the exception. try: self.parser.error("unknown option --blah") except SBToolError, msg: self.assertEqual(str(msg), "Subcommand '%s': unknown option --blah\n%s" % (self.tool.get_command(), self.parser.get_usage_command()))
def setUp(self): class TestTool1(SBTool): def __init__(self, sbtools): self.sbtools = sbtools def get_command(self): return "TestTool1" def get_alt_commands(self): return [] self.sbtools = SBTools() self.tool = TestTool1(self.sbtools) self.usage = "TestTool1 [options]" self.version = "0.1" self.description = "The test tool does something." self.parser = SBToolOptionParser(self.tool, self.sbtools, self.usage, self.version, self.description)