Ejemplo n.º 1
0
def test_last_option_is_updated_on_global_options(index_data):
    index_data['aws']['arguments'] = ['--no-sign-request']
    index_data['aws']['commands'] = ['ec2']
    index_data['aws']['children'] = {
        'ec2': {
            'commands': ['create-tags'],
            'argument_metadata': {},
            'arguments': [],
            'children': {
                'create-tags': {
                    'commands': [],
                    'argument_metadata': {
                        '--resources': {
                            'example': '',
                            'minidoc': 'foo'
                        },
                    },
                    'arguments': ['--resources'],
                    'children': {},
                }
            }
        }
    }
    completer = AWSCLIModelCompleter(index_data)
    completer.autocomplete('ec2 create-tags --resources ')
    assert completer.last_option == '--resources'
    completer.autocomplete('ec2 create-tags --resources f --no-sign-request ')
    assert completer.last_option == '--no-sign-request'
Ejemplo n.º 2
0
def test_autocompletes_argument_names(index_data):
    index_data['aws']['arguments'] = ['--query', '--debug']
    completer = AWSCLIModelCompleter(index_data)
    # These should only appear once in the output.  So we need
    # to know if we're a top level argument or not.
    assert completer.autocomplete('-') == ['--query', '--debug']
    assert completer.autocomplete('--q') == ['--query']
Ejemplo n.º 3
0
def test_last_option_updated_up_releated_api_params(index_data):
    index_data['aws']['commands'] = ['ec2']
    index_data['aws']['children'] = {
        'ec2': {
            'commands': ['create-tags'],
            'argument_metadata': {},
            'arguments': [],
            'children': {
                'create-tags': {
                    'commands': [],
                    'argument_metadata': {
                        '--resources': {
                            'example': '',
                            'minidoc': 'foo'
                        },
                        '--tags': {
                            'example': 'bar',
                            'minidoc': 'baz'
                        },
                    },
                    'arguments': ['--resources', '--tags'],
                    'children': {},
                }
            }
        }
    }
    completer = AWSCLIModelCompleter(index_data)
    completer.autocomplete('ec2 create-tags --resources ')
    assert completer.last_option == '--resources'
    completer.autocomplete('ec2 create-tags --resources f --tags ')
    # last_option should be updated.
    assert completer.last_option == '--tags'
Ejemplo n.º 4
0
def test_last_option_updated_up_releated_api_params(index_data):
    index_data['aws']['commands'] = ['ec2']
    index_data['aws']['children'] = {
        'ec2': {
            'commands': ['create-tags'],
            'argument_metadata': {},
            'arguments': [],
            'children': {
                'create-tags': {
                    'commands': [],
                    'argument_metadata': {
                        '--resources': {'example': '', 'minidoc': 'foo'},
                        '--tags': {'example': 'bar', 'minidoc': 'baz'},
                    },
                    'arguments': ['--resources', '--tags'],
                    'children': {},
                }
            }
        }
    }
    completer = AWSCLIModelCompleter(index_data)
    completer.autocomplete('ec2 create-tags --resources ')
    assert completer.last_option == '--resources'
    completer.autocomplete('ec2 create-tags --resources f --tags ')
    # last_option should be updated.
    assert completer.last_option == '--tags'
Ejemplo n.º 5
0
def test_autocompletes_argument_names(index_data):
    index_data['aws']['arguments'] = ['--query', '--debug']
    completer = AWSCLIModelCompleter(index_data)
    # These should only appear once in the output.  So we need
    # to know if we're a top level argument or not.
    assert completer.autocomplete('-') == ['--query', '--debug']
    assert completer.autocomplete('--q') == ['--query']
Ejemplo n.º 6
0
def test_last_option_is_updated_on_global_options(index_data):
    index_data['aws']['arguments'] = ['--no-sign-request']
    index_data['aws']['commands'] = ['ec2']
    index_data['aws']['children'] = {
        'ec2': {
            'commands': ['create-tags'],
            'argument_metadata': {},
            'arguments': [],
            'children': {
                'create-tags': {
                    'commands': [],
                    'argument_metadata': {
                        '--resources': {'example': '', 'minidoc': 'foo'},
                    },
                    'arguments': ['--resources'],
                    'children': {},
                }
            }
        }
    }
    completer = AWSCLIModelCompleter(index_data)
    completer.autocomplete('ec2 create-tags --resources ')
    assert completer.last_option == '--resources'
    completer.autocomplete('ec2 create-tags --resources f --no-sign-request ')
    assert completer.last_option == '--no-sign-request'
