class LoadCompletionsTest(unittest.TestCase):

    def setUp(self):
        self.completion_index = CompletionIndex()
        # This would probably be cleaner with a pytest.fixture like
        # test_completions.index_data
        DATA = (
            '{"aws": '
            '{"commands": ["devicefarm", "foo"], '
            '"arguments": ["--debug", "--endpoint-url"], '
            '"children": {"devicefarm": '
            '{"commands": ["create-device-pool"], '
            '"children": {"create-device-pool": '
            '{"commands": [], '
            '"arguments": ["--project-arn", "--name"]}}}, '
            '"foo": '
            '{"commands": ["bar"], '
            '"children": {"bar": '
            '{"commands": [], "arguments": ["--baz"]}}}}}}'
        )
        self.completion_index.load_index = lambda x: DATA
        self.completion_index.load_completions()

    def test_load_completions(self):
        assert self.completion_index.commands == [
            'devicefarm', 'foo']
        assert self.completion_index.subcommands == [
            'create-device-pool', 'bar']
        assert self.completion_index.global_opts == [
            '--debug', '--endpoint-url']
        assert self.completion_index.args_opts == set([
            '--project-arn', '--name', '--baz'])
class LoadCompletionsTest(unittest.TestCase):
    def setUp(self):
        self.completion_index = CompletionIndex()
        # This would probably be cleaner with a pytest.fixture like
        # test_completions.index_data
        DATA = ('{"aws": '
                '{"commands": ["devicefarm", "foo"], '
                '"arguments": ["--debug", "--endpoint-url"], '
                '"children": {"devicefarm": '
                '{"commands": ["create-device-pool"], '
                '"children": {"create-device-pool": '
                '{"commands": [], '
                '"arguments": ["--project-arn", "--name"]}}}, '
                '"foo": '
                '{"commands": ["bar"], '
                '"children": {"bar": '
                '{"commands": [], "arguments": ["--baz"]}}}}}}')
        self.completion_index.load_index = lambda x: DATA
        self.completion_index.load_completions()

    def test_load_completions(self):
        assert self.completion_index.commands == ['devicefarm', 'foo']
        assert self.completion_index.subcommands == [
            'create-device-pool', 'bar'
        ]
        assert self.completion_index.global_opts == [
            '--debug', '--endpoint-url'
        ]
        assert self.completion_index.args_opts == set(
            ['--project-arn', '--name', '--baz'])
Esempio n. 3
0
class ShellLexer(RegexLexer):
    """Provides highlighting for commands, subcommands, arguments, and options.

    :type completion_index: :class:`CompletionIndex`
    :param completion_index: Completion index used to determine commands,
        subcommands, arguments, and options for highlighting.

    :type tokens: dict
    :param tokens: A dict of (`pygments.lexer`, `pygments.token`) used for
        pygments highlighting.
    """
    completion_index = CompletionIndex()
    completion_index.load_completions()
    tokens = {
        'root': [
            # ec2, s3, elb...
            (words(tuple(completion_index.commands),
                   prefix=r'\b',
                   suffix=r'\b'), Literal.String),
            # describe-instances
            (words(tuple(completion_index.subcommands),
                   prefix=r'\b',
                   suffix=r'\b'), Name.Class),
            # --instance-ids
            (words(tuple(list(completion_index.args_opts)),
                   prefix=r'',
                   suffix=r'\b'), Keyword.Declaration),
            # --profile
            (words(tuple(completion_index.global_opts),
                   prefix=r'',
                   suffix=r'\b'), Operator.Word),
            # Everything else
            (r'.*\n', Text),
        ]
    }
 def setUp(self):
     self.completion_index = CompletionIndex()
     # This would probably be cleaner with a pytest.fixture like
     # test_completions.index_data
     DATA = ('{"aws": '
             '{"commands": ["devicefarm", "foo"], '
             '"arguments": ["--debug", "--endpoint-url"], '
             '"children": {"devicefarm": '
             '{"commands": ["create-device-pool"], '
             '"children": {"create-device-pool": '
             '{"commands": [], '
             '"arguments": ["--project-arn", "--name"]}}}, '
             '"foo": '
             '{"commands": ["bar"], '
             '"children": {"bar": '
             '{"commands": [], "arguments": ["--baz"]}}}}}}')
     self.completion_index.load_index = lambda x: DATA
     self.completion_index.load_completions()
 def setUp(self):
     self.completion_index = CompletionIndex()
     # This would probably be cleaner with a pytest.fixture like
     # test_completions.index_data
     DATA = (
         '{"aws": '
         '{"commands": ["devicefarm", "foo"], '
         '"arguments": ["--debug", "--endpoint-url"], '
         '"children": {"devicefarm": '
         '{"commands": ["create-device-pool"], '
         '"children": {"create-device-pool": '
         '{"commands": [], '
         '"arguments": ["--project-arn", "--name"]}}}, '
         '"foo": '
         '{"commands": ["bar"], '
         '"children": {"bar": '
         '{"commands": [], "arguments": ["--baz"]}}}}}}'
     )
     self.completion_index.load_index = lambda x: DATA
     self.completion_index.load_completions()