Пример #1
0
def test_completions():
    completer = Completer()
    for cmdline, point, expected_results in COMPLETIONS:
        if point == -1:
            point = len(cmdline)
        results = set(completer.complete(cmdline, point))
        yield check_completer, cmdline, results, expected_results
Пример #2
0
 def test_complete_top_level_args(self):
     commands = {
         'subcommands': {},
         'arguments': ['foo', 'bar']
     }
     completer = Completer(
         self.clidriver_creator.create_clidriver(commands))
     self.assert_completion(completer, 'aws --', ['--foo', '--bar'])
Пример #3
0
 def test_complete_service_arg_with_arg_already_used(self):
     commands = {
         'subcommands': {
             'baz': {}
         },
         'arguments': ['foo', 'bar']
     }
     completer = Completer(
         self.clidriver_creator.create_clidriver(commands))
     self.assert_completion(completer, 'aws baz --foo --f', [])
Пример #4
0
 def test_complete_service_arguments(self):
     commands = {
         'subcommands': {
             'foo': {}
         },
         'arguments': ['baz', 'bin']
     }
     completer = Completer(
         self.clidriver_creator.create_clidriver(commands))
     self.assert_completion(completer, 'aws foo --', ['--baz', '--bin'])
Пример #5
0
 def test_complete_operation_arg_when_arg_already_used(self):
     commands = {
         'subcommands': {
             'foo': {'subcommands': {
                 'bar': {'arguments': ['baz']}
             }}
         },
         'arguments': []
     }
     completer = Completer(
         self.clidriver_creator.create_clidriver(commands))
     self.assert_completion(completer, 'aws foo bar --baz --b', [])
Пример #6
0
 def test_complete_undocumented_command(self):
     class UndocumentedCommand(CLICommand):
         _UNDOCUMENTED = True
     commands = {
         'subcommands': {
             'foo': {},
             'bar': UndocumentedCommand()
         },
         'arguments': []
     }
     completer = Completer(
         self.clidriver_creator.create_clidriver(commands))
     self.assert_completion(completer, 'aws ', ['foo'])
Пример #7
0
 def test_complete_partial_service_arguments(self):
     commands = {
         'subcommands': {
             'biz': {}
         },
         'arguments': ['foo', 'bar', 'foobar', 'fubar']
     }
     completer = Completer(
         self.clidriver_creator.create_clidriver(commands))
     self.assert_completion(completer, 'aws biz --f', [
         '--foo', '--fubar', '--foobar'])
     self.assert_completion(completer, 'aws biz --fo', [
         '--foo', '--foobar'])
     self.assert_completion(completer, 'aws biz --foob', ['--foobar'])
Пример #8
0
def test_completions():
    environ = {
        'AWS_DATA_PATH': os.environ['AWS_DATA_PATH'],
        'AWS_DEFAULT_REGION': 'us-east-1',
        'AWS_ACCESS_KEY_ID': 'access_key',
        'AWS_SECRET_ACCESS_KEY': 'secret_key',
        'AWS_CONFIG_FILE': '',
    }
    with mock.patch('os.environ', environ):
        completer = Completer()
        for cmdline, point, expected_results in COMPLETIONS:
            if point == -1:
                point = len(cmdline)
            results = set(completer.complete(cmdline, point))
            yield check_completer, cmdline, results, expected_results
Пример #9
0
 def test_complete_on_invalid_service(self):
     commands = {
         'subcommands': {
             'foo': {},
             'bar': {
                 'subcommands': {
                     'baz': {}
                 }
             }
         },
         'arguments': []
     }
     completer = Completer(
         self.clidriver_creator.create_clidriver(commands))
     self.assert_completion(completer, 'aws bin', [])
Пример #10
0
 def test_complete_positional_argument(self):
     commands = {
         'subcommands': {
             'foo': {'subcommands': {
                 'bar': {'arguments': [
                     'baz',
                     CustomArgument('bin', positional_arg=True)
                 ]}
             }}
         },
         'arguments': []
     }
     completer = Completer(
         self.clidriver_creator.create_clidriver(commands))
     self.assert_completion(completer, 'aws foo bar --bin ', [])
     self.assert_completion(completer, 'aws foo bar --bin blah --',
                            ['--baz'])
