Пример #1
0
 def setUp(self):
     super(TestFocusArgParser, self).setUp()
     self.parser = FocusArgParser()
Пример #2
0
class TestFocusArgParser(FocusTestCase):
    def setUp(self):
        super(TestFocusArgParser, self).setUp()
        self.parser = FocusArgParser()

    def testMessageDefStatus__exit(self):
        """ FocusArgParser.exit: message, default status.
            """
        message = 'the message'
        with self.assertRaises(HelpBanner) as cm:
            self.parser.exit(message=message)

        exc = cm.exception
        self.assertEqual(exc.code, 0)
        self.assertEqual(exc.description, message)

    def testMessageStatusSet__exit(self):
        """ FocusArgParser.exit: message and status set.
            """
        message = 'the message'
        with self.assertRaises(HelpBanner) as cm:
            self.parser.exit(message=message, status=999)

        exc = cm.exception
        self.assertEqual(exc.code, 999)
        self.assertEqual(exc.description, message)

    def testStripsSubparse__format_help(self):
        """ FocusArgParser.format_help: strips out subparser section.
            """
        sp = self.parser.add_subparsers()
        sp.add_parser('subcmd1')
        sp.add_parser('subcmd2')
        msg = super(FocusArgParser, self.parser).format_help()
        self.assertRegexpMatches(msg, r'\{.+\}')

        msg = self.parser.format_help()
        self.assertNotRegexpMatches(msg, r'\{.+\}')

    def testIgnoresMessage__error(self):
        """ FocusArgParser.error: fails with message from `format_help()`,
            ignores provided message.
            """
        message = 'the message'
        with self.assertRaises(HelpBanner) as cm:
            self.parser.error(message=message)
        self.assertNotRegexpMatches(cm.exception.description, message)

    def test__print_help(self):
        """ FocusArgParser.print_help: fails with message from `format_help()`.
            """
        with self.assertRaises(HelpBanner) as cm:
            self.parser.print_help()
        self.assertEqual(cm.exception.description, self.parser.format_help())