def test_LspServerHandler_cache_file(self): handler = LspServerHandler(None) content = "from getgauge.python import step\n\n" \ "@step('Vowels in English language are <aeiou>.')\n" \ "def foo(vowels):" \ "\tprint(vowels)" loader.load_steps(content, 'foo.py') self.assertTrue( registry.is_implemented('Vowels in English language are {}.')) content = "from getgauge.python import step\n\n" \ "@step('get lost!')\n" \ "def foo():" \ "\tpass" req = CacheFileRequest( **{ 'content': content, 'filePath': 'foo.py', 'status': CacheFileRequest.CHANGED }) handler.CacheFile(req, None) self.assertTrue(registry.is_implemented('get lost!'))
def test_LspServerHandler_cache_file(self): handler = LspServerHandler(None) self.load_content_steps('''\ from getgauge.python import step @step('Vowels in English language are <aeiou>.') def foo(vowels): print(vowels) ''') self.assertTrue(registry.is_implemented( 'Vowels in English language are {}.')) content = dedent('''\ from getgauge.python import step @step('get lost!') def foo(): pass ''') req = CacheFileRequest( content=content, filePath='foo.py', status=CacheFileRequest.CHANGED) handler.CacheFile(req, None) self.assertTrue(registry.is_implemented('get lost!'))
def test_Processor_process_cache_file_request(self): self.load_content_steps('''\ from getgauge.python import step @step('Vowels in English language are <aeiou>.') def foo(vowels): print(vowels) ''') self.assertTrue( registry.is_implemented('Vowels in English language are {}.')) content = dedent('''\ from getgauge.python import step @step('get lost!') def foo(): pass ''') req = CacheFileRequest(content=content, filePath='foo.py', status=CacheFileRequest.CHANGED) processor.process_cache_file_request(req) self.assertTrue(registry.is_implemented('get lost!'))
def test_Processor_cache_file_with_closed_status(self): request = Message() response = Message() self.load_content_steps('''\ from getgauge.python import step @step('foo1') def foo(): pass ''') request.cacheFileRequest.filePath = 'foo.py' request.cacheFileRequest.status = CacheFileRequest.CLOSED self.fs.create_file('foo.py', contents=dedent('''\ from getgauge.python import step @step('foo <bar>') def foo(): pass ''')) processors[Message.CacheFileRequest](request, response, None) self.assertEqual(registry.is_implemented('foo1'), False) self.assertEqual(registry.is_implemented('foo {}'), True)
def test_Processor_cache_file_with_changed_status(self): request = Message() response = Message() ast = loader.generate_ast("from getgauge.python import step\n@step('foo1')\ndef foo():\n\tpass\n", "foo.py") loader.load_steps(ast, "foo.py") request.cacheFileRequest.filePath = 'foo.py' request.cacheFileRequest.content = "from getgauge.python import step\n@step('foo <bar>')\ndef foo():\n\tpass\n" request.cacheFileRequest.status = CacheFileRequest.CHANGED processors[Message.CacheFileRequest](request, response, None) self.assertEqual(registry.is_implemented('foo1'), False) self.assertEqual(registry.is_implemented('foo {}'), True)
def test_loader_populates_registry_from_given_file_content(self): content = dedent(""" @step("print hello") def printf(): print("hello") @step("print <hello>.") def print_word(word): print(word) """) load_steps(Parser.parse("foo.py", content)) self.assertTrue(registry.is_implemented("print hello")) self.assertTrue(registry.is_implemented("print {}.")) self.assertEqual(len(registry.steps()), 2)
def test_loader_triple_quote_strings(self): content = dedent(""" @step('''print hello <>''') def printf(arg1): print(arg1) """) load_steps(Parser.parse("foo.py", content)) self.assertTrue(registry.is_implemented("print hello {}"))
def test_loader_non_string_argument(self): content = dedent(""" @step(100) def printf(arg1): print(arg1) """) load_steps(Parser.parse("foo.py", content)) self.assertFalse(registry.is_implemented("print hello {}"))
def test_loader_reload_registry_for_given_content_with_empty_arg(self): content = """ @step("print hello <>") def print(arg1): print(arg1) """ load_steps(content, "foo.py") self.assertTrue(registry.is_implemented("print hello {}"))
def test_loader_populates_registry_from_given_file_content(self): content = """ @step("print hello") def print(): print("hello") @step("print <hello>.") def print_word(word): print(word) """ ast = generate_ast(content, "foo.py") load_steps(ast, "foo.py") self.assertTrue(registry.is_implemented("print hello")) self.assertTrue(registry.is_implemented("print {}.")) self.assertEqual(len(registry.steps()), 2)
def test_Processor_cache_file_with_create_status_when_file_is_cached(self): request = CacheFileRequest() self.load_content_steps('''\ from getgauge.python import step @step('foo <bar>') def foo(): pass ''') self.assertEqual(registry.is_implemented('foo {}'), True) request.filePath = 'foo.py' request.status = CacheFileRequest.CREATED self.fs.create_file('foo.py') processor.process_cache_file_request(request) self.assertEqual(registry.is_implemented('foo {}'), True)
def test_loader_reload_registry_for_given_content_with_empty_arg(self): content = dedent(""" @step("print hello <>") def printf(arg1): print(arg1) """) load_steps(Parser.parse("foo.py", content)) self.assertTrue(registry.is_implemented("print hello {}"))
def test_loader_step_indirect_argument(self): content = dedent(""" v = 'print hello <>' @step(v) def printf(arg1): print(arg1) """) load_steps(Parser.parse("foo.py", content)) self.assertFalse(registry.is_implemented("print hello {}"))
def test_loader_populates_registry_only_with_steps_from_given_file_content( self): content = dedent(""" @step("print hello") def printf(): print("hello") @hello("some other decorator") @step("print <hello>.") def print_word(word): print(word) """) load_steps(Parser.parse("foo.py", content)) self.assertTrue(registry.is_implemented("print hello")) self.assertTrue(registry.is_implemented("print {}.")) self.assertFalse(registry.is_implemented("some other decorator"))
def test_Processor_cache_file_with_create_status(self): request = Message() response = Message() request.cacheFileRequest.filePath = 'foo.py' request.cacheFileRequest.status = CacheFileRequest.CREATED self.fs.create_file('foo.py', contents="from getgauge.python import step\n@step('foo <bar>')\ndef foo():\n\tpass\n") processors[Message.CacheFileRequest](request, response, None) self.assertEqual(registry.is_implemented('foo {}'), True)
def test_loader_does_not_populate_registry_for_content_having_parse_error( self): content = """ @step("print hello") def print(): print(.__str_()) """ load_steps(content, "foo.py") self.assertFalse(registry.is_implemented("print hello"))
def test_loader_reload_registry_for_given_content(self): content = dedent(""" @step("print hello") def printf(): print("hello") """) load_steps(Parser.parse("foo.py", content)) self.assertTrue(registry.is_implemented("print hello")) content = dedent(""" @step("print world") def printf(): print("hello") """) reload_steps('foo.py', content) self.assertFalse(registry.is_implemented("print hello")) self.assertTrue(registry.is_implemented("print world"))
def test_loader_populates_registry_only_with_steps_from_given_file_content( self): content = """ @step("print hello") def print(): print("hello") @hello("some other decorator") @step("print <hello>.") def print_word(word): print(word) """ ast = generate_ast(content, "foo.py") load_steps(ast, "foo.py") self.assertTrue(registry.is_implemented("print hello")) self.assertTrue(registry.is_implemented("print {}.")) self.assertFalse(registry.is_implemented("some other decorator"))
def test_loader_populates_registry_for_with_aliases(self): content = """ @step(["print hello", "say hello"]) def print(): print("hello") """ load_steps(content, "foo.py") self.assertTrue(registry.is_implemented("say hello")) self.assertTrue(registry.get_info_for("say hello").has_alias)
def test_loader_populates_registry_for_with_aliases(self): content = dedent(""" @step(["print hello", "say hello"]) def printf(): print("hello") """) load_steps(PythonFile.parse("foo.py", content)) self.assertTrue(registry.is_implemented("say hello")) self.assertTrue(registry.get_info_for("say hello").has_alias)
def test_loader_reload_registry_for_given_content(self): content = """ @step("print hello") def print(): print("hello") """ ast = generate_ast(content, "foo.py") load_steps(ast, "foo.py") self.assertTrue(registry.is_implemented("print hello")) content = """ @step("print world") def print(): print("hello") """ reload_steps(content, 'foo.py') self.assertFalse(registry.is_implemented("print hello")) self.assertTrue(registry.is_implemented("print world"))
def validate_step(request): response = StepValidateResponse() response.isValid = True if registry.is_implemented(request.stepText) is False: response.errorType = StepValidateResponse.STEP_IMPLEMENTATION_NOT_FOUND response.errorMessage = 'Step implementation not found' response.isValid = False response.suggestion = _impl_suggestion(request.stepValue) elif registry.has_multiple_impls(request.stepText): response.isValid = False response.errorType = StepValidateResponse.DUPLICATE_STEP_IMPLEMENTATION response.suggestion = _duplicate_impl_suggestion(request) return response
def test_Processor_cache_file_with_delete_status(self): request = Message() response = Message() loader.load_steps( "from getgauge.python import step\n@step('foo1')\ndef foo():\n\tpass\n", 'foo.py') request.cacheFileRequest.filePath = 'foo.py' request.cacheFileRequest.status = CacheFileRequest.DELETED processors[Message.CacheFileRequest](request, response, None) self.assertEqual(registry.is_implemented('foo1'), False)
def test_Processor_cache_file_with_changed_status(self): request = CacheFileRequest() self.load_content_steps('''\ from getgauge.python import step @step('foo1') def foo(): pass ''') request.filePath = 'foo.py' request.content = dedent('''\ from getgauge.python import step @step('foo <bar>') def foo(): pass ''') request.status = CacheFileRequest.CHANGED processor.process_cache_file_request(request) self.assertEqual(registry.is_implemented('foo1'), False) self.assertEqual(registry.is_implemented('foo {}'), True)
def test_Processor_cache_file_with_delete_status(self): request = CacheFileRequest() self.load_content_steps('''\ from getgauge.python import step @step('foo1') def foo(): pass ''') request.filePath = 'foo.py' request.status = CacheFileRequest.DELETED processor.process_cache_file_request(request) self.assertEqual(registry.is_implemented('foo1'), False)
def validate_step(request, response): response.messageType = Message.StepValidateResponse response.stepValidateResponse.isValid = True if registry.is_implemented(request.stepValidateRequest.stepText) is False: response.stepValidateResponse.errorType = StepValidateResponse.STEP_IMPLEMENTATION_NOT_FOUND response.stepValidateResponse.errorMessage = "Step implementation not found" response.stepValidateResponse.isValid = False elif registry.has_multiple_impls(request.stepValidateRequest.stepText): response.stepValidateResponse.isValid = False response.stepValidateResponse.errorType = StepValidateResponse.DUPLICATE_STEP_IMPLEMENTATION response.stepValidateResponse.errorMessage = "Multiple implementation found for `{}` ({})".format( request.stepValidateRequest.stepText, ", ".join( [ "{}:{}".format(impl.file_name, impl.line_number) for impl in registry.get_infos_for(request.stepValidateRequest.stepText) ] ), )