Пример #11
0
 def test_complete_partial_operation_arguments(self):
     commands = {
         'subcommands': {
             'foo': {'subcommands': {
                 'bar': {'arguments': ['base', 'baz', 'air']}
             }}
         },
         'arguments': ['bin']
     }
     completer = Completer(
         self.clidriver_creator.create_clidriver(commands))
     self.assert_completion(completer, 'aws foo bar --b', [
         '--base', '--baz', '--bin'])
     self.assert_completion(completer, 'aws foo bar --ba', [
         '--base', '--baz'])
     self.assert_completion(completer, 'aws foo bar --bas', ['--base'])
     self.assert_completion(completer, 'aws foo bar --base', [])
Пример #12
0
 def setUp(self):
     super(TestCompleteCustomCommands, self).setUp()
     custom_arguments = [{'name': 'recursive'}, {'name': 'sse'}]
     custom_commands = [
         self.create_custom_command('mb'),
         self.create_custom_command('mv'),
         self.create_custom_command('cp', arguments=custom_arguments)
     ]
     custom_service = self.create_custom_command('s3', custom_commands)
     clidriver = self.clidriver_creator.create_clidriver({
         'subcommands': {
             's3': custom_service['command_class'](mock.Mock()),
             'foo': {}
         },
         'arguments': ['bar']
     })
     self.completer = Completer(clidriver)
Пример #13
0
 def test_complete_partial_service_name(self):
     commands = {
         'subcommands': {
             'cloudfront': {},
             'cloudformation': {},
             'cloudhsm': {},
             'sts': {}
         },
         'arguments': []
     }
     completer = Completer(
         self.clidriver_creator.create_clidriver(commands))
     self.assert_completion(completer, 'aws cloud', [
         'cloudfront', 'cloudformation', 'cloudhsm'])
     self.assert_completion(completer, 'aws cloudf', [
         'cloudfront', 'cloudformation'])
     self.assert_completion(completer, 'aws cloudfr', ['cloudfront'])
     self.assert_completion(completer, 'aws cloudfront', [])
Пример #14
0
def start_server(ns):
    clients = []
    sock = socket()
    try:
        sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
        sock.bind((ns.address, ns.port))
        sock.listen(5)

        completer = Completer()

        ns.logfile = None
        if ns.log:
            ns.logfile = open(ns.log, 'a')

        while True:
            c, a = sock.accept()
            log(ns, f'New client from {a}')
            clients.append(c)
            ClientThread(c, a, completer, ns).start()
    except:
        if ns.logfile:
            try:
                traceback.print_exc(file=ns.logfile)
                traceback.print_stack(file=ns.logfile)
            except:
                traceback.print_exc()
                traceback.print_stack()
    finally:
        for c in clients:
            try:
                c.shutdown(SHUT_RDWR)
                c.close()
            except:
                pass
        try:
            sock.shutdown(SHUT_RDWR)
            sock.close()
        except:
            pass
        if ns.log:
            try:
                ns.logfile.close()
            except:
                pass
Пример #15
0
 def test_complete_partial_service_commands(self):
     commands = {
         'subcommands': {
             'foo': {
                 'subcommands': {
                     'barb': {
                         'arguments': ['nil']
                     },
                     'baz': {},
                     'biz': {},
                     'foobar': {}
                 }
             }
         },
         'arguments': []
     }
     completer = Completer(
         self.clidriver_creator.create_clidriver(commands))
     self.assert_completion(completer, 'aws foo b', ['barb', 'baz', 'biz'])
     self.assert_completion(completer, 'aws foo ba', ['barb', 'baz'])
     self.assert_completion(completer, 'aws foo bar', ['barb'])
     self.assert_completion(completer, 'aws foo barb', [])