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
def testComment(self): "Test a comment." self.assertEqual((('', Modifiers(), None),), tuple(findCommands('# comment')))
def testEmpty(self): "Test an empty string produces no commands at all." self.assertEqual(tuple(), tuple(findCommands('')))
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")))
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}")))
def testNoSplitAssignment(self): "Test an assignment with splitting off" self.assertEqual((('a = 3', Modifiers(), None),), tuple(findCommands('a = 3', splitLines=False)))
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 :=')))
def testTwoCommands(self): "Test two commands on one line" self.assertEqual( (('hey', Modifiers(), None), ('you', Modifiers(), None)), tuple(findCommands('hey you')))
def testCommandWithCountThenModifiers(self): "Test a command with a count then modifiers" self.assertEqual((('hey', strToModifiers('=p'), 101),), tuple(findCommands('hey :101=p')))
def testCommandWithCount(self): "Test a command with a count" self.assertEqual((('hey', Modifiers(), 101),), tuple(findCommands('hey :101')))
def testCommandWithNoModifiersCaseUnchanged(self): "Test that command case is unmodified" self.assertEqual((('HeY', Modifiers(), None),), tuple(findCommands('HeY')))
def testCommandWithSurroundingSpaceAndNoModifiers(self): "Test a command with surrounding space and no modifiers" self.assertEqual((('hey', Modifiers(), None),), tuple(findCommands(' hey ')))
def testCommandWithNoModifiersFollowedByWhitespace(self): "Test a command with no modifiers followed by whitespace" self.assertEqual((('hey', Modifiers(), None),), tuple(findCommands('hey ')))
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)))
def testCommentPrecededByWhitespace(self): "Test a comment preceeded by whitespace." self.assertEqual((('', Modifiers(), None),), tuple(findCommands(' # comment')))
def testCommandWithNoModifiers(self): "Test a command with no modifiers" self.assertEqual((('hey', Modifiers(), None),), tuple(findCommands('hey')))
def testCommandWithModifiersThenCount(self): "Test a command with modifiers then a count" self.assertEqual((('hey', strToModifiers('=p'), 101),), tuple(findCommands('hey :=p101')))
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')))
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)))
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')))
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)))