Exemplo n.º 1
0
    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!'))
Exemplo n.º 2
0
    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!'))
Exemplo n.º 3
0
    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!'))
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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 {}"))
Exemplo n.º 8
0
    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 {}"))
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
    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)
Exemplo n.º 12
0
    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 {}"))
Exemplo n.º 13
0
    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 {}"))
Exemplo n.º 14
0
    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"))
Exemplo n.º 15
0
    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"))
Exemplo n.º 17
0
    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"))
Exemplo n.º 18
0
    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)
Exemplo n.º 20
0
    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)
Exemplo n.º 21
0
    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"))
Exemplo n.º 22
0
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
Exemplo n.º 23
0
    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)
Exemplo n.º 24
0
    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)
Exemplo n.º 25
0
    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)
Exemplo n.º 26
0
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)
                ]
            ),
        )