Пример #1
0
 def test_split_keep_original(self):
     """Test if splitting with keep=True yields the original string."""
     for case in test_data.strip().splitlines():
         cmd = case.split('/')[0]
         with self.subTest(cmd=cmd):
             items = split.split(cmd, keep=True)
             self.assertEqual(''.join(items), cmd)
Пример #2
0
 def test_split_keep(self):
     """Test splitting with keep=True."""
     for case in test_data.strip().splitlines():
         cmd, _mid, out = case.split('/')[:-1]
         with self.subTest(cmd=cmd):
             items = split.split(cmd, keep=True)
             self.assertEqual(items, out.split('|'))
Пример #3
0
 def test_split(self):
     """Test splitting."""
     for case in test_data.strip().splitlines():
         cmd, out = case.split('/')[:-2]
         with self.subTest(cmd=cmd):
             items = split.split(cmd)
             self.assertEqual(items, out.split('|'))
Пример #4
0
 def test_split_keep(self):
     """Test splitting with keep=True."""
     for case in test_data.strip().splitlines():
         cmd, _mid, out = case.split('/')[:-1]
         with self.subTest(cmd=cmd):
             items = split.split(cmd, keep=True)
             self.assertEqual(items, out.split('|'))
Пример #5
0
 def test_split_keep_original(self):
     """Test if splitting with keep=True yields the original string."""
     for case in test_data.strip().splitlines():
         cmd = case.split('/')[0]
         with self.subTest(cmd=cmd):
             items = split.split(cmd, keep=True)
             self.assertEqual(''.join(items), cmd)
Пример #6
0
 def test_split(self):
     """Test splitting."""
     for case in test_data.strip().splitlines():
         cmd, out = case.split('/')[:-2]
         with self.subTest(cmd=cmd):
             items = split.split(cmd)
             self.assertEqual(items, out.split('|'))
Пример #7
0
    def _split_args(self, argstr, keep):
        """Split the arguments from an arg string.

        Args:
            argstr: An argument string.
            keep: Whether to keep special chars and whitespace

        Return:
            A list containing the splitted strings.
        """
        if not argstr:
            self._args = []
        elif self._cmd.split:
            self._args = split.split(argstr, keep=keep)
        else:
            # If split=False, we still want to split the flags, but not
            # everything after that.
            # We first split the arg string and check the index of the first
            # non-flag args, then we re-split again properly.
            # example:
            #
            # input: "--foo -v bar baz"
            # first split: ['--foo', '-v', 'bar', 'baz']
            #                0        1     2      3
            # second split: ['--foo', '-v', 'bar baz']
            # (maxsplit=2)
            split_args = split.simple_split(argstr, keep=keep)
            for i, arg in enumerate(split_args):
                arg = arg.strip()
                if not arg.startswith('-'):
                    self._args = split.simple_split(argstr, keep=keep,
                                                    maxsplit=i)
                    break
            else:
                # If there are only flags, we got it right on the first try
                # already.
                self._args = split_args