Пример #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!'))
Пример #2
0
    def test_LspServerHandler_step_positions(self):
        handler = LspServerHandler(None)
        content = "@step('foo')\ndef foo():\n\tpass\n"
        loader.load_steps(content, 'foo.py')

        req = StepPositionsRequest(**{'filePath': 'foo.py'})
        res = handler.GetStepPositions(req, None)
        self.assertEqual(res.stepPositions[0].stepValue, 'foo')
Пример #3
0
    def test_LspServerHandler_step_names(self):
        handler = LspServerHandler(None)
        content = "@step('foo')\ndef foo():\n\tpass\n"
        loader.load_steps(content, 'foo.py')

        req = StepNamesRequest()
        res = handler.GetStepNames(req, None)

        self.assertEqual(res.steps, ['foo'])
Пример #4
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 {}"))
Пример #5
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 {}"))
Пример #6
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 {}"))
    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 {}"))
Пример #8
0
    def test_LspServerHandler_step_name(self):
        handler = LspServerHandler(None)
        content = "@step('foo')\ndef foo():\n\tpass\n"
        loader.load_steps(content, 'foo.py')

        req = StepNameRequest(**{'stepValue': 'foo'})
        res = handler.GetStepName(req, None)

        self.assertTrue(res.isStepPresent)
        self.assertEqual(res.fileName, 'foo.py')
Пример #9
0
    def test_LspServerHandler_implement_stub(self):
        handler = LspServerHandler(None)
        content = "@step('foo')\ndef foo():\n\tpass\n"
        ast = loader.generate_ast(content, 'foo.py')
        loader.load_steps(ast, 'foo.py')

        req = StubImplementationCodeRequest(**{'implementationFilePath': 'New File', 'codes': ['add hello']})
        res = handler.ImplementStub(req, None)
        self.assertEqual(os.path.basename(res.filePath), 'step_implementation.py')
        self.assertEqual(res.textDiffs[0].content, 'from getgauge.python import step\n\nadd hello')
Пример #10
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 {}"))
Пример #11
0
    def test_LspServerHandler_validate_step(self):
        handler = LspServerHandler(None)
        content = "@step('foo')\ndef foo():\n\tpass\n"
        ast = loader.generate_ast(content, 'foo.py')
        loader.load_steps(ast, 'foo.py')
        step_value = ProtoStepValue(**{'stepValue': 'foo', 'parameterizedStepValue': 'foo'})

        req = StepValidateRequest(**{'stepText': 'foo', 'stepValue': step_value, 'numberOfParameters': 0})
        res = handler.ValidateStep(req, None)
        self.assertTrue(res.isValid)
    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_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)
Пример #14
0
    def test_Processor_cache_file_with_delete_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.status = CacheFileRequest.DELETED

        processors[Message.CacheFileRequest](request, response, None)

        self.assertEqual(registry.is_implemented('foo1'), False)
Пример #15
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)
Пример #16
0
    def test_loader_populates_registry_with_duplicate_steps(self):
        content = dedent("""
        @step("print hello")
        def printf():
            print("hello")


        @step("print hello")
        def print_word():
            print("hello")

        """)
        load_steps(Parser.parse("foo.py", content))
        self.assertTrue(registry.has_multiple_impls("print hello"))
    def test_loader_populates_registry_with_duplicate_steps(self):
        content = """
        @step("print hello")
        def print():
            print("hello")


        @step("print hello")
        def print_word():
            print("hello")

        """
        load_steps(content, "foo.py")
        self.assertTrue(registry.has_multiple_impls("print hello"))
Пример #18
0
    def test_Processor_cache_file_with_closed_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.status = CacheFileRequest.CLOSED
        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('foo1'), False)
        self.assertEqual(registry.is_implemented('foo {}'), True)
Пример #19
0
    def test_Processor_cache_file_with_changed_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.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)
Пример #20
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)
Пример #21
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)
Пример #22
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"))
Пример #23
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"))
Пример #24
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"))
Пример #25
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"))
Пример #26
0
 def load_content_steps(self, content):
     content = dedent(content)
     pf = PythonFile.parse("foo.py", content)
     self.assertIsNotNone(pf)
     loader.load_steps(pf)