Skip to content

Commit 927bbf1

Browse files
vkmrishadtjprescott
authored andcommitted
PEP 8 Fix + String Formatting (#106)
1 parent a782443 commit 927bbf1

16 files changed

+41
-12
lines changed

examples/exapp

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ helps['abc list'] = """
2828
text: {cli_name} abc list
2929
""".format(cli_name=cli_name)
3030

31+
3132
def a_test_command_handler():
3233
return [{'a': 1, 'b': 1234}, {'a': 3, 'b': 4}]
3334

@@ -36,6 +37,7 @@ def abc_list_command_handler():
3637
import string
3738
return list(string.ascii_lowercase)
3839

40+
3941
def hello_command_handler(myarg=None, abc=None):
4042
return ['hello', 'world', myarg, abc]
4143

@@ -51,13 +53,15 @@ WELCOME_MESSAGE = r"""
5153
Welcome to the cool new CLI!
5254
"""
5355

56+
5457
class MyCLIHelp(CLIHelp):
5558

5659
def __init__(self, cli_ctx=None):
5760
super(MyCLIHelp, self).__init__(cli_ctx=cli_ctx,
5861
privacy_statement='My privacy statement.',
5962
welcome_message=WELCOME_MESSAGE)
6063

64+
6165
class MyCommandsLoader(CLICommandsLoader):
6266

6367
def load_command_table(self, args):
@@ -73,6 +77,7 @@ class MyCommandsLoader(CLICommandsLoader):
7377
ac.argument('myarg', type=int, default=100)
7478
super(MyCommandsLoader, self).load_arguments(command)
7579

80+
7681
mycli = CLI(cli_name=cli_name,
7782
config_dir=os.path.join('~', '.{}'.format(cli_name)),
7883
config_env_var_prefix=cli_name,

examples/exapp2

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ helps['abc list'] = """
2828
text: {cli_name} abc list
2929
""".format(cli_name=cli_name)
3030

31+
3132
def a_test_command_handler():
3233
return [{'a': 1, 'b': 1234}, {'a': 3, 'b': 4}]
3334

@@ -36,6 +37,7 @@ def abc_list_command_handler():
3637
import string
3738
return list(string.ascii_lowercase)
3839

40+
3941
def hello_command_handler(myarg=None, abc=None):
4042
return ['hello', 'world', myarg, abc]
4143

@@ -51,13 +53,15 @@ WELCOME_MESSAGE = r"""
5153
Welcome to the cool new CLI!
5254
"""
5355

56+
5457
class MyCLIHelp(CLIHelp):
5558

5659
def __init__(self, cli_ctx=None):
5760
super(MyCLIHelp, self).__init__(cli_ctx=cli_ctx,
5861
privacy_statement='My privacy statement.',
5962
welcome_message=WELCOME_MESSAGE)
6063

64+
6165
class MyCommandsLoader(CLICommandsLoader):
6266

6367
def load_command_table(self, args):

examples/test_exapp

+12-4
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,22 @@ from knack import CLI
1212
from knack.commands import CLICommandsLoader, CommandGroup
1313
from knack.arguments import ArgumentsContext
1414

15-
## DEFINE MY CLI
15+
# DEFINE MY CLI
16+
1617

1718
def a_test_command_handler():
1819
return [{'a': 1, 'b': 1234}, {'a': 3, 'b': 4}]
1920

21+
2022
def abc_list_command_handler():
2123
import string
2224
return list(string.ascii_lowercase)
2325

26+
2427
def hello_command_handler(myarg=None, abc=None):
2528
return ['hello', 'world', myarg, abc]
2629

30+
2731
class MyCommandsLoader(CLICommandsLoader):
2832

2933
def load_command_table(self, args):
@@ -39,19 +43,22 @@ class MyCommandsLoader(CLICommandsLoader):
3943
ac.argument('myarg', type=int, default=100)
4044
super(MyCommandsLoader, self).load_arguments(command)
4145

46+
4247
name = 'exapp4'
4348

4449
mycli = CLI(cli_name=name,
4550
config_dir=os.path.join('~', '.{}'.format(name)),
4651
config_env_var_prefix=name,
4752
commands_loader_cls=MyCommandsLoader)
4853

49-
## END OF - DEFINE MY CLI
5054

51-
## DEFINE MY TESTS
55+
# END OF - DEFINE MY CLI
56+
57+
# DEFINE MY TESTS
5258

5359
from knack.testsdk import ScenarioTest, JMESPathCheck
5460

61+
5562
class TestMyScenarios(ScenarioTest):
5663

5764
def __init__(self, method_name):
@@ -72,7 +79,8 @@ class TestMyScenarios(ScenarioTest):
7279
JMESPathCheck('length(@)', 2),
7380
])
7481

