bebraw
1/14/2010 - 1:52 PM

interpreter.py

...
from py.test import raises

...

class TestInterpreter:

...

    def test_system_exit(self):
        def quit():
            raise SystemExit

        command = self.create_command('quit', execute_method=quit)

        interpreter = Interpreter(command)

        raises(SystemExit, interpreter.interpret, 'quit')

...
...
    def interpret(self, expression):
        possible_parameters = {'context': self.context,
            'commands': self.commands, 'expression': expression,
            'variables': self.variables}

        try:
            if self.context.owner:
                command = self.context.owner
            else:
                command = self.commands.match(expression)
            
            args = self._get_args(command.execute)
            params = self._find_parameters(possible_parameters, args)

            return command.execute(**params)
        except SystemExit, e:
            raise e
        except:
            return 'null'
...