def multifilechooser_helper(names):
            # Note that the MultiFileChooser widget produces a single string with
            # paths separated by os.pathsep.
            if names:
                prefix = names[0] + ' '
            else:
                prefix = ''

            expected_outputs = [
                (names, None, ''),
                (names, prefix + '"abc"', 'abc'),
                (names, prefix + '"abc" "def"', os.pathsep.join(['abc', 'def'])),
                # paths with spaces
                (names, prefix + '"a b c"', 'a b c'),
                (names, prefix + '"a b c" "d e f"', os.pathsep.join(['a b c', 'd e f'])),
            ]

            for commands, expected, widget_result in expected_outputs:
                result = formatters.multiFileChooser({'commands': commands}, widget_result)
                self.assertEqual(result, expected)
                # make sure that argparse actually accepts it as valid.
                if result:
                    parser = argparse.ArgumentParser()
                    if not names:
                        names = ["file"]
                    parser.add_argument(names[0], nargs='+')
                    parser.parse_args(shlex.split(result))
Example #2
0
 def formatOutput(self, metadata, value):
     return formatters.multiFileChooser(metadata, value)