Ejemplo n.º 7
0
def test_autocompletes_argument_names_substring(index_data):
    index_data['aws']['arguments'] = ['--foo', '--bar foo']
    completer = AWSCLIModelCompleter(index_data)
    completer.match_fuzzy = False
    # These should only appear once in the output.  So we need
    # to know if we're a top level argument or not.
    assert completer.autocomplete('--f') == ['--foo']
Ejemplo n.º 8
0
def test_autocompletes_argument_names_substring(index_data):
    index_data['aws']['arguments'] = ['--foo', '--bar foo']
    completer = AWSCLIModelCompleter(index_data)
    completer.match_fuzzy = False
    # These should only appear once in the output.  So we need
    # to know if we're a top level argument or not.
    assert completer.autocomplete('--f') == ['--foo']
Ejemplo n.º 9
0
def test_can_handle_autocomplete_empty_string_twice(index_data):
    # Sometimes prompt_toolkit will try to autocomplete
    # the empty string multiple times.  We need to handle this
    # gracefully.
    index_data['aws']['commands'] = ['first', 'second']
    completer = AWSCLIModelCompleter(index_data)
    assert completer.autocomplete('') == []
    assert completer.autocomplete('') == []
Ejemplo n.º 10
0
def test_can_handle_autocomplete_empty_string_twice(index_data):
    # Sometimes prompt_toolkit will try to autocomplete
    # the empty string multiple times.  We need to handle this
    # gracefully.
    index_data['aws']['commands'] = ['first', 'second']
    completer = AWSCLIModelCompleter(index_data)
    assert completer.autocomplete('') == []
    assert completer.autocomplete('') == []
Ejemplo n.º 11
0
def test_reset_auto_complete(index_data):
    index_data['aws']['commands'] = ['first', 'second']
    completer = AWSCLIModelCompleter(index_data)
    completer.autocomplete('f')
    completer.autocomplete('fi')
    completer.autocomplete('fir')
    # Then the user hits enter.
    # Now they've moved on to the next command.
    assert completer.autocomplete('d') == ['second']
Ejemplo n.º 12
0
def test_reset_auto_complete(index_data):
    index_data['aws']['commands'] = ['first', 'second']
    completer = AWSCLIModelCompleter(index_data)
    completer.autocomplete('f')
    completer.autocomplete('fi')
    completer.autocomplete('fir')
    # Then the user hits enter.
    # Now they've moved on to the next command.
    assert completer.autocomplete('d') == ['second']
Ejemplo n.º 13
0
def test_add_context_changes_context(index_data):
    index_data['aws']['commands'] = ['ec2']
    index_data['aws']['children'] = {
        'ec2': {
            'commands': ['create-tags'],
            'argument_metadata': {},
            'arguments': [],
            'children': {
                'create-tags': {
                    'commands': [],
                    'argument_metadata': {
                        '--resources': {
                            'example': '',
                            'minidoc': 'foo'
                        },
                    },
                    'arguments': ['--resources'],
                    'children': {},
                }
            }
        }
    }
    completer = AWSCLIModelCompleter(index_data)
    completer.reset()
    completer.autocomplete('c')
    assert completer.autocomplete('c') == ['ec2']
    completer.context = ['ec2']
    completer.reset()
    completer.autocomplete('c')
    assert completer.autocomplete('c') == ['create-tags']
Ejemplo n.º 14
0
def test_add_context_changes_context(index_data):
    index_data['aws']['commands'] = ['ec2']
    index_data['aws']['children'] = {
        'ec2': {
            'commands': ['create-tags'],
            'argument_metadata': {},
            'arguments': [],
            'children': {
                'create-tags': {
                    'commands': [],
                    'argument_metadata': {
                        '--resources': {'example': '', 'minidoc': 'foo'},
                    },
                    'arguments': ['--resources'],
                    'children': {},
                }
            }
        }
    }
    completer = AWSCLIModelCompleter(index_data)
    completer.reset()
    completer.autocomplete('c')
    assert completer.autocomplete('c') == ['ec2']
    completer.context = ['ec2']
    completer.reset()
    completer.autocomplete('c')
    assert completer.autocomplete('c') == ['create-tags']
