Exemplo n.º 1
0
    def execute(self, line):
        """
        Execute a line of commands. Stop executing commands on any error.

        @param line: A C{str} command line to run.
        @return: A C{bool} indicating if all commands ran without error.
        """
        commands = findCommands(line, self._splitLines, self._separator)

        while True:
            try:
                command, modifiers, count = next(commands)
            except UnknownModifiersError as e:
                self.err('Unknown modifiers: %s' % ', '.join(e.args))
                return False
            except IncompatibleModifiersError as e:
                self.err('Incompatible modifiers: %s' % e.args[0])
                return False
            except StopIteration:
                break
            else:
                if not self._executeOneCommand(command, modifiers, count):
                    # Print a debug message if there were pending commands
                    # that did not get run at all.
                    try:
                        command, modifiers, count = next(commands)
                    except StopIteration:
                        pass
                    else:
                        self.debug('Ignoring commands from %r on due to '
                                   'previous error' % command)
                    return False
Exemplo n.º 2
0
 def testComment(self):
     "Test a comment."
     self.assertEqual((('', Modifiers(), None),),
                      tuple(findCommands('# comment')))
Exemplo n.º 3
0
 def testEmpty(self):
     "Test an empty string produces no commands at all."
     self.assertEqual(tuple(), tuple(findCommands('')))
Exemplo n.º 4
0
 def testDictWithModifiers(self):
     "A dict with a count must be processed correctly."
     self.assertEqual((("{'a':6,'b':10,'c':15}", Modifiers(), 7),),
                      tuple(findCommands("{'a':6,'b':10,'c':15}:7")))
Exemplo n.º 5
0
 def testDict(self):
     "A dict must not be confused for a string with modifiers."
     self.assertEqual((("{'a':6,'b':10,'c':15}", Modifiers(), None),),
                      tuple(findCommands("{'a':6,'b':10,'c':15}")))
Exemplo n.º 6
0
 def testNoSplitAssignment(self):
     "Test an assignment with splitting off"
     self.assertEqual((('a = 3', Modifiers(), None),),
                      tuple(findCommands('a = 3', splitLines=False)))
Exemplo n.º 7
0
 def testTwoCommandsSecondWithModifiersAfterSpace(self):
     "Test two commands on one line, the 2nd with modifiers after a space"
     self.assertEqual(
         (('hey', Modifiers(), None), ('you', strToModifiers('='), None)),
         tuple(findCommands('hey you :=')))
Exemplo n.º 8
0
 def testTwoCommands(self):
     "Test two commands on one line"
     self.assertEqual(
         (('hey', Modifiers(), None), ('you', Modifiers(), None)),
         tuple(findCommands('hey you')))
Exemplo n.º 9
0
 def testCommandWithCountThenModifiers(self):
     "Test a command with a count then modifiers"
     self.assertEqual((('hey', strToModifiers('=p'), 101),),
                      tuple(findCommands('hey :101=p')))
Exemplo n.º 10
0
 def testCommandWithCount(self):
     "Test a command with a count"
     self.assertEqual((('hey', Modifiers(), 101),),
                      tuple(findCommands('hey :101')))
Exemplo n.º 11
0
 def testCommandWithNoModifiersCaseUnchanged(self):
     "Test that command case is unmodified"
     self.assertEqual((('HeY', Modifiers(), None),),
                      tuple(findCommands('HeY')))
Exemplo n.º 12
0
 def testCommandWithSurroundingSpaceAndNoModifiers(self):
     "Test a command with surrounding space and no modifiers"
     self.assertEqual((('hey', Modifiers(), None),),
                      tuple(findCommands(' hey ')))
Exemplo n.º 13
0
 def testCommandWithNoModifiersFollowedByWhitespace(self):
     "Test a command with no modifiers followed by whitespace"
     self.assertEqual((('hey', Modifiers(), None),),
                      tuple(findCommands('hey ')))
Exemplo n.º 14
0
 def testTwoCommandsSplitLines(self):
     "Test two words on one line when splitLines is False"
     self.assertEqual(
         (('hey you', Modifiers(), None),),
         tuple(findCommands('hey you', splitLines=False)))
Exemplo n.º 15
0
 def testCommentPrecededByWhitespace(self):
     "Test a comment preceeded by whitespace."
     self.assertEqual((('', Modifiers(), None),),
                      tuple(findCommands('  # comment')))
Exemplo n.º 16
0
 def testCommandWithNoModifiers(self):
     "Test a command with no modifiers"
     self.assertEqual((('hey', Modifiers(), None),),
                      tuple(findCommands('hey')))
Exemplo n.º 17
0
 def testCommandWithModifiersThenCount(self):
     "Test a command with modifiers then a count"
     self.assertEqual((('hey', strToModifiers('=p'), 101),),
                      tuple(findCommands('hey :=p101')))
Exemplo n.º 18
0
 def testTwoCommandsFirstWithModifiers(self):
     "Test two commands on one line, the 1st with modifiers (and no space)"
     self.assertEqual(
         (('hey', strToModifiers('='), None), ('you', Modifiers(), None)),
         tuple(findCommands('hey:= you')))
Exemplo n.º 19
0
 def testCommandWithCountThenSpaceAndModifiers(self):
     "Test a command with a count then a space then modifiers with space"
     self.assertEqual(
         (('hey', strToModifiers('=p'), 101),),
         tuple(findCommands('hey :101 =p', splitLines=False)))
Exemplo n.º 20
0
 def testThreeCommandsSecondWithModifiers(self):
     "Test three commands on one line, the 2nd with modifiers"
     self.assertEqual(
         (('hey', Modifiers(), None), ('you', strToModifiers('='), None),
          ('there', Modifiers(), None)),
         tuple(findCommands('hey you:= there')))
Exemplo n.º 21
0
 def testCommandWithModifiersSurroundingCountNoSplit(self):
     "Test a command with modifiers before and after a count"
     self.assertEqual(
         (('hey', strToModifiers('=p*'), 16),),
         tuple(findCommands('hey :=p 16 *', splitLines=False)))