コード例 #1
0
    def testParseLeadingTrailingWhitespaces(self):
        command = "  foo bar baz qux   "
        self.assertEqual(["foo", "bar", "baz", "qux"],
                         command_parser.parse_command(command))

        command = "\nfoo bar baz qux\n"
        self.assertEqual(["foo", "bar", "baz", "qux"],
                         command_parser.parse_command(command))
コード例 #2
0
    def testParseCommandWithTwoArgsContainingQuotes(self):
        command = "foo \"bar\" \"qux\""
        self.assertEqual(["foo", "bar", "qux"],
                         command_parser.parse_command(command))

        command = "foo \"\" \"qux\""
        self.assertEqual(["foo", "", "qux"],
                         command_parser.parse_command(command))
コード例 #3
0
  def testParseLeadingTrailingWhitespaces(self):
    command = "  foo bar baz qux   "
    self.assertEqual(["foo", "bar", "baz", "qux"],
                     command_parser.parse_command(command))

    command = "\nfoo bar baz qux\n"
    self.assertEqual(["foo", "bar", "baz", "qux"],
                     command_parser.parse_command(command))
コード例 #4
0
  def testParseCommandWithTwoArgsContainingBrackets(self):
    command = "pt foo[1, :] bar[:, 2]"
    self.assertEqual(["pt", "foo[1, :]", "bar[:, 2]"],
                     command_parser.parse_command(command))

    command = "pt foo[] bar[:, 2]"
    self.assertEqual(["pt", "foo[]", "bar[:, 2]"],
                     command_parser.parse_command(command))
コード例 #5
0
    def testParseCommandWithTwoArgsContainingBrackets(self):
        command = "pt foo[1, :] bar[:, 2]"
        self.assertEqual(["pt", "foo[1, :]", "bar[:, 2]"],
                         command_parser.parse_command(command))

        command = "pt foo[] bar[:, 2]"
        self.assertEqual(["pt", "foo[]", "bar[:, 2]"],
                         command_parser.parse_command(command))
コード例 #6
0
  def testParseCommandWithTwoArgsContainingQuotes(self):
    command = "foo \"bar\" \"qux\""
    self.assertEqual(["foo", "bar", "qux"],
                     command_parser.parse_command(command))

    command = "foo \"\" \"qux\""
    self.assertEqual(["foo", "", "qux"],
                     command_parser.parse_command(command))
コード例 #7
0
    def testParseCommandsWithQuotes(self):
        command = "inject_value foo \"np.zeros([100, 500])\""
        self.assertEqual(["inject_value", "foo", "np.zeros([100, 500])"],
                         command_parser.parse_command(command))
        # The pair of double quotes should have been stripped.

        command = "\"command prefix with spaces\" arg1"
        self.assertEqual(["command prefix with spaces", "arg1"],
                         command_parser.parse_command(command))
コード例 #8
0
  def testParseCommandsWithQuotes(self):
    command = "inject_value foo \"np.zeros([100, 500])\""
    self.assertEqual(["inject_value", "foo", "np.zeros([100, 500])"],
                     command_parser.parse_command(command))
    # The pair of double quotes should have been stripped.

    command = "\"command prefix with spaces\" arg1"
    self.assertEqual(["command prefix with spaces", "arg1"],
                     command_parser.parse_command(command))
コード例 #9
0
    def testParseCommandsWithBrackets(self):
        command = "pt foo[1, 2, :]"
        self.assertEqual(["pt", "foo[1, 2, :]"],
                         command_parser.parse_command(command))
        command = "pt  foo[1, 2, :]   -a"
        self.assertEqual(["pt", "foo[1, 2, :]", "-a"],
                         command_parser.parse_command(command))

        command = "inject_value foo [1, 2,:] 0"
        self.assertEqual(["inject_value", "foo", "[1, 2,:]", "0"],
                         command_parser.parse_command(command))
コード例 #10
0
  def testParseCommandsWithBrackets(self):
    command = "pt foo[1, 2, :]"
    self.assertEqual(["pt", "foo[1, 2, :]"],
                     command_parser.parse_command(command))
    command = "pt  foo[1, 2, :]   -a"
    self.assertEqual(["pt", "foo[1, 2, :]", "-a"],
                     command_parser.parse_command(command))

    command = "inject_value foo [1, 2,:] 0"
    self.assertEqual(["inject_value", "foo", "[1, 2,:]", "0"],
                     command_parser.parse_command(command))
コード例 #11
0
  def testParseNoBracketsOrQuotes(self):
    command = ""
    self.assertEqual([], command_parser.parse_command(command))

    command = "a"
    self.assertEqual(["a"], command_parser.parse_command(command))

    command = "foo bar baz qux"
    self.assertEqual(["foo", "bar", "baz", "qux"],
                     command_parser.parse_command(command))

    command = "foo bar\tbaz\t qux"
    self.assertEqual(["foo", "bar", "baz", "qux"],
                     command_parser.parse_command(command))
コード例 #12
0
    def testParseNoBracketsOrQuotes(self):
        command = ""
        self.assertEqual([], command_parser.parse_command(command))

        command = "a"
        self.assertEqual(["a"], command_parser.parse_command(command))

        command = "foo bar baz qux"
        self.assertEqual(["foo", "bar", "baz", "qux"],
                         command_parser.parse_command(command))

        command = "foo bar\tbaz\t qux"
        self.assertEqual(["foo", "bar", "baz", "qux"],
                         command_parser.parse_command(command))
コード例 #13
0
ファイル: curses_ui.py プロジェクト: HowieYang0/notmnist-ex
    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).
    """
        command = command.strip()
        if not command:
            return "", []

        command_items = command_parser.parse_command(command)
        return command_items[0], command_items[1:]
コード例 #14
0
ファイル: curses_ui.py プロジェクト: chinnadhurai/block_rnn
  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).
    """
    command = command.strip()
    if not command:
      return "", []

    command_items = command_parser.parse_command(command)
    return command_items[0], command_items[1:]
コード例 #15
0
ファイル: base_ui.py プロジェクト: AbhinavJain13/tensorflow
  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
コード例 #16
0
ファイル: base_ui.py プロジェクト: Harryi0/tinyML
    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
コード例 #17
0
 def testParseCommandWithUnmatchedBracket(self):
   command = "pt  foo[1, 2, :"
   self.assertNotEqual(["pt", "foo[1, 2, :]"],
                       command_parser.parse_command(command))
コード例 #18
0
 def testParseCommandWithUnmatchedBracket(self):
     command = "pt  foo[1, 2, :"
     self.assertNotEqual(["pt", "foo[1, 2, :]"],
                         command_parser.parse_command(command))