コード例 #1
0
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'))
        for file_path in py_files:
            pf = PythonFile.parse(file_path)
            if pf:
                load_steps(pf)
コード例 #2
0
    def test_loader_non_string_argument(self):
        content = dedent("""
            @step(100)
            def printf(arg1):
                print(arg1)
            """)
        load_steps(PythonFile.parse("foo.py", content))

        self.assertFalse(registry.is_implemented("print hello {}"))
コード例 #3
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(PythonFile.parse("foo.py", content))

        self.assertTrue(registry.is_implemented("print hello {}"))
コード例 #4
0
    def test_loader_triple_quote_strings(self):
        content = dedent("""
            @step('''print hello <>''')
            def printf(arg1):
                print(arg1)
            """)
        load_steps(PythonFile.parse("foo.py", content))

        self.assertTrue(registry.is_implemented("print hello {}"))
コード例 #5
0
    def test_loader_step_indirect_argument(self):
        content = dedent("""
            v = 'print hello <>'
            @step(v)
            def printf(arg1):
                print(arg1)
            """)
        load_steps(PythonFile.parse("foo.py", content))

        self.assertFalse(registry.is_implemented("print hello {}"))
コード例 #6
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)
コード例 #7
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(PythonFile.parse("foo.py", content))
        self.assertTrue(registry.has_multiple_impls("print hello"))
コード例 #8
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(PythonFile.parse("foo.py", content))

        self.assertTrue(registry.is_implemented("print hello"))
        self.assertTrue(registry.is_implemented("print {}."))
        self.assertEqual(len(registry.steps()), 2)
コード例 #9
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(PythonFile.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"))
コード例 #10
0
    def test_loader_reload_registry_for_given_content(self):
        content = dedent("""
            @step("print hello")
            def printf():
                print("hello")
            """)
        load_steps(PythonFile.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"))
コード例 #11
0
def refactor_step(request, response, with_location=True):
    if registry.has_multiple_impls(request.oldStepValue.stepValue):
        raise Exception('Multiple Implementation found for `{}`'.format(
            request.oldStepValue.parameterizedStepValue))
    info = registry.get_info_for(request.oldStepValue.stepValue)
    impl_file = PythonFile.parse(info.file_name)
    diffs = impl_file.refactor_step(
        info.step_text,
        request.newStepValue.parameterizedStepValue,
        _new_parameter_positions(request),
    )
    content = impl_file.get_code()
    if request.saveChanges:
        with open(info.file_name, 'w') as f:
            f.write(content)
    response.refactorResponse.success = True
    response.refactorResponse.filesChanged.append(info.file_name)
    response.refactorResponse.fileChanges.add(
        fileName=info.file_name,
        fileContent=content,  # FIXME: Remove deprecated field
        diffs=[TextDiff(span=Span(**d[0]), content=d[1]) for d in diffs],
    )
コード例 #12
0
 def load_content_steps(self, content):
     content = dedent(content)
     pf = PythonFile.parse("foo.py", content)
     self.assertIsNotNone(pf)
     loader.load_steps(pf)
コード例 #13
0
def reload_steps(file_path, content=None):
    pf = PythonFile.parse(file_path, content)
    if pf:
        registry.remove_steps(file_path)
        load_steps(pf)