From 7ff99ec2334082e1e78daff926d59b757d8e1ea7 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Thu, 13 Jan 2022 12:23:30 +0100 Subject: [PATCH] move doctests to unit tests --- lib/galaxy/util/xml_macros.py | 97 +--------------- test/unit/tool_util/test_tool_loader.py | 142 ++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 91 deletions(-) diff --git a/lib/galaxy/util/xml_macros.py b/lib/galaxy/util/xml_macros.py index fdec287eb741..b0bced9bf4b7 100644 --- a/lib/galaxy/util/xml_macros.py +++ b/lib/galaxy/util/xml_macros.py @@ -160,97 +160,12 @@ def _expand_macro(element, expand_el, macros, tokens): def _expand_yield_statements(macro_def, expand_el): """ - Modifies the macro_def element by replacing all tags below the - macro_def element by the children of the expand_el - - >>> from galaxy.util import XML, xml_to_string - >>> expand_el = XML(''' - ... - ... - ... - ... - ... - ... - ... - ... - ... - ... - ... - ... ''') - >>> macro_def = XML(''' - ... - ... - ... - ... - ... ''') - >>> _expand_yield_statements(macro_def, expand_el) - >>> print(xml_to_string(macro_def, pretty=True)) - - - - - - - - - - - - - - - - >>> # test replacement of top level yields - >>> macro_def = XML(''' - ... - ... - ... - ... - ... - ... - ... - ... ''') - >>> _expand_yield_statements(macro_def, expand_el) - >>> print(xml_to_string(macro_def, pretty=True)) - - - - - - - - - - - - - >>> # test recursion like replacements - >>> expand_el = XML(''' - ... - ... - ... - ... - ... - ... - ... - ... - ... ''') - >>> macro_def = XML(''' - ... - ... - ... ''') - >>> _expand_yield_statements(macro_def, expand_el) - >>> print(xml_to_string(macro_def, pretty=True)) - - - - - - - - - - + Modifies the macro_def element by replacing + + 1. all named yield tags by the content of the corresponding token tags + - token tags need to be direct children of the expand + - processed in order of definition of the token tags + 2. all unnamed yield tags by the non-token children of the expand tag """ # replace named yields for token_el in expand_el.findall('./token'): diff --git a/test/unit/tool_util/test_tool_loader.py b/test/unit/tool_util/test_tool_loader.py index b42d57a4e384..550eddd0b317 100644 --- a/test/unit/tool_util/test_tool_loader.py +++ b/test/unit/tool_util/test_tool_loader.py @@ -332,3 +332,145 @@ def load(self, name="tool.xml", preprocess=True): assert input_els[0].find("cow").text == "hello" assert input_els[1].find("cow").text == "world" assert input_els[2].find("cow").text == "the_default" + + # test expansion of named and unnamed yield + # - named yields are replaced by content of the corresponding token + # - unnamed yields are replaced by all non-token elements of the expand tag + with TestToolDirectory() as tool_dir: + tool_dir.write(''' + + + + + + + + + + + + + + + + + + + + + + + + + + +''') + xml = tool_dir.load() + assert xml_to_string(xml, pretty=True) == ''' + + + + + + + + + + + + + + + +''' + + # test replacement of multiple top level yield + with TestToolDirectory() as tool_dir: + tool_dir.write(''' + + + + + + + + + + + + + + + + + + + + + + + + +''') + xml = tool_dir.load() + assert xml_to_string(xml, pretty=True) == ''' + + + + + + + + + + + + +''' + + + # test 'recursive' replacement with named yields + # since named yields are processed in order of the definition of the + # corresponding tokens: + # - replacing yield for token1 introduces yield for token2 + # - replacing yield for token2 introduced unnamed yield + # - replacing unnamed yield gives the only non-token element of the expand + with TestToolDirectory() as tool_dir: + tool_dir.write(''' + + + + + + + + + + + + + + + + + + + + + +''') + + xml = tool_dir.load() + print(xml_to_string(xml, pretty=True)) + assert xml_to_string(xml, pretty=True) == ''' + + + + + + + + + + +''' \ No newline at end of file