diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 70a1f55..746eb58 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -6,4 +6,4 @@ This project has adopted the `Microsoft Open Source Code of Conduct `__ or contact `opencode@microsoft.com `__ with any additional questions or comments. If you would like to become an active contributor to this project please -follow the instructions provided in `Contribution License Agreement `__ +follow the instructions provided in `Contribution License Agreement `__. diff --git a/README.rst b/README.rst index 4429970..ed9bac3 100644 --- a/README.rst +++ b/README.rst @@ -39,7 +39,7 @@ You can install knack as a non-privilaged user to your home directory by adding ------------ -.. note:: The project is in `initial development phase `__ . We recommend pinning to at least a specific minor version when marking **knack** as a dependency in your project. +.. note:: The project is in `initial development phase `__. We recommend pinning to at least a specific minor version when marking **knack** as a dependency in your project. ------------ @@ -141,7 +141,7 @@ This project has adopted the `Microsoft Open Source Code of Conduct `__ or contact `opencode@microsoft.com `__ with any additional questions or comments. If you would like to become an active contributor to this project please -follow the instructions provided in `Contribution License Agreement `__ +follow the instructions provided in `Contribution License Agreement `__. License diff --git a/knack/help.py b/knack/help.py index 850bbbd..1dcdf36 100644 --- a/knack/help.py +++ b/knack/help.py @@ -307,7 +307,7 @@ def __init__(self, name_source, description, required, choices=None, def update_from_data(self, data): if self.name != data.get('name'): - raise HelpAuthoringException(u"mismatched name {0} vs. {1}" + raise HelpAuthoringException(u"mismatched name {} vs. {}" .format(self.name, data.get('name'))) @@ -426,13 +426,13 @@ def _print_items(layouts): @staticmethod def _get_choices_defaults_sources_str(p): - choice_str = u' Allowed values: {0}.'.format(', '.join(sorted([str(x) for x in p.choices]))) \ + choice_str = u' Allowed values: {}.'.format(', '.join(sorted([str(x) for x in p.choices]))) \ if p.choices else '' - default_str = u' Default: {0}.'.format(p.default) \ + default_str = u' Default: {}.'.format(p.default) \ if p.default and p.default != argparse.SUPPRESS else '' - value_sources_str = u' Values from: {0}.'.format(', '.join(p.value_sources)) \ + value_sources_str = u' Values from: {}.'.format(', '.join(p.value_sources)) \ if p.value_sources else '' - return u'{0}{1}{2}'.format(choice_str, default_str, value_sources_str) + return u'{}{}{}'.format(choice_str, default_str, value_sources_str) @staticmethod def print_description_list(help_files): @@ -440,11 +440,11 @@ def print_description_list(help_files): max_length = max(len(f.name) for f in help_files) if help_files else 0 for help_file in sorted(help_files, key=lambda h: h.name): column_indent = max_length - len(help_file.name) - _print_indent(u'{0}{1}{2}'.format(help_file.name, - ' ' * column_indent, - FIRST_LINE_PREFIX + help_file.short_summary - if help_file.short_summary - else ''), + _print_indent(u'{}{}{}'.format(help_file.name, + ' ' * column_indent, + FIRST_LINE_PREFIX + help_file.short_summary + if help_file.short_summary + else ''), indent, _get_hanging_indent(max_length, indent)) diff --git a/tests/test_command_registration.py b/tests/test_command_registration.py index eb90e8e..82e2d60 100644 --- a/tests/test_command_registration.py +++ b/tests/test_command_registration.py @@ -62,9 +62,9 @@ def test_register_cli_argument(self): TestCommandRegistration.sample_command_handler.__name__)) with ArgumentsContext(cl, command_name) as ac: ac.argument('resource_name', CLIArgumentType( - options_list=('--wonky-name', '-n'), metavar='RNAME', help='Completely WONKY name...', - required=False - )) + options_list=('--wonky-name', '-n'), metavar='RNAME', help='Completely WONKY name...', + required=False + )) cl.load_arguments(command_name) self.assertEqual(len(cl.command_table), 1, 'We expect exactly one command in the command table') command_metadata = cl.command_table[command_name] @@ -192,9 +192,9 @@ def test_register_cli_argument_with_overrides(self): command1 = cl.command_table['test sample-get'].arguments['resource_name'] command2 = cl.command_table['test command sample-get-1'].arguments['resource_name'] command3 = cl.command_table['test command sample-get-2'].arguments['resource_name'] - self.assertTrue(command1.options['help'] == 'foo help') - self.assertTrue(command2.options['help'] == 'first modification') - self.assertTrue(command3.options['help'] == 'second modification') + self.assertEqual(command1.options['help'], 'foo help') + self.assertEqual(command2.options['help'], 'first modification') + self.assertEqual(command3.options['help'], 'second modification') def test_register_extra_cli_argument(self): cl = CLICommandsLoader(self.mock_ctx) @@ -308,10 +308,10 @@ def test_validator_completer(): g.command('foo', sample_sdk_method.__name__) with ArgumentsContext(cl, 'override_using_register_cli_argument') as ac: ac.argument('param_a', - options_list=('--overridden', '-r'), - validator=test_validator_completer, - completer=test_validator_completer, - required=False) + options_list=('--overridden', '-r'), + validator=test_validator_completer, + completer=test_validator_completer, + required=False) cl.load_arguments(command_name) command_metadata = cl.command_table[command_name] @@ -331,15 +331,15 @@ def test_override_argtype_with_argtype(self): completer=None, overrides=arg, help='overridden', required=CLIArgumentType.REMOVE) self.assertEqual(overriding_argtype.settings['validator'], 'overridden') - self.assertEqual(overriding_argtype.settings['completer'], None) + self.assertIsNone(overriding_argtype.settings['completer']) self.assertEqual(overriding_argtype.settings['options_list'], ('--overridden',)) self.assertEqual(overriding_argtype.settings['help'], 'overridden') self.assertEqual(overriding_argtype.settings['required'], CLIArgumentType.REMOVE) cmd_arg = CLICommandArgument(dest='whatever', argtype=overriding_argtype, help=CLIArgumentType.REMOVE) - self.assertFalse('required' in cmd_arg.options) - self.assertFalse('help' in cmd_arg.options) + self.assertNotIn('required', cmd_arg.options) + self.assertNotIn('help', cmd_arg.options) def test_cli_ctx_type_error(self): with self.assertRaises(TypeError): diff --git a/tests/test_config.py b/tests/test_config.py index 8116ffa..190894a 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -110,7 +110,7 @@ def test_getboolean(self): value = 'true' self.cli_config.config_parser.add_section(section) self.cli_config.config_parser.set(section, option, value) - self.assertEqual(self.cli_config.getboolean(section, option), True) + self.assertTrue(self.cli_config.getboolean(section, option)) def test_getboolean_error(self): section = 'MySection' diff --git a/tests/test_deprecation.py b/tests/test_deprecation.py index e674872..721e4d1 100644 --- a/tests/test_deprecation.py +++ b/tests/test_deprecation.py @@ -113,7 +113,7 @@ def test_deprecate_command_help_hidden(self): --arg -a : Allowed values: 1, 2, 3. --arg3 """.format(self.cli_ctx.name) - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_deprecate_command_plain_execute(self): @@ -121,7 +121,7 @@ def test_deprecate_command_plain_execute(self): self.cli_ctx.invoke('cmd1 -b b'.split()) actual = self.io.getvalue() expected = "This command has been deprecated and will be removed in a future release. Use 'alt-cmd1' instead." - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_deprecate_command_hidden_execute(self): @@ -129,7 +129,7 @@ def test_deprecate_command_hidden_execute(self): self.cli_ctx.invoke('cmd3 -b b'.split()) actual = self.io.getvalue() expected = "This command has been deprecated and will be removed in a future release. Use 'alt-cmd3' instead." - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_deprecate_command_expiring_execute(self): @@ -137,7 +137,7 @@ def test_deprecate_command_expiring_execute(self): self.cli_ctx.invoke('cmd4 -b b'.split()) actual = self.io.getvalue() expected = "This command has been deprecated and will be removed in version '1.0.0'. Use 'alt-cmd4' instead." - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_deprecate_command_expired_execute(self): @@ -222,7 +222,7 @@ def test_deprecate_command_group_help_hidden(self): cmd1 : Short summary here. """.format(self.cli_ctx.name) - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_deprecate_command_group_help_expiring(self): @@ -236,7 +236,7 @@ def test_deprecate_command_group_help_expiring(self): This command group has been deprecated and will be removed in version '1.0.0'. Use 'alt-group4' instead. """.format(self.cli_ctx.name) - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_deprecate_command_group_expired(self): @@ -259,7 +259,7 @@ def test_deprecate_command_implicitly(self): command group 'group1' is deprecated and will be removed in a future release. Use 'alt- group1' instead. """.format(self.cli_ctx.name) - self.assertTrue(expected in actual) + self.assertIn(expected, actual) class TestArgumentDeprecation(unittest.TestCase): @@ -337,7 +337,7 @@ def test_deprecate_arguments_execute(self): self.cli_ctx.invoke('arg-test --arg1 foo --opt1 bar'.split()) actual = self.io.getvalue() expected = "Argument 'arg1' has been deprecated and will be removed in a future release." - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_deprecate_arguments_execute_hidden(self): @@ -345,7 +345,7 @@ def test_deprecate_arguments_execute_hidden(self): self.cli_ctx.invoke('arg-test --arg1 foo --opt1 bar --arg3 bar'.split()) actual = self.io.getvalue() expected = "Argument 'arg3' has been deprecated and will be removed in a future release." - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_deprecate_arguments_execute_expiring(self): @@ -353,7 +353,7 @@ def test_deprecate_arguments_execute_expiring(self): self.cli_ctx.invoke('arg-test --arg1 foo --opt1 bar --arg4 bar'.split()) actual = self.io.getvalue() expected = "Argument 'arg4' has been deprecated and will be removed in version '1.0.0'." - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_deprecate_arguments_execute_expired(self): @@ -362,7 +362,7 @@ def test_deprecate_arguments_execute_expired(self): self.cli_ctx.invoke('arg-test --arg1 foo --opt1 bar --arg5 foo'.split()) actual = self.io.getvalue() expected = 'unrecognized arguments: --arg5 foo' - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_deprecate_options_execute(self): @@ -370,7 +370,7 @@ def test_deprecate_options_execute(self): self.cli_ctx.invoke('arg-test --arg1 foo --alt1 bar'.split()) actual = self.io.getvalue() expected = "Option '--alt1' has been deprecated and will be removed in a future release. Use '--opt1' instead." - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_deprecate_options_execute_non_deprecated(self): @@ -378,7 +378,7 @@ def test_deprecate_options_execute_non_deprecated(self): self.cli_ctx.invoke('arg-test --arg1 foo --opt1 bar'.split()) actual = self.io.getvalue() expected = "Option '--alt1' has been deprecated and will be removed in a future release. Use '--opt1' instead." - self.assertTrue(expected not in actual) + self.assertNotIn(expected, actual) @redirect_io def test_deprecate_options_execute_hidden(self): @@ -386,7 +386,7 @@ def test_deprecate_options_execute_hidden(self): self.cli_ctx.invoke('arg-test --arg1 foo --opt1 bar --alt3 bar'.split()) actual = self.io.getvalue() expected = "Option '--alt3' has been deprecated and will be removed in a future release. Use '--opt3' instead." - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_deprecate_options_execute_hidden_non_deprecated(self): @@ -394,7 +394,7 @@ def test_deprecate_options_execute_hidden_non_deprecated(self): self.cli_ctx.invoke('arg-test --arg1 foo --opt1 bar --opt3 bar'.split()) actual = self.io.getvalue() expected = "Option '--alt3' has been deprecated and will be removed in a future release. Use '--opt3' instead." - self.assertTrue(expected not in actual) + self.assertNotIn(expected, actual) @redirect_io def test_deprecate_options_execute_expired(self): @@ -403,7 +403,7 @@ def test_deprecate_options_execute_expired(self): self.cli_ctx.invoke('arg-test --arg1 foo --opt1 bar --alt5 foo'.split()) actual = self.io.getvalue() expected = 'unrecognized arguments: --alt5 foo' - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_deprecate_options_execute_expired_non_deprecated(self): @@ -418,7 +418,7 @@ def test_deprecate_options_execute_expiring(self): self.cli_ctx.invoke('arg-test --arg1 foo --opt1 bar --alt4 bar'.split()) actual = self.io.getvalue() expected = "Option '--alt4' has been deprecated and will be removed in version '1.0.0'. Use '--opt4' instead." - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_deprecate_options_execute_expiring_non_deprecated(self): @@ -426,7 +426,7 @@ def test_deprecate_options_execute_expiring_non_deprecated(self): self.cli_ctx.invoke('arg-test --arg1 foo --opt1 bar --opt4 bar'.split()) actual = self.io.getvalue() expected = "Option '--alt4' has been deprecated and will be removed in version '1.0.0'. Use '--opt4' instead." - self.assertTrue(expected not in actual) + self.assertNotIn(expected, actual) if __name__ == '__main__': diff --git a/tests/test_help.py b/tests/test_help.py index 4b96e92..3470d11 100644 --- a/tests/test_help.py +++ b/tests/test_help.py @@ -208,7 +208,7 @@ def test_choice_list_with_ints(self): self.cli_ctx.invoke('n1 -h'.split()) actual = io.getvalue() expected = 'Allowed values: 1, 2, 3' - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_help_param(self): @@ -393,7 +393,7 @@ def test_help_extra_params(self): actual = io.getvalue() expected = 'unrecognized arguments: -c extra' - self.assertTrue(expected in actual) + self.assertIn(expected, actual) @redirect_io def test_help_group_help(self): diff --git a/tests/test_parser.py b/tests/test_parser.py index 8d355ec..74c16fc 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -143,7 +143,7 @@ def __init__(self, test, substr=None): def __call__(self, message): if self.substr: - self.test.assertTrue(message.find(self.substr) >= 0) + self.test.assertGreaterEqual(message.find(self.substr), 0) self.called = True diff --git a/tests/test_prompting.py b/tests/test_prompting.py index b58a0e5..3c859ab 100644 --- a/tests/test_prompting.py +++ b/tests/test_prompting.py @@ -52,7 +52,7 @@ def test_prompt_msg_question_with_help_string(self, _): with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout: actual_result = prompt('Please enter some text: ', help_string='Anything you want!') self.assertEqual(expected_result, actual_result) - self.assertTrue('Anything you want!' in mock_stdout.getvalue()) + self.assertIn('Anything you want!', mock_stdout.getvalue()) @mock.patch('sys.stdin.isatty', return_value=True) def test_prompt_int(self, _): @@ -95,7 +95,7 @@ def test_prompt_int_question_with_help_string(self, _): with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout: actual_result = prompt_int('Please enter a number: ', help_string='Anything you want!') self.assertEqual(int(my_response), actual_result) - self.assertTrue('Anything you want!' in mock_stdout.getvalue()) + self.assertIn('Anything you want!', mock_stdout.getvalue()) @mock.patch('sys.stdin.isatty', return_value=True) def test_prompt_pass(self, _): @@ -132,7 +132,7 @@ def test_prompt_pass_question_with_help_string(self, _): with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout: actual_result = prompt_pass(help_string='Anything you want!') self.assertEqual(my_password, actual_result) - self.assertTrue('Anything you want!' in mock_stdout.getvalue()) + self.assertIn('Anything you want!', mock_stdout.getvalue()) @mock.patch('sys.stdin.isatty', return_value=True) def test_prompt_pass_confirm_valid(self, _): @@ -207,7 +207,7 @@ def test_prompt_y_n_question_with_help_string(self, _): with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout: actual_result = prompt_y_n('Do you accept?', help_string='y to accept conditions; no otherwise') self.assertTrue(actual_result) - self.assertTrue('y to accept conditions; no otherwise' in mock_stdout.getvalue()) + self.assertIn('y to accept conditions; no otherwise', mock_stdout.getvalue()) @mock.patch('sys.stdin.isatty', return_value=True) def test_prompt_y_n_default(self, _): @@ -262,7 +262,7 @@ def test_prompt_t_f_question_with_help_string(self, _): with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout: actual_result = prompt_t_f('Do you accept?', help_string='t to accept conditions; no otherwise') self.assertTrue(actual_result) - self.assertTrue('t to accept conditions; no otherwise' in mock_stdout.getvalue()) + self.assertIn('t to accept conditions; no otherwise', mock_stdout.getvalue()) @mock.patch('sys.stdin.isatty', return_value=True) def test_prompt_t_f_default(self, _): @@ -314,7 +314,8 @@ def test_prompt_choice_list_question_with_help_string(self, _): a_list, help_string='Your real favourite.') self.assertEqual(0, actual_result) - self.assertTrue('Your real favourite.' in mock_stdout.getvalue()) + self.assertIn('Your real favourite.', mock_stdout.getvalue()) + if __name__ == '__main__':