def test_index_of__key_function_not_found(self): iterable = [ { 'id': 'a' }, { 'id': 'b' }, { 'id': 'c' }, ] result = utils.index_of(iterable, 'D', key=lambda x: str.upper(x['id'])) self.assertEqual(-1, result)
def prompt_for_platform_branch(family): branches = platform_branch_ops.list_nonretired_platform_branches() branches = [branch for branch in branches if branch['PlatformName'] == family] branches = _sort_platform_branches_for_prompt(branches) if len(branches) == 1: return PlatformBranch.from_platform_branch_summary(branches[0]) branch_display_names = [_generate_platform_branch_prompt_text(branch) for branch in branches] default = utils.index_of( branches, value=platform_branch_lifecycle_states.SUPPORTED, key=lambda b: b['LifecycleState']) if default == -1: default = None else: default += 1 io.echo(prompts['platformbranch.prompt']) index = utils.prompt_for_index_in_list(branch_display_names, default=default) return PlatformBranch.from_platform_branch_summary(branches[index])
def test_index_of__value_not_present(self): iterable = ['a', 'b', 'c'] result = utils.index_of(iterable, 'd') self.assertEqual(-1, result)
def test_index_of__tuple(self): iterable = ('a', 'b', 'c') result = utils.index_of(iterable, 'b') self.assertEqual(1, result)
def test_index_of__string(self): iterable = 'abc' result = utils.index_of(iterable, 'b') self.assertEqual(1, result)
def test_index_of__list(self): iterable = ['a', 'b', 'c'] result = utils.index_of(iterable, 'b') self.assertEqual(1, result)