コード例 #1
0
    def test_find_tests_section_without_section_returns_none(self) -> None:
        document = TestUtils.to_document("<tool></tool>")
        tool = GalaxyToolXmlDocument(document)

        actual = tool.find_element("notexistent")

        assert actual is None
コード例 #2
0
    def test_get_element_content_range_of_element_returns_expected(self, source: str, element: str, expected: Range) -> None:
        document = TestUtils.to_document(source)
        tool = GalaxyToolXmlDocument(document)
        node = tool.find_element(element)

        actual = tool.get_element_content_range(node)

        assert actual == expected
コード例 #3
0
    def test_get_element_content_range_of_unknown_element_returns_none(self) -> None:
        document = TestUtils.to_document("<tool><tests></tests></tool>")
        tool = GalaxyToolXmlDocument(document)
        node = tool.find_element("unknown")

        actual = tool.get_element_content_range(node)

        assert actual is None
コード例 #4
0
    def test_find_tests_section_returns_expected(self) -> None:
        document = TestUtils.to_document("<tool><tests></tests></tool>")
        tool = GalaxyToolXmlDocument(document)

        actual = tool.find_element("tests")

        assert actual
        assert actual.name == "tests"
コード例 #5
0
    def test_get_position_after_element_returns_expected_position(
        self, source: str, element_name: str, expected_position: Position
    ) -> None:
        document = TestUtils.to_document(source)
        tool = GalaxyToolXmlDocument(document)
        element = tool.find_element(element_name, maxlevel=4)

        assert element is not None
        actual_position = tool.get_position_after(element)
        assert actual_position == expected_position
コード例 #6
0
    def _find_macros_insert_position(self,
                                     tool: GalaxyToolXmlDocument) -> Position:
        """Returns the position inside the document where the macros section
        can be inserted.

        Returns:
            Range: The position where the macros section can be inserted in the document.
        """
        section = tool.find_element(XREF)
        if section:
            return tool.get_position_after(section)
        section = tool.find_element(DESCRIPTION)
        if section:
            return tool.get_position_after(section)
        root = tool.find_element(TOOL)
        content_range = tool.get_content_range(root)
        if content_range:
            return content_range.start
        return Position(line=0, character=0)
コード例 #7
0
 def _edit_create_import_macros_section(self, tool: GalaxyToolXmlDocument,
                                        macros_file_name: str) -> TextEdit:
     """Returns the TextEdit operation that will add a macros file <import> definition to the existing
     <macros> section of a tool wrapper or also create the <macros> section if it doesn't exists."""
     macros_element = tool.find_element(MACROS)
     if macros_element:
         insert_position = tool.get_position_before_first_child(
             macros_element)
         macro_xml = f"<import>{macros_file_name}</import>"
     else:
         insert_position = self._find_macros_insert_position(tool)
         macro_xml = f"<macros>\n<import>{macros_file_name}</import>\n</macros>"
     insert_range = Range(start=insert_position, end=insert_position)
     final_macro_xml = self._adapt_format(tool.xml_document, insert_range,
                                          macro_xml)
     return TextEdit(
         range=insert_range,
         new_text=final_macro_xml,
     )