From 8919453e10987f0e5228ee6a4785b1529d666719 Mon Sep 17 00:00:00 2001 From: Anastasia Kuznetsova Date: Fri, 6 Feb 2015 20:12:35 +0400 Subject: [PATCH] Fix H904 pep8 error Change-Id: I6540c5547a68721cc40b46b96da3648be00fa766 --- mistral/cmd/launch.py | 4 +- mistral/engine/__init__.py | 8 ++-- mistral/engine/data_flow.py | 12 +++--- mistral/engine/retry.py | 4 +- mistral/engine1/commands.py | 4 +- mistral/engine1/utils.py | 8 ++-- mistral/expressions.py | 4 +- mistral/services/action_manager.py | 12 +++--- mistral/services/scheduler.py | 1 + mistral/tests/base.py | 4 +- mistral/tests/functional/base.py | 8 ++-- .../tests/unit/api/v2/test_cron_triggers.py | 4 +- .../tests/unit/engine/default/test_engine.py | 10 ++--- .../unit/engine/default/test_executor.py | 14 +++---- mistral/tests/unit/engine/test_data_flow.py | 40 +++++++++---------- mistral/utils/__init__.py | 12 +++--- mistral/workbook/v2/workbook.py | 4 +- mistral/workflow/base.py | 5 ++- mistral/workflow/data_flow.py | 4 +- mistral/workflow/reverse_workflow.py | 4 +- mistral/workflow/utils.py | 4 +- tox.ini | 2 +- 22 files changed, 86 insertions(+), 86 deletions(-) diff --git a/mistral/cmd/launch.py b/mistral/cmd/launch.py index 0dd8a6d9..cb3cd66d 100755 --- a/mistral/cmd/launch.py +++ b/mistral/cmd/launch.py @@ -157,8 +157,8 @@ Mistral Workflow Service, version 0.1, 2014 def print_server_info(): print(MISTRAL_TITLE) - comp_str = "[%s]" % ','.join(LAUNCH_OPTIONS) \ - if cfg.CONF.server == ['all'] else cfg.CONF.server + comp_str = ("[%s]" % ','.join(LAUNCH_OPTIONS) + if cfg.CONF.server == ['all'] else cfg.CONF.server) print('Launching server components %s...' % comp_str) diff --git a/mistral/engine/__init__.py b/mistral/engine/__init__.py index 22998602..c39a1920 100644 --- a/mistral/engine/__init__.py +++ b/mistral/engine/__init__.py @@ -188,15 +188,15 @@ class Engine(object): WF_TRACE.info("Task '%s' [%s -> %s, result = %s]" % (task.name, task.state, state, result)) - action_name = spec_parser.get_task_spec(task.task_spec)\ - .get_full_action_name() + action_name = spec_parser.get_task_spec( + task.task_spec).get_full_action_name() if not a_m.get_action_class(action_name): action = a_m.resolve_adhoc_action_name(workbook, action_name) if not action: - msg = 'Unknown action [workbook=%s, action=%s]' % \ - (workbook, action_name) + msg = 'Unknown action [workbook=%s, action=%s]' % ( + workbook, action_name) raise exc.ActionException(msg) result = a_m.convert_adhoc_action_result(workbook, diff --git a/mistral/engine/data_flow.py b/mistral/engine/data_flow.py index 46f64918..c6a69a66 100644 --- a/mistral/engine/data_flow.py +++ b/mistral/engine/data_flow.py @@ -89,8 +89,8 @@ def prepare_tasks(tasks_to_start, context, workbook, tasks): # Get action name. Unwrap ad-hoc and reevaluate params if # necessary. - action_name = spec_parser.get_task_spec(task.task_spec)\ - .get_full_action_name() + action_name = spec_parser.get_task_spec( + task.task_spec).get_full_action_name() openstack_ctx = context.get('openstack') @@ -103,8 +103,8 @@ def prepare_tasks(tasks_to_start, context, workbook, tasks): action = a_m.resolve_adhoc_action_name(workbook, action_name) if not action: - msg = 'Unknown action [workbook=%s, action=%s]' % \ - (workbook, action_name) + msg = ('Unknown action [workbook=%s, action=%s]' % + (workbook, action_name)) raise exc.ActionException(msg) action_params = a_m.convert_adhoc_action_params(workbook, @@ -113,8 +113,8 @@ def prepare_tasks(tasks_to_start, context, workbook, tasks): action_name = action if _has_action_context_param(a_m.get_action_class(action_name)): - action_params[_ACTION_CTX_PARAM] = \ - _get_action_context(task, openstack_ctx) + action_params[_ACTION_CTX_PARAM] = _get_action_context( + task, openstack_ctx) results.append((task.id, action_name, action_params)) diff --git a/mistral/engine/retry.py b/mistral/engine/retry.py index edb5cf82..17162cd8 100644 --- a/mistral/engine/retry.py +++ b/mistral/engine/retry.py @@ -61,8 +61,8 @@ def get_task_runtime(task_spec, state=states.IDLE, outbound_context=None, retry_count, break_on, delay = task_spec.get_retry_parameters() retries_remain = retry_no + 1 < retry_count - break_early = expressions.evaluate(break_on, outbound_context) if \ - break_on and outbound_context else False + break_early = (expressions.evaluate(break_on, outbound_context) + if break_on and outbound_context else False) if retries_remain and not break_early: state = states.DELAYED if delay > 0 else states.IDLE diff --git a/mistral/engine1/commands.py b/mistral/engine1/commands.py index 6bab675c..e61f0661 100644 --- a/mistral/engine1/commands.py +++ b/mistral/engine1/commands.py @@ -337,5 +337,5 @@ RESERVED_COMMANDS = { def get_reserved_command(cmd_name): - return RESERVED_COMMANDS[cmd_name]() if cmd_name in RESERVED_COMMANDS \ - else None + return (RESERVED_COMMANDS[cmd_name]() + if cmd_name in RESERVED_COMMANDS else None) diff --git a/mistral/engine1/utils.py b/mistral/engine1/utils.py index 0933adb3..725433b5 100644 --- a/mistral/engine1/utils.py +++ b/mistral/engine1/utils.py @@ -109,11 +109,11 @@ def transform_result(exec_db, task_db, raw_result): if raw_result.is_error(): return raw_result - action_spec_name =\ - spec_parser.get_task_spec(task_db.spec).get_action_name() + action_spec_name = spec_parser.get_task_spec( + task_db.spec).get_action_name() - wf_spec_name = \ - spec_parser.get_workflow_spec(exec_db.wf_spec).get_name() + wf_spec_name = spec_parser.get_workflow_spec( + exec_db.wf_spec).get_name() if action_spec_name: return transform_action_result( diff --git a/mistral/expressions.py b/mistral/expressions.py index 376ffa85..1259a9b8 100644 --- a/mistral/expressions.py +++ b/mistral/expressions.py @@ -127,8 +127,8 @@ _EVALUATOR = InlineYAQLEvaluator def evaluate(expression, context): # Check if the passed value is expression so we don't need to do this # every time on a caller side. - if not isinstance(expression, six.string_types) or \ - not _EVALUATOR.is_expression(expression): + if (not isinstance(expression, six.string_types) or + not _EVALUATOR.is_expression(expression)): return expression return _EVALUATOR.evaluate(expression, context) diff --git a/mistral/services/action_manager.py b/mistral/services/action_manager.py index 710a9712..6794d90c 100644 --- a/mistral/services/action_manager.py +++ b/mistral/services/action_manager.py @@ -174,17 +174,17 @@ def resolve_adhoc_action_name(workbook, action_name): action_spec = workbook.get_action(action_name) if not action_spec: - msg = 'Ad-hoc action class is not registered ' \ - '[workbook=%s, action=%s, action_spec=%s]' % \ - (workbook, action_name, action_spec) + msg = ('Ad-hoc action class is not registered ' + '[workbook=%s, action=%s, action_spec=%s]' % + (workbook, action_name, action_spec)) raise exc.ActionException(msg) base_cls = get_action_class(action_spec.clazz) if not base_cls: - msg = 'Ad-hoc action base class is not registered ' \ - '[workbook=%s, action=%s, base_class=%s]' % \ - (workbook, action_name, base_cls) + msg = ('Ad-hoc action base class is not registered ' + '[workbook=%s, action=%s, base_class=%s]' % + (workbook, action_name, base_cls)) raise exc.ActionException(msg) return action_spec.clazz diff --git a/mistral/services/scheduler.py b/mistral/services/scheduler.py index d2353b94..5efbe65a 100644 --- a/mistral/services/scheduler.py +++ b/mistral/services/scheduler.py @@ -29,6 +29,7 @@ LOG = log.getLogger(__name__) def schedule_call(factory_method_path, target_method_name, run_after, serializers=None, **method_args): + """Add this call specification to DB, and then after run_after seconds service CallScheduler invokes the target_method. diff --git a/mistral/tests/base.py b/mistral/tests/base.py index 055f397e..c3645f2f 100644 --- a/mistral/tests/base.py +++ b/mistral/tests/base.py @@ -93,8 +93,8 @@ class BaseTest(base.BaseTestCase): def _assert_multiple_items(self, items, count, **props): def _matches(item, **props): for prop_name, prop_val in props.iteritems(): - v = item[prop_name] if isinstance(item, dict) \ - else getattr(item, prop_name) + v = item[prop_name] if isinstance( + item, dict) else getattr(item, prop_name) if v != prop_val: return False diff --git a/mistral/tests/functional/base.py b/mistral/tests/functional/base.py index 4cf5bdcb..360d5ac1 100644 --- a/mistral/tests/functional/base.py +++ b/mistral/tests/functional/base.py @@ -180,15 +180,15 @@ class MistralClientV1(MistralClientBase): while ex_body['state'] != 'SUCCESS': if time.time() - start_time > timeout: - msg = "Execution exceeds timeout {0} to change state " \ - "to SUCCESS. Execution: {1}".format(timeout, ex_body) + msg = ("Execution exceeds timeout {0} to change state " + "to SUCCESS. Execution: {1}".format(timeout, ex_body)) raise exceptions.TimeoutException(msg) _, ex_body = self.get_object('executions', ex_body['id']) if ex_body['state'] not in expected_states: - msg = "Execution state %s is not in expected " \ - "states: %s" % (ex_body['state'], expected_states) + msg = ("Execution state %s is not in expected " + "states: %s" % (ex_body['state'], expected_states)) raise exceptions.TempestException(msg) time.sleep(2) diff --git a/mistral/tests/unit/api/v2/test_cron_triggers.py b/mistral/tests/unit/api/v2/test_cron_triggers.py index e6940cc9..e13d1dbc 100644 --- a/mistral/tests/unit/api/v2/test_cron_triggers.py +++ b/mistral/tests/unit/api/v2/test_cron_triggers.py @@ -36,8 +36,8 @@ TRIGGER = { } trigger_values = copy.copy(TRIGGER) -trigger_values['workflow_input'] = \ - json.loads(trigger_values['workflow_input']) +trigger_values['workflow_input'] = json.loads( + trigger_values['workflow_input']) TRIGGER_DB = models.CronTrigger() TRIGGER_DB.update(trigger_values) diff --git a/mistral/tests/unit/engine/default/test_engine.py b/mistral/tests/unit/engine/default/test_engine.py index eb87b138..94101430 100644 --- a/mistral/tests/unit/engine/default/test_engine.py +++ b/mistral/tests/unit/engine/default/test_engine.py @@ -74,11 +74,11 @@ class TestEngine(base.EngineTestCase): task = db_api.tasks_get(workbook_name=WB_NAME, execution_id=execution['id'])[0] - executor.ExecutorClient.handle_task \ - .assert_called_once_with(auth_context.ctx(), - params={'output': 'Stormin Stanley'}, - task_id=task['id'], - action_name='std.echo') + executor.ExecutorClient.handle_task.assert_called_once_with( + auth_context.ctx(), + params={'output': 'Stormin Stanley'}, + task_id=task['id'], + action_name='std.echo') self.engine.convey_task_result(task['id'], states.SUCCESS, diff --git a/mistral/tests/unit/engine/default/test_executor.py b/mistral/tests/unit/engine/default/test_executor.py index d2089dcb..df2bc913 100644 --- a/mistral/tests/unit/engine/default/test_executor.py +++ b/mistral/tests/unit/engine/default/test_executor.py @@ -142,10 +142,10 @@ class TestExecutor(base.DbTestCase): action_name=action_name, params=params) - engine.EngineClient.convey_task_result\ - .assert_called_once_with(task_id, - states.SUCCESS, - action.return_value) + engine.EngineClient.convey_task_result.assert_called_once_with( + task_id, + states.SUCCESS, + action.return_value) @mock.patch.object(engine.EngineClient, 'convey_task_result', mock.MagicMock()) @@ -187,7 +187,5 @@ class TestExecutor(base.DbTestCase): params=params) self.assertTrue(log.called, "Exception must be logged") - engine.EngineClient.convey_task_result\ - .assert_called_once_with(task_id, - states.ERROR, - None) + engine.EngineClient.convey_task_result.assert_called_once_with( + task_id, states.ERROR, None) diff --git a/mistral/tests/unit/engine/test_data_flow.py b/mistral/tests/unit/engine/test_data_flow.py index bffbdeb2..289071aa 100644 --- a/mistral/tests/unit/engine/test_data_flow.py +++ b/mistral/tests/unit/engine/test_data_flow.py @@ -107,10 +107,10 @@ class DataFlowTest(base.EngineTestCase): self.assertEqual(2, len(tasks)) - build_full_name_task = \ - self._assert_single_item(tasks, name='build_full_name') - build_greeting_task = \ - self._assert_single_item(tasks, name='build_greeting') + build_full_name_task = self._assert_single_item( + tasks, name='build_full_name') + build_greeting_task = self._assert_single_item( + tasks, name='build_greeting') # Check the first task. self.assertEqual(states.SUCCESS, build_full_name_task['state']) @@ -175,12 +175,12 @@ class DataFlowTest(base.EngineTestCase): self.assertEqual(3, len(tasks)) - build_full_name_task = \ - self._assert_single_item(tasks, name='build_full_name') - build_greeting_task = \ - self._assert_single_item(tasks, name='build_greeting') - send_greeting_task = \ - self._assert_single_item(tasks, name='send_greeting') + build_full_name_task = self._assert_single_item( + tasks, name='build_full_name') + build_greeting_task = self._assert_single_item( + tasks, name='build_greeting') + send_greeting_task = self._assert_single_item( + tasks, name='send_greeting') # Check the first task. self.assertEqual(states.SUCCESS, build_full_name_task['state']) @@ -312,10 +312,10 @@ class DataFlowTest(base.EngineTestCase): self.assertEqual(2, len(tasks)) - build_full_name_task = \ - self._assert_single_item(tasks, name='build_full_name') - build_greeting_task = \ - self._assert_single_item(tasks, name='build_greeting') + build_full_name_task = self._assert_single_item( + tasks, name='build_full_name') + build_greeting_task = self._assert_single_item( + tasks, name='build_greeting') # Check the first task. self.assertEqual(states.SUCCESS, build_full_name_task['state']) @@ -385,12 +385,12 @@ class DataFlowTest(base.EngineTestCase): self.assertEqual(3, len(tasks)) - build_full_name_task = \ - self._assert_single_item(tasks, name='build_full_name') - build_greeting_task = \ - self._assert_single_item(tasks, name='build_greeting') - send_greeting_task = \ - self._assert_single_item(tasks, name='send_greeting') + build_full_name_task = self._assert_single_item( + tasks, name='build_full_name') + build_greeting_task = self._assert_single_item( + tasks, name='build_greeting') + send_greeting_task = self._assert_single_item( + tasks, name='send_greeting') # Check the first task. self.assertEqual(states.SUCCESS, build_full_name_task['state']) diff --git a/mistral/utils/__init__.py b/mistral/utils/__init__.py index 635ba9d9..ccef299e 100644 --- a/mistral/utils/__init__.py +++ b/mistral/utils/__init__.py @@ -70,8 +70,8 @@ def set_thread_local(var_name, val): if val: gl_storage = _get_greenlet_local_storage() if not gl_storage: - gl_storage = \ - _th_loc_storage.greenlet_locals[corolocal.get_ident()] = {} + gl_storage = _th_loc_storage.greenlet_locals[ + corolocal.get_ident()] = {} gl_storage[var_name] = val @@ -83,11 +83,11 @@ def log_exec(logger, level=logging.DEBUG): def _decorator(func): def _logged(*args, **kw): - params_repr = "[args=%s, kw=%s]" % (str(args), str(kw)) \ - if len(args) > 0 or len(kw) > 0 else "" + params_repr = ("[args=%s, kw=%s]" % (str(args), str(kw)) + if len(args) > 0 or len(kw) > 0 else "") - func_repr = "Called method [name=%s, doc='%s', params=%s]" % \ - (func.__name__, func.__doc__, params_repr) + func_repr = ("Called method [name=%s, doc='%s', params=%s]" % + (func.__name__, func.__doc__, params_repr)) logger.log(level, func_repr) diff --git a/mistral/workbook/v2/workbook.py b/mistral/workbook/v2/workbook.py index b0b8d478..3c0b86fe 100644 --- a/mistral/workbook/v2/workbook.py +++ b/mistral/workbook/v2/workbook.py @@ -46,8 +46,8 @@ class WorkbookSpec(base.BaseSpec): self._description = data.get('description') self._tags = data.get('tags', []) self._actions = self._spec_property('actions', act.ActionSpecList) - self._workflows = \ - self._spec_property('workflows', wf.WorkflowSpecList) + self._workflows = self._spec_property( + 'workflows', wf.WorkflowSpecList) self._triggers = self._spec_property('triggers', tr.TriggerSpecList) def get_name(self): diff --git a/mistral/workflow/base.py b/mistral/workflow/base.py index 4160adcc..4585de8a 100644 --- a/mistral/workflow/base.py +++ b/mistral/workflow/base.py @@ -301,8 +301,9 @@ class WorkflowHandler(object): self.exec_db.state = state self.exec_db.state_info = state_info else: - msg = "Can't change workflow state [execution=%s," \ - " state=%s -> %s]" % (self.exec_db, cur_state, state) + msg = ("Can't change workflow state " + "[execution=%s, state=%s -> %s]" % + (self.exec_db, cur_state, state)) raise exc.WorkflowException(msg) diff --git a/mistral/workflow/data_flow.py b/mistral/workflow/data_flow.py index d30454cd..c406cc0c 100644 --- a/mistral/workflow/data_flow.py +++ b/mistral/workflow/data_flow.py @@ -132,8 +132,8 @@ def evaluate_task_outbound_context(task_db): :return: Outbound task Data Flow context. """ - in_context = copy.deepcopy(dict(task_db.in_context)) \ - if task_db.in_context is not None else {} + in_context = (copy.deepcopy(dict(task_db.in_context)) + if task_db.in_context is not None else {}) out_ctx = utils.merge_dicts(in_context, task_db.output) diff --git a/mistral/workflow/reverse_workflow.py b/mistral/workflow/reverse_workflow.py index a0fc779e..c6d6f2b6 100644 --- a/mistral/workflow/reverse_workflow.py +++ b/mistral/workflow/reverse_workflow.py @@ -42,8 +42,8 @@ class ReverseWorkflowHandler(base.WorkflowHandler): task_spec = self.wf_spec.get_tasks().get(task_name) if not task_spec: - msg = 'Invalid task name [wf_spec=%s, task_name=%s]' % \ - (self.wf_spec, task_name) + msg = 'Invalid task name [wf_spec=%s, task_name=%s]' % ( + self.wf_spec, task_name) raise exc.WorkflowException(msg) task_specs = self._find_tasks_without_dependencies(task_spec) diff --git a/mistral/workflow/utils.py b/mistral/workflow/utils.py index f1b5e50b..5609e06b 100644 --- a/mistral/workflow/utils.py +++ b/mistral/workflow/utils.py @@ -24,8 +24,8 @@ class TaskResult(object): self.error = error def __repr__(self): - return 'TaskResult [data=%s, error=%s]' % \ - (repr(self.data), repr(self.error)) + return 'TaskResult [data=%s, error=%s]' % ( + repr(self.data), repr(self.error)) def is_error(self): return self.error is not None diff --git a/tox.ini b/tox.ini index 17bca872..b9352bc5 100644 --- a/tox.ini +++ b/tox.ini @@ -41,6 +41,6 @@ commands = bash tools/lintstack.sh [flake8] show-source = true -ignore = H803,H305,H405,H904 +ignore = H803,H305,H405 builtins = _ exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools,scripts