Пример #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_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 {}"))
Пример #3
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 {}"))
Пример #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 setUp(self):
     PythonFile.select_python_parser('parso')
     StaticLoaderTests.setUp(self)
Пример #14
0
def reload_steps(file_path, content=None):
    pf = PythonFile.parse(file_path, content)
    if pf:
        registry.remove_steps(file_path)
        load_steps(pf)
Пример #15
0
 def tearDown(self):
     RefactorTests.tearDown(self)
     PythonFile.select_python_parser()
Пример #16
0
 def setUp(self):
     PythonFile.select_python_parser('parso')
     RefactorTests.setUp(self)
Пример #17
0
 def setUp(self):
     PythonFile.select_python_parser('redbaron')
     RefactorTests.setUp(self)
Пример #18
0
 def tearDown(self):
     PythonFile.select_python_parser()