diff --git a/getgauge/lsp_server.py b/getgauge/lsp_server.py index c900d43..20dcab1 100644 --- a/getgauge/lsp_server.py +++ b/getgauge/lsp_server.py @@ -1,15 +1,16 @@ import threading - from getgauge import processor, validator, refactor from getgauge.messages import lsp_pb2_grpc from getgauge.messages.lsp_pb2 import Empty -from getgauge.messages.messages_pb2 import Message, ImplementationFileGlobPatternResponse, StepNamesResponse, \ +from getgauge.messages.messages_pb2 import Message, \ + ImplementationFileGlobPatternResponse, StepNamesResponse, \ ImplementationFileListResponse from getgauge.registry import registry from getgauge.util import get_impl_files, get_step_impl_dir class LspServerHandler(lsp_pb2_grpc.lspServiceServicer): + def __init__(self, server): self.server = server self.kill_event = threading.Event() @@ -37,7 +38,8 @@ def GetImplementationFiles(self, request, context): def ImplementStub(self, request, context): res = Message() - processor.stub_impl_response(request.codes, request.implementationFilePath, res) + processor.stub_impl_response( + request.codes, request.implementationFilePath, res) return res.fileDiff def ValidateStep(self, request, context): diff --git a/getgauge/parser_parso.py b/getgauge/parser_parso.py index 76b9855..00775ce 100644 --- a/getgauge/parser_parso.py +++ b/getgauge/parser_parso.py @@ -10,25 +10,30 @@ class ParsoPythonFile(object): + @staticmethod def parse(file_path, content=None): """ - Create a PythonFile object with specified file_path and content. If content is None - then, it is loaded from the file_path method. Otherwise, file_path is only used for - reporting errors. + Create a PythonFile object with specified file_path and content. + If content is None then, it is loaded from the file_path method. + Otherwise, file_path is only used for reporting errors. """ try: - # Parso reads files in binary mode and converts to unicode using python_bytes_to_unicode() - # function. As a result, we no longer have information about original file encoding and - # output of module.get_content() can not be converted back to bytes. For now we can make a - # compromise by reading the file ourselves and passing content to parse() function. + # Parso reads files in binary mode and converts to unicode + # using python_bytes_to_unicode() function. As a result, + # we no longer have information about original file encoding and + # output of module.get_content() can't be converted back to bytes + # For now we can make a compromise by reading the file ourselves + # and passing content to parse() function. if content is None: with open(file_path) as f: content = f.read() - py_tree = _parser.parse(content, path=file_path, error_recovery=False) + py_tree = _parser.parse( + content, path=file_path, error_recovery=False) return ParsoPythonFile(file_path, py_tree) except parso.parser.ParserSyntaxError as ex: - logging.error("Failed to parse %s:%d '%s'", file_path, ex.error_leaf.line, ex.error_leaf.get_code()) + logging.error("Failed to parse %s:%d '%s'", file_path, + ex.error_leaf.line, ex.error_leaf.get_code()) def __init__(self, file_path, py_tree): self.file_path = file_path @@ -51,7 +56,10 @@ def _iter_step_func_decorators(self): break def _step_decorator_args(self, decorator): - """Get the arguments passed to step decorators converted to python objects""" + """ + Get the arguments passed to step decorators + converted to python objects. + """ args = decorator.children[3:-2] step = None if len(args) == 1: @@ -68,7 +76,7 @@ def _step_decorator_args(self, decorator): self.file_path, decorator.start_pos[0]) def iter_steps(self): - """Iterate over steps in the parsed file""" + """Iterate over steps in the parsed file.""" for func, decorator in self._iter_step_func_decorators(): step = self._step_decorator_args(decorator) if step: @@ -76,7 +84,7 @@ def iter_steps(self): yield step, func.name.value, span def _find_step_node(self, step_text): - """Find the ast node which contains the text""" + """Find the ast node which contains the text.""" for func, decorator in self._iter_step_func_decorators(): step = self._step_decorator_args(decorator) arg_node = decorator.children[3] @@ -97,7 +105,8 @@ def _create_param_node(self, parent, name, prefix, is_last): start_pos = parent[-1].end_pos[0], parent[-1].end_pos[1] + len(prefix) children = [parso.python.tree.Name(name, start_pos, prefix)] if not is_last: - children.append(parso.python.tree.Operator(',', children[-1].end_pos)) + children.append(parso.python.tree.Operator( + ',', children[-1].end_pos)) return parso.python.tree.Param(children, parent) def _move_param_nodes(self, param_nodes, move_param_from_idx): @@ -109,16 +118,19 @@ def _move_param_nodes(self, param_nodes, move_param_from_idx): return param_nodes # Get the prefix from second parameter to use with new parameters prefix = param_nodes[2].name.prefix if num_params > 1 else ' ' - new_param_nodes = [parso.python.tree.Operator('(', param_nodes[0].start_pos)] + new_param_nodes = [parso.python.tree.Operator( + '(', param_nodes[0].start_pos)] for i, move_from in enumerate(move_param_from_idx): param = self._create_param_node( new_param_nodes, - self._get_param_name(param_nodes, i) if move_from < 0 else param_nodes[move_from + 1].name.value, + self._get_param_name( + param_nodes, i) if move_from < 0 else param_nodes[move_from + 1].name.value, '' if i == 0 else prefix, i >= len(move_param_from_idx) - 1 ) new_param_nodes.append(param) - new_param_nodes.append(parso.python.tree.Operator(')', new_param_nodes[-1].end_pos)) + new_param_nodes.append(parso.python.tree.Operator( + ')', new_param_nodes[-1].end_pos)) # Change the parent to actual function for node in new_param_nodes: node.parent = param_nodes[0].parent @@ -126,9 +138,9 @@ def _move_param_nodes(self, param_nodes, move_param_from_idx): def refactor_step(self, old_text, new_text, move_param_from_idx): """ - Find the step with old_text and change it to new_text. The step function - parameters are also changed according to move_param_from_idx. Each entry in - this list should specify parameter position from old + Find the step with old_text and change it to new_text.The step function + parameters are also changed according to move_param_from_idx. + Each entry in this list should specify parameter position from old. """ diffs = [] step, func = self._find_step_node(old_text) @@ -137,7 +149,8 @@ def refactor_step(self, old_text, new_text, move_param_from_idx): step_diff = self._refactor_step_text(step, old_text, new_text) diffs.append(step_diff) params_list_node = func.children[2] - moved_params = self._move_param_nodes(params_list_node.children, move_param_from_idx) + moved_params = self._move_param_nodes( + params_list_node.children, move_param_from_idx) if params_list_node.children is not moved_params: # Record original parameter list span excluding braces params_span = self._span_from_pos( @@ -150,7 +163,7 @@ def refactor_step(self, old_text, new_text, move_param_from_idx): return diffs def get_code(self): - """Returns current content of the tree.""" + """Return current content of the tree.""" return self.py_tree.get_code() def _get_param_name(self, param_nodes, i): diff --git a/getgauge/parser_redbaron.py b/getgauge/parser_redbaron.py index 0836081..9d9f8fb 100644 --- a/getgauge/parser_redbaron.py +++ b/getgauge/parser_redbaron.py @@ -4,12 +4,13 @@ class RedbaronPythonFile(object): + @staticmethod def parse(file_path, content=None): """ - Create a PythonFile object with specified file_path and content. If content is None - then, it is loaded from the file_path method. Otherwise, file_path is only used for - reporting errors. + Create a PythonFile object with specified file_path and content. + If content is None then, it is loaded from the file_path method. + Otherwise, file_path is only used for reporting errors. """ try: if content is None: @@ -51,7 +52,7 @@ def calculate_span(): return calculate_span if lazy else calculate_span() def _iter_step_func_decorators(self): - """Find top level functions with step decorator in parsed file""" + """Find top level functions with step decorator in parsed file.""" for node in self.py_tree: if node.type == 'def': for decorator in node.decorators: @@ -60,7 +61,9 @@ def _iter_step_func_decorators(self): break def _step_decorator_args(self, decorator): - """Get the arguments passed to step decorators converted to python objects""" + """ + Get arguments passed to step decorators converted to python objects. + """ args = decorator.call.value step = None if len(args) == 1: @@ -70,21 +73,22 @@ def _step_decorator_args(self, decorator): pass if isinstance(step, six.string_types + (list,)): return step - logging.error("Decorator step accepts either a string or a list of strings - %s", + logging.error("Decorator step accepts either a string or a list of \ + strings - %s", self.file_path) else: logging.error("Decorator step accepts only one argument - %s", self.file_path) def iter_steps(self): - """Iterate over steps in the parsed file""" + """Iterate over steps in the parsed file.""" for func, decorator in self._iter_step_func_decorators(): step = self._step_decorator_args(decorator) if step: yield step, func.name, self._span_for_node(func, True) def _find_step_node(self, step_text): - """Find the ast node which contains the text""" + """Find the ast node which contains the text.""" for func, decorator in self._iter_step_func_decorators(): step = self._step_decorator_args(decorator) arg_node = decorator.call.value[0].value @@ -121,9 +125,10 @@ def _move_params(self, params, move_param_from_idx): def refactor_step(self, old_text, new_text, move_param_from_idx): """ - Find the step with old_text and change it to new_text. The step function - parameters are also changed according to move_param_from_idx. Each entry in - this list should specify parameter position from old + Find the step with old_text and change it to new_text. + The step function parameters are also changed according + to move_param_from_idx. Each entry in this list should + specify parameter position from old """ diffs = [] step, func = self._find_step_node(old_text) @@ -139,5 +144,5 @@ def refactor_step(self, old_text, new_text, move_param_from_idx): return diffs def get_code(self): - """Returns current content of the tree.""" + """Return current content of the tree.""" return self.py_tree.dumps() diff --git a/getgauge/processor.py b/getgauge/processor.py index 67430c2..154a7e0 100644 --- a/getgauge/processor.py +++ b/getgauge/processor.py @@ -66,9 +66,11 @@ def _send_all_step_names(_request, response, _socket): def _execute_step(request, response, _socket): params = [] for p in request.executeStepRequest.parameters: - params.append(Table(p.table) if p.parameterType in [Parameter.Table, Parameter.Special_Table] else p.value) + params.append(Table(p.table) if p.parameterType in [ + Parameter.Table, Parameter.Special_Table] else p.value) set_response_values(request, response) - impl = registry.get_info_for(request.executeStepRequest.parsedStepText).impl + impl = registry.get_info_for( + request.executeStepRequest.parsedStepText).impl execute_method(params, impl, response, registry.is_continue_on_failure) @@ -82,70 +84,101 @@ def _execute_before_suite_hook(request, response, _socket, clear=True): registry.clear() load_impls(get_step_impl_dir()) if environ.get('DEBUGGING'): - ptvsd.enable_attach('', address=('127.0.0.1', int(environ.get('DEBUG_PORT')))) + ptvsd.enable_attach('', address=( + '127.0.0.1', int(environ.get('DEBUG_PORT')))) logging.info(ATTACH_DEBUGGER_EVENT) t = Timer(int(environ.get("debugger_wait_time", 30)), handle_detached) t.start() ptvsd.wait_for_attach() t.cancel() - execution_info = create_execution_context_from(request.executionStartingRequest.currentExecutionInfo) + execution_info = create_execution_context_from( + request.executionStartingRequest.currentExecutionInfo) run_hook(request, response, registry.before_suite(), execution_info) - response.executionStatusResponse.executionResult.message.extend(MessagesStore.pending_messages()) - response.executionStatusResponse.executionResult.screenshots.extend(ScreenshotsStore.pending_screenshots()) + response.executionStatusResponse.executionResult.message.extend( + MessagesStore.pending_messages()) + response.executionStatusResponse.executionResult.screenshots.extend( + ScreenshotsStore.pending_screenshots()) def _execute_after_suite_hook(request, response, _socket): - execution_info = create_execution_context_from(request.executionEndingRequest.currentExecutionInfo) + execution_info = create_execution_context_from( + request.executionEndingRequest.currentExecutionInfo) run_hook(request, response, registry.after_suite(), execution_info) - response.executionStatusResponse.executionResult.message.extend(MessagesStore.pending_messages()) - response.executionStatusResponse.executionResult.screenshots.extend(ScreenshotsStore.pending_screenshots()) + response.executionStatusResponse.executionResult.message.extend( + MessagesStore.pending_messages()) + response.executionStatusResponse.executionResult.screenshots.extend( + ScreenshotsStore.pending_screenshots()) def _execute_before_spec_hook(request, response, _socket): - execution_info = create_execution_context_from(request.specExecutionStartingRequest.currentExecutionInfo) - run_hook(request, response, registry.before_spec(execution_info.specification.tags), execution_info) - response.executionStatusResponse.executionResult.message.extend(MessagesStore.pending_messages()) - response.executionStatusResponse.executionResult.screenshots.extend(ScreenshotsStore.pending_screenshots()) + execution_info = create_execution_context_from( + request.specExecutionStartingRequest.currentExecutionInfo) + run_hook(request, response, registry.before_spec( + execution_info.specification.tags), execution_info) + response.executionStatusResponse.executionResult.message.extend( + MessagesStore.pending_messages()) + response.executionStatusResponse.executionResult.screenshots.extend( + ScreenshotsStore.pending_screenshots()) def _execute_after_spec_hook(request, response, _socket): - execution_info = create_execution_context_from(request.specExecutionEndingRequest.currentExecutionInfo) - run_hook(request, response, registry.after_spec(execution_info.specification.tags), execution_info) - response.executionStatusResponse.executionResult.message.extend(MessagesStore.pending_messages()) - response.executionStatusResponse.executionResult.screenshots.extend(ScreenshotsStore.pending_screenshots()) + execution_info = create_execution_context_from( + request.specExecutionEndingRequest.currentExecutionInfo) + run_hook(request, response, registry.after_spec( + execution_info.specification.tags), execution_info) + response.executionStatusResponse.executionResult.message.extend( + MessagesStore.pending_messages()) + response.executionStatusResponse.executionResult.screenshots.extend( + ScreenshotsStore.pending_screenshots()) def _execute_before_scenario_hook(request, response, _socket): - execution_info = create_execution_context_from(request.scenarioExecutionStartingRequest.currentExecutionInfo) - tags = list(execution_info.scenario.tags) + list(execution_info.specification.tags) + execution_info = create_execution_context_from( + request.scenarioExecutionStartingRequest.currentExecutionInfo) + tags = list(execution_info.scenario.tags) + \ + list(execution_info.specification.tags) run_hook(request, response, registry.before_scenario(tags), execution_info) - response.executionStatusResponse.executionResult.message.extend(MessagesStore.pending_messages()) - response.executionStatusResponse.executionResult.screenshots.extend(ScreenshotsStore.pending_screenshots()) + response.executionStatusResponse.executionResult.message.extend( + MessagesStore.pending_messages()) + response.executionStatusResponse.executionResult.screenshots.extend( + ScreenshotsStore.pending_screenshots()) def _execute_after_scenario_hook(request, response, _socket): - execution_info = create_execution_context_from(request.scenarioExecutionEndingRequest.currentExecutionInfo) - tags = list(execution_info.scenario.tags) + list(execution_info.specification.tags) + execution_info = create_execution_context_from( + request.scenarioExecutionEndingRequest.currentExecutionInfo) + tags = list(execution_info.scenario.tags) + \ + list(execution_info.specification.tags) run_hook(request, response, registry.after_scenario(tags), execution_info) - response.executionStatusResponse.executionResult.message.extend(MessagesStore.pending_messages()) - response.executionStatusResponse.executionResult.screenshots.extend(ScreenshotsStore.pending_screenshots()) + response.executionStatusResponse.executionResult.message.extend( + MessagesStore.pending_messages()) + response.executionStatusResponse.executionResult.screenshots.extend( + ScreenshotsStore.pending_screenshots()) def _execute_before_step_hook(request, response, _socket): - execution_info = create_execution_context_from(request.stepExecutionStartingRequest.currentExecutionInfo) - tags = list(execution_info.scenario.tags) + list(execution_info.specification.tags) + execution_info = create_execution_context_from( + request.stepExecutionStartingRequest.currentExecutionInfo) + tags = list(execution_info.scenario.tags) + \ + list(execution_info.specification.tags) run_hook(request, response, registry.before_step(tags), execution_info) - response.executionStatusResponse.executionResult.message.extend(MessagesStore.pending_messages()) - response.executionStatusResponse.executionResult.screenshots.extend(ScreenshotsStore.pending_screenshots()) + response.executionStatusResponse.executionResult.message.extend( + MessagesStore.pending_messages()) + response.executionStatusResponse.executionResult.screenshots.extend( + ScreenshotsStore.pending_screenshots()) def _execute_after_step_hook(request, response, _socket): - execution_info = create_execution_context_from(request.stepExecutionEndingRequest.currentExecutionInfo) - tags = list(execution_info.scenario.tags) + list(execution_info.specification.tags) + execution_info = create_execution_context_from( + request.stepExecutionEndingRequest.currentExecutionInfo) + tags = list(execution_info.scenario.tags) + \ + list(execution_info.specification.tags) run_hook(request, response, registry.after_step(tags), execution_info) - response.executionStatusResponse.executionResult.message.extend(MessagesStore.pending_messages()) - response.executionStatusResponse.executionResult.screenshots.extend(ScreenshotsStore.pending_screenshots()) + response.executionStatusResponse.executionResult.message.extend( + MessagesStore.pending_messages()) + response.executionStatusResponse.executionResult.screenshots.extend( + ScreenshotsStore.pending_screenshots()) def _init_scenario_data_store(request, response, _socket): @@ -191,7 +224,8 @@ def _step_positions(request, response, _socket): def step_positions_response(file_path, response): positions = registry.get_step_positions(file_path) response.messageType = Message.StepPositionsResponse - response.stepPositionsResponse.stepPositions.extend([_create_pos(x) for x in positions]) + response.stepPositionsResponse.stepPositions.extend( + [_create_pos(x) for x in positions]) def _create_pos(p): @@ -206,7 +240,8 @@ def _kill_runner(_request, _response, socket): def _get_impl_file_list(_request, response, _socket): response.messageType = Message.ImplementationFileListResponse files = get_impl_files() - response.implementationFileListResponse.implementationFilePaths.extend(files) + response.implementationFileListResponse.implementationFilePaths.extend( + files) def _get_stub_impl_content(request, response, _socket): @@ -220,10 +255,13 @@ def stub_impl_response(codes, file_name, response): content = read_file_contents(file_name) prefix = "" if content is not None: - new_line_char = '\n' if len(content.strip().split('\n')) == len(content.split('\n')) else '' + new_line_char = '\n' if len(content.strip().split( + '\n')) == len(content.split('\n')) else '' last_line = len(content.split('\n')) - prefix = "from getgauge.python import step\n" if len(content.strip()) == 0 else new_line_char - span = Span(**{'start': last_line, 'startChar': 0, 'end': last_line, 'endChar': 0}) + prefix = "from getgauge.python import step\n" if len( + content.strip()) == 0 else new_line_char + span = Span(**{'start': last_line, 'startChar': 0, + 'end': last_line, 'endChar': 0}) else: file_name = get_file_name() prefix = "from getgauge.python import step\n" @@ -268,15 +306,16 @@ def dispatch_messages(socket): while True: request = read_message(socket, Message()) response = Message() - + try: processors[request.messageType](request, response, socket) except Exception as e: response = Message() response.messageType = Message.ExecutionStatusResponse response.executionStatusResponse.executionResult.failed = True - response.executionStatusResponse.executionResult.errorMessage = str(e) - response.executionStatusResponse.executionResult.stackTrace = traceback.format_exc() + response.executionStatusResponse.executionResult.errorMessage = str( + e) + response.executionStatusResponse.executionResult.stackTrace = traceback.format_exc() if request.messageType != Message.CacheFileRequest: send_message(response, request, socket) diff --git a/getgauge/python.py b/getgauge/python.py index cb6aed3..a785283 100644 --- a/getgauge/python.py +++ b/getgauge/python.py @@ -1,18 +1,18 @@ import sys import warnings - from getgauge.registry import registry, MessagesStore, ScreenshotsStore -try: +if sys.version_info[0] is 3: from collections.abc import MutableMapping -except ImportError: +else: from collections import MutableMapping def step(step_text): def _step(func): f_code = sys._getframe().f_back.f_code - span = {'start': f_code.co_firstlineno, 'startChar': 0, 'end': 0, 'endChar': 0} + span = {'start': f_code.co_firstlineno, + 'startChar': 0, 'end': 0, 'endChar': 0} registry.add_step(step_text, func, f_code.co_filename, span) return func @@ -169,8 +169,10 @@ def tags(self): def __str__(self): return "Specification: {{ name: {}, is_failing: {}, tags: {}, file_name: {} }}".format(self.name, - str(self.is_failing), - ", ".join(self.tags), + str( + self.is_failing), + ", ".join( + self.tags), self.file_name) def __eq__(self, other): @@ -245,7 +247,8 @@ def __getattr__(self, name): try: return self[name] except KeyError: - raise AttributeError("'{0}' object has no attribute '{1}'".format(self.__class__.__name__, name)) + raise AttributeError("'{0}' object has no attribute '{1}'".format( + self.__class__.__name__, name)) def __setattr__(self, name, value): self[name] = value @@ -254,7 +257,8 @@ def __delattr__(self, name): try: del self[name] except KeyError: - raise AttributeError("'{0}' object has no attribute '{1}'".format(self.__class__.__name__, name)) + raise AttributeError("'{0}' object has no attribute '{1}'".format( + self.__class__.__name__, name)) class DataStoreContainer(object): @@ -303,7 +307,8 @@ def __eq__(self, other): def _warn_datastore_deprecation(store_type): warnings.warn( - "'DataStoreFactory.{0}_data_store()' is deprecated in favour of 'data_store.{0}'".format(store_type), + "'DataStoreFactory.{0}_data_store()' is deprecated in favour of 'data_store.{0}'".format( + store_type), DeprecationWarning, stacklevel=3) warnings.simplefilter('default', DeprecationWarning) diff --git a/getgauge/registry.py b/getgauge/registry.py index c1393bb..731492f 100644 --- a/getgauge/registry.py +++ b/getgauge/registry.py @@ -78,7 +78,8 @@ def get(self, tags=None): return _filter_hooks(tags, getattr(self, '__{}'.format(hook))) def add(self, func, tags=None): - getattr(self, '__{}'.format(hook)).append({'tags': tags, 'func': func}) + getattr(self, '__{}'.format(hook)).append( + {'tags': tags, 'func': func}) setattr(self.__class__, hook, get) setattr(self.__class__, 'add_{}'.format(hook), add) @@ -87,7 +88,8 @@ def add(self, func, tags=None): def add_step(self, step_text, func, file_name, span=None, has_alias=False, aliases=None): if not isinstance(step_text, list): parsed_step_text = _get_step_value(step_text) - info = StepInfo(step_text, parsed_step_text, func, file_name, span, has_alias, aliases) + info = StepInfo(step_text, parsed_step_text, func, + file_name, span, has_alias, aliases) self.__steps_map.setdefault(parsed_step_text, []).append(info) return for text in step_text: @@ -128,7 +130,8 @@ def is_continue_on_failure(self, func, exception): def get_step_positions(self, file_name): positions = [] for step, infos in self.__steps_map.items(): - positions = positions + [{'stepValue': step, 'span': i.span} for i in infos if i.file_name == file_name] + positions = positions + [{'stepValue': step, 'span': i.span} + for i in infos if i.file_name == file_name] return positions def remove_steps(self, file_name): @@ -172,9 +175,11 @@ def _take_screenshot(): _file.close() return data except Exception as err: - logging.error("\nFailed to take screenshot using gauge_screenshot.\n{0}".format(err)) + logging.error( + "\nFailed to take screenshot using gauge_screenshot.\n{0}".format(err)) except: - logging.error("\nFailed to take screenshot using gauge_screenshot.\n{0}".format(sys.exc_info()[0])) + logging.error("\nFailed to take screenshot using gauge_screenshot.\n{0}".format( + sys.exc_info()[0])) return str.encode("") diff --git a/getgauge/static_loader.py b/getgauge/static_loader.py index b7a4c95..47bbfc8 100644 --- a/getgauge/static_loader.py +++ b/getgauge/static_loader.py @@ -5,7 +5,8 @@ def load_steps(python_file): for funcStep in python_file.iter_steps(): - registry.add_step(funcStep[0], funcStep[1], python_file.file_path, funcStep[2]) + registry.add_step(funcStep[0], funcStep[1], + python_file.file_path, funcStep[2]) def reload_steps(file_path, content=None): @@ -17,7 +18,8 @@ def reload_steps(file_path, content=None): def load_files(step_impl_dir): for dirpath, dirs, files in os.walk(step_impl_dir): - py_files = (os.path.join(dirpath, f) for f in files if f.endswith('.py')) + py_files = (os.path.join(dirpath, f) + for f in files if f.endswith('.py')) for file_path in py_files: pf = PythonFile.parse(file_path) if pf: diff --git a/getgauge/util.py b/getgauge/util.py index 5b44906..702fc92 100644 --- a/getgauge/util.py +++ b/getgauge/util.py @@ -21,7 +21,7 @@ def get_impl_files(): file_list = [] for root, _, files in os.walk(step_impl_dir): for file in files: - if file.endswith('.py') and '__init__.py' != os.path.basename(file) : + if file.endswith('.py') and '__init__.py' != os.path.basename(file): file_list.append(os.path.join(root, file)) return file_list diff --git a/getgauge/validator.py b/getgauge/validator.py index bdb9172..fe70acb 100644 --- a/getgauge/validator.py +++ b/getgauge/validator.py @@ -2,7 +2,6 @@ import random import re import string - from getgauge.messages.messages_pb2 import Message, StepValidateResponse from getgauge.registry import registry @@ -14,11 +13,13 @@ def validate_step(request, response): response.stepValidateResponse.errorType = StepValidateResponse.STEP_IMPLEMENTATION_NOT_FOUND response.stepValidateResponse.errorMessage = 'Step implementation not found' response.stepValidateResponse.isValid = False - response.stepValidateResponse.suggestion = _impl_suggestion(request.stepValue) + response.stepValidateResponse.suggestion = _impl_suggestion( + request.stepValue) elif registry.has_multiple_impls(request.stepText): response.stepValidateResponse.isValid = False response.stepValidateResponse.errorType = StepValidateResponse.DUPLICATE_STEP_IMPLEMENTATION - response.stepValidateResponse.suggestion = _duplicate_impl_suggestion(request) + response.stepValidateResponse.suggestion = _duplicate_impl_suggestion( + request) def _duplicate_impl_suggestion(request): @@ -29,7 +30,8 @@ def _duplicate_impl_suggestion(request): def _impl_suggestion(step_value): - name = re.sub('\s*\{\}\s*', ' ', step_value.stepValue).strip().replace(' ', '_').lower() + name = re.sub('\s*\{\}\s*', ' ', + step_value.stepValue).strip().replace(' ', '_').lower() return """@step("{}") def {}({}): assert False, "Add implementation code" @@ -43,7 +45,8 @@ def _format_params(params): def _format_impl(impl): - lines = [l for l in impl.split('\n') if l.strip().startswith('def') or l.strip().startswith('@')] + lines = [l for l in impl.split('\n') if l.strip( + ).startswith('def') or l.strip().startswith('@')] return '\n'.join(lines) + '\n ...\n' @@ -54,6 +57,5 @@ def _is_valid(name, template='{} = None'): except: return False - def _random_word(length=6): return ''.join(random.choice(string.ascii_lowercase) for _ in range(length)) diff --git a/requirements.txt b/requirements.txt index 9ca3555..881978d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,5 @@ ptvsd==3.0.0 grpcio-tools grpcio protobuf>=3.5.2 -parso \ No newline at end of file +parso +futures \ No newline at end of file diff --git a/skel/step_impl/step_impl.py b/skel/step_impl/step_impl.py index beba388..34ce8f9 100644 --- a/skel/step_impl/step_impl.py +++ b/skel/step_impl/step_impl.py @@ -24,8 +24,10 @@ def assert_default_vowels(given_vowels): @step("Almost all words have vowels