Exemplo n.º 1
0
  def testFlagWithEqualGreaterThanShouldIgnoreIntervalFlags(self):
    args, output_path = command_parser.extract_output_file_path(
        ["lp", "--execution_time=>100ms"])
    self.assertEqual(["lp", "--execution_time=>100ms"], args)
    self.assertIsNone(output_path)

    args, output_path = command_parser.extract_output_file_path(
        ["lp", "--execution_time", ">1.2s"])
    self.assertEqual(["lp", "--execution_time", ">1.2s"], args)
    self.assertIsNone(output_path)

    args, output_path = command_parser.extract_output_file_path(
        ["lp", "-e", ">1200"])
    self.assertEqual(["lp", "-e", ">1200"], args)
    self.assertIsNone(output_path)

    args, output_path = command_parser.extract_output_file_path(
        ["lp", "--foo_value", ">-.2MB"])
    self.assertEqual(["lp", "--foo_value", ">-.2MB"], args)
    self.assertIsNone(output_path)

    args, output_path = command_parser.extract_output_file_path(
        ["lp", "--bar_value", ">-42e3GB"])
    self.assertEqual(["lp", "--bar_value", ">-42e3GB"], args)
    self.assertIsNone(output_path)

    args, output_path = command_parser.extract_output_file_path(
        ["lp", "--execution_time", ">=100ms"])
    self.assertEqual(["lp", "--execution_time", ">=100ms"], args)
    self.assertIsNone(output_path)

    args, output_path = command_parser.extract_output_file_path(
        ["lp", "--execution_time=>=100ms"])
    self.assertEqual(["lp", "--execution_time=>=100ms"], args)
    self.assertIsNone(output_path)
Exemplo n.º 2
0
    def testFlagWithEqualGreaterThanShouldIgnoreIntervalFlags(self):
        args, output_path = command_parser.extract_output_file_path(
            ["lp", "--execution_time=>100ms"])
        self.assertEqual(["lp", "--execution_time=>100ms"], args)
        self.assertIsNone(output_path)

        args, output_path = command_parser.extract_output_file_path(
            ["lp", "--execution_time", ">1.2s"])
        self.assertEqual(["lp", "--execution_time", ">1.2s"], args)
        self.assertIsNone(output_path)

        args, output_path = command_parser.extract_output_file_path(
            ["lp", "-e", ">1200"])
        self.assertEqual(["lp", "-e", ">1200"], args)
        self.assertIsNone(output_path)

        args, output_path = command_parser.extract_output_file_path(
            ["lp", "--foo_value", ">-.2MB"])
        self.assertEqual(["lp", "--foo_value", ">-.2MB"], args)
        self.assertIsNone(output_path)

        args, output_path = command_parser.extract_output_file_path(
            ["lp", "--bar_value", ">-42e3GB"])
        self.assertEqual(["lp", "--bar_value", ">-42e3GB"], args)
        self.assertIsNone(output_path)

        args, output_path = command_parser.extract_output_file_path(
            ["lp", "--execution_time", ">=100ms"])
        self.assertEqual(["lp", "--execution_time", ">=100ms"], args)
        self.assertIsNone(output_path)

        args, output_path = command_parser.extract_output_file_path(
            ["lp", "--execution_time=>=100ms"])
        self.assertEqual(["lp", "--execution_time=>=100ms"], args)
        self.assertIsNone(output_path)
Exemplo n.º 3
0
    def testFlagWithEqualGreaterThanShouldRecognizeFilePaths(self):
        args, output_path = command_parser.extract_output_file_path(
            ["lp", ">1.2s"])
        self.assertEqual(["lp"], args)
        self.assertEqual("1.2s", output_path)

        args, output_path = command_parser.extract_output_file_path(
            ["lp", "--execution_time", ">x.yms"])
        self.assertEqual(["lp", "--execution_time"], args)
        self.assertEqual("x.yms", output_path)

        args, output_path = command_parser.extract_output_file_path(
            ["lp", "--memory", ">a.1kB"])
        self.assertEqual(["lp", "--memory"], args)
        self.assertEqual("a.1kB", output_path)

        args, output_path = command_parser.extract_output_file_path(
            ["lp", "--memory", ">e002MB"])
        self.assertEqual(["lp", "--memory"], args)
        self.assertEqual("e002MB", output_path)
Exemplo n.º 4
0
  def testFlagWithEqualGreaterThanShouldRecognizeFilePaths(self):
    args, output_path = command_parser.extract_output_file_path(
        ["lp", ">1.2s"])
    self.assertEqual(["lp"], args)
    self.assertEqual("1.2s", output_path)

    args, output_path = command_parser.extract_output_file_path(
        ["lp", "--execution_time", ">x.yms"])
    self.assertEqual(["lp", "--execution_time"], args)
    self.assertEqual("x.yms", output_path)

    args, output_path = command_parser.extract_output_file_path(
        ["lp", "--memory", ">a.1kB"])
    self.assertEqual(["lp", "--memory"], args)
    self.assertEqual("a.1kB", output_path)

    args, output_path = command_parser.extract_output_file_path(
        ["lp", "--memory", ">e002MB"])
    self.assertEqual(["lp", "--memory"], args)
    self.assertEqual("e002MB", output_path)