Ejemplo n.º 15
0
def test_everything_completed_on_space(index_data):
    # Right after "aws ec2<space>" all the operations should be
    # autocompleted.
    index_data['aws']['commands'] = ['ec2']
    index_data['aws']['children'] = {
        'ec2': {
            'arguments': [],
            'commands': ['copy-image', 'copy-snapshot', 'other'],
            'children': {},
        }
    }
    completer = AWSCLIModelCompleter(index_data)
    completer.autocomplete('e')
    completer.autocomplete('ec')
    completer.autocomplete('ec2')
    assert completer.autocomplete('ec2 ') == ['copy-image', 'copy-snapshot',
                                              'other']
Ejemplo n.º 16
0
def test_everything_completed_on_space(index_data):
    # Right after "aws ec2<space>" all the operations should be
    # autocompleted.
    index_data['aws']['commands'] = ['ec2']
    index_data['aws']['children'] = {
        'ec2': {
            'arguments': [],
            'commands': ['copy-image', 'copy-snapshot', 'other'],
            'children': {},
        }
    }
    completer = AWSCLIModelCompleter(index_data)
    completer.autocomplete('e')
    completer.autocomplete('ec')
    completer.autocomplete('ec2')
    assert completer.autocomplete('ec2 ') == ['copy-image', 'copy-snapshot',
                                              'other']
Ejemplo n.º 17
0
def test_can_complete_subcommands(index_data):
    index_data['aws']['commands'] = ['ec2']
    index_data['aws']['children'] = {
        'ec2': {
            'arguments': [],
            'commands': ['copy-image', 'copy-snapshot', 'other'],
            'children': {},
        }
    }
    completer = AWSCLIModelCompleter(index_data)
    # The completer tracks state to optimize lookups,
    # so we simulate exactly how it's called.
    completer.autocomplete('e')
    completer.autocomplete('ec')
    completer.autocomplete('ec2')
    completer.autocomplete('ec2 ')
    completer.autocomplete('ec2 c')
    completer.autocomplete('ec2 co')
    assert completer.autocomplete('ec2 cop') == ['copy-image', 'copy-snapshot']
Ejemplo n.º 18
0
def test_completes_service_names_substring(index_data):
    index_data['aws']['commands'] = ['foo', 'bar foo']
    completer = AWSCLIModelCompleter(index_data)
    completer.match_fuzzy = False
    assert completer.autocomplete('fo') == ['foo']
Ejemplo n.º 19
0
def test_completes_service_names(index_data):
    index_data['aws']['commands'] = ['first', 'second']
    completer = AWSCLIModelCompleter(index_data)
    assert completer.autocomplete('fi') == ['first']
Ejemplo n.º 20
0
def test_no_completion(index_data):
    index_data['aws']['commands'] = ['foo', 'bar']
    completer = AWSCLIModelCompleter(index_data)
    assert completer.autocomplete('baz') == []
Ejemplo n.º 21
0
def test_can_handle_autocompleting_same_string_twice(index_data):
    index_data['aws']['commands'] = ['first', 'second']
    completer = AWSCLIModelCompleter(index_data)
    completer.autocomplete('f')
    assert completer.autocomplete('f') == ['first']
Ejemplo n.º 22
0
def test_no_completion(index_data):
    index_data['aws']['commands'] = ['foo', 'bar']
    completer = AWSCLIModelCompleter(index_data)
    assert completer.autocomplete('baz') == []
Ejemplo n.º 23
0
def test_completes_multiple_service_names(index_data):
    index_data['aws']['commands'] = ['abc', 'acd', 'b']
    completer = AWSCLIModelCompleter(index_data)
    assert completer.autocomplete('a') == ['abc', 'acd']
