Skip to content

Commit c0a6dff

Browse files
committed
Merge pull request #37 from vrutkovs/code-smells
Fix logging (PEP-282) code smells
2 parents ca62c54 + 723d33b commit c0a6dff

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

ctf_cli/application.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def update(self):
168168
common_steps_dir = os.path.join(self._execution_dir_path, "tests", "steps", "common_steps")
169169
common_features_dir = os.path.join(self._execution_dir_path, "tests", "features", "common-features")
170170
for directory in [common_steps_dir, common_features_dir]:
171-
logger.info("Updating %s" % directory)
171+
logger.info("Updating %s", directory)
172172
check_call("git fetch origin", shell=True, cwd=directory)
173173
check_call("git checkout origin/master", shell=True, cwd=directory)
174174

ctf_cli/behave.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from ctf_cli.common_environment import common_environment_py_header
3030
from ctf_cli import __path__
3131

32+
3233
class BehaveTestsConfig(object):
3334
"""
3435
Configuration parser for tests configuration
@@ -219,8 +220,8 @@ def _add_project_specific_steps(self):
219220
"""
220221
project_steps_dir = os.path.join(self._project_tests_dir, 'steps')
221222
if os.path.exists(project_steps_dir):
222-
logger.info("Using project specific Steps from '%s'", project_steps_dir.replace(self._execution_dir
223-
+ os.sep, ''))
223+
logger.info("Using project specific Steps from '%s'",
224+
project_steps_dir.replace(self._execution_dir + os.sep, ''))
224225
shutil.copytree(project_steps_dir, os.path.join(self._steps_dir,
225226
'{0}_steps'.format(os.path.basename(
226227
self._execution_dir).replace('-', '_'))))
@@ -237,8 +238,8 @@ def _add_project_specific_features(self):
237238
"""
238239
project_features_dir = os.path.join(self._project_tests_dir, 'features')
239240
if os.path.exists(project_features_dir):
240-
logger.info("Using project specific Features from '%s'", project_features_dir.replace(self._execution_dir
241-
+ os.sep, ''))
241+
logger.info("Using project specific Features from '%s'",
242+
project_features_dir.replace(self._execution_dir + os.sep, ''))
242243
shutil.copytree(project_features_dir, os.path.join(self._features_dir,
243244
'{0}_features'.format(os.path.basename(
244245
self._execution_dir).replace('-', '_'))))
@@ -324,7 +325,7 @@ def get_import_statements(path):
324325
"""
325326
imports = []
326327

327-
for (dirpath, dirnames, filenames) in os.walk(path, followlinks=True):
328+
for (dirpath, _, filenames) in os.walk(path, followlinks=True):
328329
module = dirpath.replace(path, '').strip(os.sep).replace(os.sep, '.')
329330
# generate imports for the *.py files in the current dir
330331

@@ -356,7 +357,7 @@ def check_and_add_init_py(path, skip_root=False):
356357
"""
357358
files = []
358359

359-
for (dirpath, dirnames, filenames) in os.walk(path, followlinks=True):
360+
for (dirpath, _, filenames) in os.walk(path, followlinks=True):
360361
if skip_root and dirpath == path:
361362
continue
362363

ctf_cli/common_environment_content.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def open_file(path):
4343
inventory=inventory,
4444
module_args='src={0} dest={1}'.format(
4545
path, context.temp_dir)).run()
46-
for host, value in ret['contacted'].iteritems():
46+
for _, value in ret['contacted'].iteritems():
4747
try:
4848
ret_file = open(value['dest'])
4949
return ret_file
@@ -55,7 +55,7 @@ def open_file(path):
5555
def run(command):
5656
if '{{' in command:
5757
command = command.replace("{{", "{{ '{{").replace("}}", "}}' }}")
58-
logging.info("Running '%s'" % command)
58+
logging.info("Running '%s'", command)
5959
context.result = ansible.runner.Runner(
6060
module_name="shell",
6161
inventory=inventory,
@@ -72,9 +72,9 @@ def run(command):
7272
print("stderr: {0}".format(values['stderr']))
7373
print("cmd: {0}".format(values['cmd']))
7474
assert False
75-
logging.info('stdout:\\n%s' % values['stdout'])
75+
logging.info('stdout:\\n%s', values['stdout'])
7676
if values['stderr']:
77-
logging.info('stderr\\n:%s' % values['stderr'])
77+
logging.info('stderr\\n:%s', values['stderr'])
7878
return values['stdout']
7979
context.run = run
8080

@@ -109,7 +109,7 @@ def copy_dockerfile():
109109
oct(stat.S_IMODE(os.stat(glob_path).st_mode)))
110110
).run()
111111
except Exception as e:
112-
logging.warning("copy_dockerfile:%s" % e)
112+
logging.warning("copy_dockerfile:%s", e)
113113

114114
copy_dockerfile()
115115

@@ -141,7 +141,7 @@ def after_scenario(context, scenario):
141141
try:
142142
cid = context.run('cat %s' % context.cid_file)
143143
except AssertionError as e:
144-
logging.info("before_scenario: {0}".format(e))
144+
logging.info("before_scenario: %s", e)
145145
return
146146
if cid:
147147
context.run("docker logs %s" % cid)

0 commit comments

Comments
 (0)