Exemplo n.º 5
0
    def _parse_command(self, command):
        """Parse a command string into prefix and arguments.

    Args:
      command: (str) Command string to be parsed.

    Returns:
      prefix: (str) The command prefix.
      args: (list of str) The command arguments (i.e., not including the
        prefix).
      output_file_path: (str or None) The path to save the screen output
        to (if any).
    """
        command = command.strip()
        if not command:
            return "", [], None

        command_items = command_parser.parse_command(command)
        command_items, output_file_path = command_parser.extract_output_file_path(
            command_items)

        return command_items[0], command_items[1:], output_file_path
Exemplo n.º 6
0
  def _parse_command(self, command):
    """Parse a command string into prefix and arguments.

    Args:
      command: (str) Command string to be parsed.

    Returns:
      prefix: (str) The command prefix.
      args: (list of str) The command arguments (i.e., not including the
        prefix).
      output_file_path: (str or None) The path to save the screen output
        to (if any).
    """
    command = command.strip()
    if not command:
      return "", [], None

    command_items = command_parser.parse_command(command)
    command_items, output_file_path = command_parser.extract_output_file_path(
        command_items)

    return command_items[0], command_items[1:], output_file_path
Exemplo n.º 7
0
 def testOutputPathInLastArgGreaterThanInSecondLastIsHandledCorrectly(self):
   args, output_path = command_parser.extract_output_file_path(
       ["pt", "a:0>", "/tmp/foo.txt"])
   self.assertEqual(["pt", "a:0"], args)
   self.assertEqual(output_path, "/tmp/foo.txt")
Exemplo n.º 8
0
 def testOutputPathMergedWithLastArgIsHandledCorrectly(self):
   args, output_path = command_parser.extract_output_file_path(
       ["pt", "a:0>/tmp/foo.txt"])
   self.assertEqual(["pt", "a:0"], args)
   self.assertEqual(output_path, "/tmp/foo.txt")
Exemplo n.º 9
0
 def testHasGreaterThanSignButNoFileNameCausesSyntaxError(self):
   with self.assertRaisesRegexp(SyntaxError, "Redirect file path is empty"):
     command_parser.extract_output_file_path(
         ["pt", "a:0", ">"])
Exemplo n.º 10
0
 def testHasOutputFilePathInTwoArgsIsReflected(self):
   args, output_path = command_parser.extract_output_file_path(
       ["pt", "a:0", ">", "/tmp/foo.txt"])
   self.assertEqual(["pt", "a:0"], args)
   self.assertEqual(output_path, "/tmp/foo.txt")
Exemplo n.º 11
0
 def testNoOutputFilePathIsReflected(self):
   args, output_path = command_parser.extract_output_file_path(["pt", "a:0"])
   self.assertEqual(["pt", "a:0"], args)
   self.assertIsNone(output_path)
Exemplo n.º 12
0
 def testEmptyArgumentIsHandledCorrectly(self):
     args, output_path = command_parser.extract_output_file_path([])
     self.assertEqual([], args)
     self.assertIsNone(output_path)
Exemplo n.º 13
0
 def testOutputPathInLastArgGreaterThanInSecondLastIsHandledCorrectly(self):
     args, output_path = command_parser.extract_output_file_path(
         ["pt", "a:0>", "/tmp/foo.txt"])
     self.assertEqual(["pt", "a:0"], args)
     self.assertEqual(output_path, "/tmp/foo.txt")
Exemplo n.º 14
0
 def testOutputPathMergedWithLastArgIsHandledCorrectly(self):
     args, output_path = command_parser.extract_output_file_path(
         ["pt", "a:0>/tmp/foo.txt"])
     self.assertEqual(["pt", "a:0"], args)
     self.assertEqual(output_path, "/tmp/foo.txt")
Exemplo n.º 15
0
 def testHasGreaterThanSignButNoFileNameCausesSyntaxError(self):
     with self.assertRaisesRegexp(SyntaxError,
                                  "Redirect file path is empty"):
         command_parser.extract_output_file_path(["pt", "a:0", ">"])
Exemplo n.º 16
0
 def testHasOutputFilePathInTwoArgsIsReflected(self):
     args, output_path = command_parser.extract_output_file_path(
         ["pt", "a:0", ">", "/tmp/foo.txt"])
     self.assertEqual(["pt", "a:0"], args)
     self.assertEqual(output_path, "/tmp/foo.txt")
Exemplo n.º 17
0
 def testEmptyArgumentIsHandledCorrectly(self):
   args, output_path = command_parser.extract_output_file_path([])
   self.assertEqual([], args)
   self.assertIsNone(output_path)
Exemplo n.º 18
0
 def testNoOutputFilePathIsReflected(self):
     args, output_path = command_parser.extract_output_file_path(
         ["pt", "a:0"])
     self.assertEqual(["pt", "a:0"], args)
     self.assertIsNone(output_path)