diff -r 747eec42e7ae distutils2/create.py --- a/distutils2/create.py Mon May 21 17:01:44 2012 -0400 +++ b/distutils2/create.py Sat May 26 21:05:25 2012 -0400 @@ -668,25 +668,29 @@ def set_maturity_status(self, classifiers): maturity_name = lambda mat: mat.split('- ')[-1] - maturity_question = '''\ - Please select the project status: + choices = {} + choice_prompts = [] + for i, n in enumerate(PROJECT_MATURITY): + choices[str(i + 1)] = n + choice_prompts.append('%s - %s' % (i + 1, maturity_name(n))) - %s + maturity_question = '''Please select the project status: - Status''' % '\n'.join('%s - %s' % (i, maturity_name(n)) - for i, n in enumerate(PROJECT_MATURITY)) +%s + +Status''' % '\n'.join(choice_prompts) + while True: choice = ask(dedent(maturity_question), required=False) + if not choice: + return - if choice: - try: - choice = int(choice) - 1 - key = PROJECT_MATURITY[choice] - classifiers.add(key) - return - except (IndexError, ValueError): - logger.error( - "Invalid selection, type a single digit number.") + try: + classifiers.add(choices[choice]) + return + except (KeyError): + logger.error( + "Invalid selection, type a number from the list above.") def main(): diff -r 747eec42e7ae distutils2/tests/test_create.py --- a/distutils2/tests/test_create.py Mon May 21 17:01:44 2012 -0400 +++ b/distutils2/tests/test_create.py Sat May 26 21:05:25 2012 -0400 @@ -46,6 +46,17 @@ self.assertEqual('b', ask(str(list(range(0, 70))), default='c', lengthy=True)) + def test_set_maturity_status(self): + mainprogram = MainProgram() + create.raw_input = Inputs('', '0', '2') + # test skipping choosing a maturity status + mainprogram.set_maturity_status(mainprogram.classifiers) + self.assertEqual(set(), mainprogram.classifiers) + # test entering a bad option followed by a good one. + mainprogram.set_maturity_status(mainprogram.classifiers) + self.assertEqual(set([create.PROJECT_MATURITY[1]]), + mainprogram.classifiers) + def test_set_multi(self): mainprogram = MainProgram() create.raw_input = Inputs('aaaaa')