Ejemplo n.º 24
0
def test_completes_multiple_service_names(index_data):
    index_data['aws']['commands'] = ['abc', 'acd', 'b']
    completer = AWSCLIModelCompleter(index_data)
    assert completer.autocomplete('a') == ['abc', 'acd']
Ejemplo n.º 25
0
def test_completes_service_names_substring(index_data):
    index_data['aws']['commands'] = ['foo', 'bar foo']
    completer = AWSCLIModelCompleter(index_data)
    completer.match_fuzzy = False
    assert completer.autocomplete('fo') == ['foo']
Ejemplo n.º 26
0
def test_can_handle_autocompleting_same_string_twice(index_data):
    index_data['aws']['commands'] = ['first', 'second']
    completer = AWSCLIModelCompleter(index_data)
    completer.autocomplete('f')
    assert completer.autocomplete('f') == ['first']
Ejemplo n.º 27
0
def test_can_complete_subcommands(index_data):
    index_data['aws']['commands'] = ['ec2']
    index_data['aws']['children'] = {
        'ec2': {
            'arguments': [],
            'commands': ['copy-image', 'copy-snapshot', 'other'],
            'children': {},
        }
    }
    completer = AWSCLIModelCompleter(index_data)
    # The completer tracks state to optimize lookups,
    # so we simulate exactly how it's called.
    completer.autocomplete('e')
    completer.autocomplete('ec')
    completer.autocomplete('ec2')
    completer.autocomplete('ec2 ')
    completer.autocomplete('ec2 c')
    completer.autocomplete('ec2 co')
    assert completer.autocomplete('ec2 cop') == ['copy-image', 'copy-snapshot']
Ejemplo n.º 28
0
def test_autocomplete_top_leve_services_on_space(index_data):
    index_data['aws']['commands'] = ['first', 'second']
    completer = AWSCLIModelCompleter(index_data)
    assert completer.autocomplete(' ') == ['first', 'second']
Ejemplo n.º 29
0
def test_autocomplete_top_leve_services_on_space(index_data):
    index_data['aws']['commands'] = ['first', 'second']
    completer = AWSCLIModelCompleter(index_data)
    assert completer.autocomplete(' ') == ['first', 'second']
Ejemplo n.º 30
0
def test_reset_after_subcommand_completion(index_data):
    index_data['aws']['commands'] = ['ec2', 's3']
    index_data['aws']['children'] = {
        'ec2': {
            'arguments': [],
            'commands': ['copy-image', 'copy-snapshot', 'other'],
            'children': {},
        }
    }
    completer = AWSCLIModelCompleter(index_data)
    # The completer tracks state to optimize lookups,
    # so we simulate exactly how it's called.
    completer.autocomplete('e')
    completer.autocomplete('ec')
    completer.autocomplete('ec2')
    completer.autocomplete('ec2 ')
    completer.autocomplete('ec2 c')
    completer.autocomplete('ec2 co')
    # The user hits enter and auto completes copy-snapshot.
    # The next request should be to auto complete
    # top level commands:
    assert completer.autocomplete('s') == ['s3']
Ejemplo n.º 31
0
def test_reset_after_subcommand_completion(index_data):
    index_data['aws']['commands'] = ['ec2', 's3']
    index_data['aws']['children'] = {
        'ec2': {
            'arguments': [],
            'commands': ['copy-image', 'copy-snapshot', 'other'],
            'children': {},
        }
    }
    completer = AWSCLIModelCompleter(index_data)
    # The completer tracks state to optimize lookups,
    # so we simulate exactly how it's called.
    completer.autocomplete('e')
    completer.autocomplete('ec')
    completer.autocomplete('ec2')
    completer.autocomplete('ec2 ')
    completer.autocomplete('ec2 c')
    completer.autocomplete('ec2 co')
    # The user hits enter and auto completes copy-snapshot.
    # The next request should be to auto complete
    # top level commands:
    assert completer.autocomplete('s') == ['s3']
Ejemplo n.º 32
0
def test_completes_service_names(index_data):
    index_data['aws']['commands'] = ['first', 'second']
    completer = AWSCLIModelCompleter(index_data)
    assert completer.autocomplete('fi') == ['first']