Example #1
0
class BaseParsingTestCase(unittest.TestCase):
    class SimpleCommand(object):
        COMMAND_NAMES = ('simple', 's')
        ARGUMENTS = ()
        @staticmethod
        def CONSTRUCTOR():
            return '<simple command>'

    class IntegerCommand(object):
        COMMAND_NAMES = ('integer', 'i')
        ARGUMENTS = ('int',)
        @staticmethod
        def CONSTRUCTOR(i):
            return i

    class StringCommand(object):
        COMMAND_NAMES = ('string',)
        ARGUMENTS = ('str',)
        @staticmethod
        def CONSTRUCTOR(s):
            return s

    class DirectionCommand(object):
        COMMAND_NAMES = ('direction', 'd')
        ARGUMENTS = ('direction',)
        @staticmethod
        def CONSTRUCTOR(d):
            return d

    class ComplexCommand(object):
        COMMAND_NAMES = ('complex', 'c')
        ARGUMENTS = ('int', 'str', 'direction')
        @staticmethod
        def CONSTRUCTOR(i, s, d):
            return (i, s, d)

    ALL_COMMANDS = (SimpleCommand,
                    IntegerCommand,
                    StringCommand,
                    DirectionCommand,
                    ComplexCommand)

    def setUp(self):
        self.p = Parser(BaseParsingTestCase.ALL_COMMANDS)

    def parse_text(self, input_text):
        self.message_stubs, self.commands = self.p.parse(input_text)

    def assert_no_messages(self):
        self.assertEqual(self.message_stubs, [])

    def assert_no_command(self):
        self.assertEqual(self.commands, [])

    def assert_command_is(self, command):
        self.assertEqual(self.commands, [command])
Example #2
0
 def setUp(self):
     self.p = Parser(BaseParsingTestCase.ALL_COMMANDS)