75-
## END OF - DEFINE MY TESTS
82+
# END OF - DEFINE MY TESTS
83+
7684

7785
if __name__ == '__main__':
7886
unittest.main()

knack/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, config_dir=None, config_env_var_prefix=None, config_file_name
4343
self.config_dir = os.environ.get('{}CONFIG_DIR'.format(env_var_prefix), default_config_dir)
4444
configuration_file_name = config_file_name or CLIConfig._DEFAULT_CONFIG_FILE_NAME
4545
self.config_path = os.path.join(self.config_dir, configuration_file_name)
46-
self._env_var_format = env_var_prefix + '{section}_{option}'
46+
self._env_var_format = '{}{}'.format(env_var_prefix, '{section}_{option}')
4747
self.config_parser.read(self.config_path)
4848

4949
def env_var_name(self, section, option):

knack/help.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
def _get_preview_tag():
2525
import colorama
26-
PREVIEW_TAG = colorama.Fore.CYAN + '[Preview]' + colorama.Fore.RESET
26+
PREVIEW_TAG = '{}[Preview]{}'.format(colorama.Fore.CYAN, colorama.Fore.RESET)
2727
PREVIEW_TAG_LEN = len(PREVIEW_TAG) - 2 * len(colorama.Fore.RESET)
2828
return (PREVIEW_TAG, PREVIEW_TAG_LEN)
2929

