def generate_command(
         self, document: Document) -> Optional[GeneratedSnippetResult]:
     """Generates a boilerplate Cheetah code snippet based on the current inputs and outputs
     of this tool wrapper."""
     tool = GalaxyToolXmlDocument(document)
     generator = GalaxyToolCommandSnippetGenerator(tool)
     return generator.generate_snippet()
    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
 def generate_tests(self,
                    document: Document) -> Optional[GeneratedSnippetResult]:
     """Generates a code snippet with some tests for the current inputs and outputs
     of this tool wrapper."""
     tool = GalaxyToolXmlDocument(document)
     generator = GalaxyToolTestSnippetGenerator(tool)
     return generator.generate_snippet()
    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
    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
    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"
    def test_find_snippet_position_returns_expected_result(self, source: str, expected_position: Position) -> None:
        document = TestUtils.to_document(source)
        tool = GalaxyToolXmlDocument(document)
        generator = GalaxyToolCommandSnippetGenerator(tool)

        actual_position = generator._find_snippet_insert_position()

        assert actual_position == expected_position
Пример #8
0
    def test_generate_snippet_with_tests_section_returns_snippet_only(self) -> None:
        document = TestUtils.to_document("<tool><tests></tests></tool>")
        tool = GalaxyToolXmlDocument(document)
        generator = GalaxyToolTestSnippetGenerator(tool)

        result = generator.generate_snippet()

        assert "<tests>" not in result.snippet
    def test_build_snippet_returns_expected_result(self, tool_file: str, expected_snippet_file: str) -> None:
        document = TestUtils.get_test_document_from_file(tool_file)
        expected_snippet = TestUtils.get_test_file_contents(expected_snippet_file)
        tool = GalaxyToolXmlDocument(document)
        generator = GalaxyToolCommandSnippetGenerator(tool)

        actual_snippet = generator._build_snippet()

        assert actual_snippet == expected_snippet
Пример #10
0
    def test_generate_snippet_with_command_with_cdata_returns_snippet_only(self) -> None:
        document = TestUtils.to_document("<tool><command><![CDATA[]]></command></tool>")
        tool = GalaxyToolXmlDocument(document)
        generator = GalaxyToolCommandSnippetGenerator(tool)

        result = generator.generate_snippet()

        assert "<command" not in result.snippet
        assert "<![CDATA[" not in result.snippet
    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
 def _get_expanded_tool_document(self, tool_document: GalaxyToolXmlDocument) -> GalaxyToolXmlDocument:
     """If the given tool document uses macros, a new tool document with the expanded macros is returned,
     otherwise, the same document is returned.
     """
     if tool_document.uses_macros:
         try:
             document = tool_document.document
             expanded_tool_tree, _ = xml_macros.load_with_references(document.path)
             expanded_tool_tree = cast(etree._ElementTree, expanded_tool_tree)
             expanded_source = etree.tostring(expanded_tool_tree, encoding=str)
             expanded_document = Document(uri=document.uri, source=expanded_source, version=document.version)
             return GalaxyToolXmlDocument(expanded_document)
         except BaseException:
             return tool_document
     return tool_document
    def test_analyze_inputs_returns_expected_number_of_leaves(self) -> None:
        tool = GalaxyToolXmlDocument(TEST_TOOL_WITH_INPUTS_DOCUMENT)
        result = tool.analyze_inputs()

        assert len(result.leaves) == 3
    def test_uses_macros_returns_expected(self, source: str, expected: bool) -> None:
        document = TestUtils.to_document(source)
        tool = GalaxyToolXmlDocument(document)

        assert tool.uses_macros == expected
    def test_is_valid(self, source: str, expected: bool) -> None:
        document = TestUtils.to_document(source)
        tool = GalaxyToolXmlDocument(document)

        assert tool.is_valid == expected
    def test_init_sets_properties(self) -> None:
        document = TestUtils.to_document("<tool></tool>")
        tool = GalaxyToolXmlDocument(document)

        assert not tool.xml_document.is_empty