knack/log.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def get_logger(module_name=None):
2525
:rtype: logger
2626
"""
2727
if module_name:
28-
logger_name = '{}.'.format(CLI_LOGGER_NAME) + module_name
28+
logger_name = '{}.{}'.format(CLI_LOGGER_NAME, module_name)
2929
else:
3030
logger_name = CLI_LOGGER_NAME
3131
return logging.getLogger(logger_name)
@@ -41,7 +41,7 @@ def get_color_wrapper(cls, level):
4141

4242
def _color_wrapper(color_marker):
4343
def wrap_msg_with_color(msg):
44-
return color_marker + msg + colorama.Style.RESET_ALL
44+
return '{}{}{}'.format(color_marker, msg, colorama.Style.RESET_ALL)
4545
return wrap_msg_with_color
4646

4747
cls.COLOR_MAP = {

tests/test_cli_scenarios.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from knack.invocation import CommandInvoker
1616
from tests.util import MockContext
1717

18+
1819
class TestCLIScenarios(unittest.TestCase):
1920

2021
def setUp(self):
@@ -27,6 +28,7 @@ def invoke_with_command_table(self, command, command_table):
2728

2829
def test_list_value_parameter(self):
2930
handler_args = {}
31+
3032
def handler(args):
3133
handler_args.update(args)
3234

@@ -47,7 +49,6 @@ def handler(_):
4749
command.add_argument('var', '--var', '-v')
4850
cmd_table = {'test command': command}
4951

50-
5152
def _test(cmd_line):
5253
ci = CommandInvoker(cli_ctx=self.mock_ctx)
5354
self.mock_ctx.invocation = ci
@@ -121,5 +122,6 @@ def load_command_table(self, args):
121122
self.assertEqual(expected_output, mock_stdout.getvalue())
122123
self.assertEqual(0, exit_code)
123124

125+
124126
if __name__ == '__main__':
125127
unittest.main()

tests/test_command_registration.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from knack.arguments import CLIArgumentType, CLICommandArgument, ArgumentsContext
1111
from tests.util import MockContext
1212

13+
1314
def _dictContainsSubset(expected, actual):
1415
"""Checks whether actual is a superset of expected.
1516
Helper for deprecated assertDictContainsSubset"""
@@ -53,7 +54,6 @@ def sample_command_handler2(group_name, resource_name, opt_param=None, expand=No
5354
raw=False, **operation_config):
5455
pass
5556

56-
5757
def test_register_cli_argument(self):
5858
cl = CLICommandsLoader(self.mock_ctx)
5959
command_name = 'test register sample-command'
@@ -93,7 +93,6 @@ def test_register_command_custom_excluded_params(self):
9393
self.assertEqual(len(command_metadata.arguments), 4, 'We expected exactly 4 arguments')
9494
self.assertIn(command_name, cl.command_table)
9595

96-
9796
def test_register_command(self):
9897
cl = CLICommandsLoader(self.mock_ctx)
9998
command_name = 'test register sample-command'
@@ -151,6 +150,7 @@ def test_register_command_confirmation_bool(self):
151150

152151
def test_register_command_confirmation_callable(self):
153152
cl = CLICommandsLoader(self.mock_ctx)
153+
154154
def confirm_callable(_):
155155
pass
156156
command_name = 'test sample-command'
@@ -345,5 +345,6 @@ def test_cli_ctx_type_error(self):
345345
with self.assertRaises(TypeError):
346346
CLICommandsLoader(cli_ctx=object())
347347

348+
348349
if __name__ == '__main__':
349350
unittest.main()

tests/test_completion.py

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from knack.completion import CLICompletion, CaseInsensitiveChoicesCompleter, ARGCOMPLETE_ENV_NAME
1111
from tests.util import MockContext
1212

13+
1314
class TestCompletion(unittest.TestCase):
1415

1516
def setUp(self):
@@ -73,5 +74,6 @@ def test_case_insensitive_choices_list_multi_case_with_prefix(self):
7374
expected_result = ['YelLoW']
7475
self.assertListEqual(actual_result, expected_result)
7576

77+
7678
if __name__ == '__main__':
7779
unittest.main()

tests/test_help.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_short_summary_no_fullstop(self):
5858
obj = HelpObject()
5959
original_summary = 'This summary has no fullstop'
6060
obj.short_summary = original_summary
61-
self.assertEqual(obj.short_summary, original_summary + '.')
61+
self.assertEqual(obj.short_summary, '{}.'.format(original_summary))
6262

6363
def test_short_summary_fullstop(self):
6464
obj = HelpObject()

tests/test_output.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from knack.util import CommandResultItem, normalize_newlines
1414
from tests.util import MockContext
1515

16+
1617
class TestOutput(unittest.TestCase):
1718

1819
def setUp(self):

tests/test_parser.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from knack.arguments import enum_choice_list
1212
from tests.util import MockContext
1313

14+
1415
class TestParser(unittest.TestCase):
1516

1617
def setUp(self):

tests/test_prompting.py

+1
Original file line numberDiff line numberDiff line change
@@ -316,5 +316,6 @@ def test_prompt_choice_list_question_with_help_string(self, _):
316316
self.assertEqual(0, actual_result)
317317
self.assertTrue('Your real favourite.' in mock_stdout.getvalue())
318318

319+
319320
if __name__ == '__main__':
320321
unittest.main()

tests/test_query.py

+1
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,6 @@ def test_query_invalid_4(self):
7878
with self.assertRaises(ValueError):
7979
CLIQuery.jmespath_type(query)
8080

81+
8182
if __name__ == '__main__':
8283
unittest.main()

tests/test_util.py

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from knack.util import todict, to_snake_case
1111

12+
1213
class TestUtils(unittest.TestCase):
1314

1415
def test_application_todict_none(self):
@@ -86,5 +87,6 @@ def test_to_snake_case_already_snake(self):
8687
actual = to_snake_case(the_input)
8788
self.assertEqual(expected, actual)
8889

90+
8991
if __name__ == '__main__':
9092
unittest.main()

tests/util.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from knack.cli import CLI, CLICommandsLoader
99

10+
1011
class MockContext(CLI):
1112

1213
def __init__(self):

0 commit comments

Comments
 (0)