diff --git a/lib/galaxy/util/xml_macros.py b/lib/galaxy/util/xml_macros.py
index b02796080e1..7af8c5bd10c 100644
--- a/lib/galaxy/util/xml_macros.py
+++ b/lib/galaxy/util/xml_macros.py
@@ -173,7 +173,7 @@ def _expand_yield_statements(macro_def, expand_el):
if macro_def_el.tag == "yield":
for target in expand_el_children:
i += 1
- macro_def.insert(i, deepcopy(target))
+ macro_def.insert(i, target)
macro_def.remove(macro_def_el)
continue
@@ -269,7 +269,7 @@ def _xml_replace(query, targets, parent_map):
current_index = matching_index
for target in targets:
current_index += 1
- parent_el.insert(current_index, deepcopy(target))
+ parent_el.insert(current_index, target)
parent_el.remove(query)
diff --git a/test/unit/tool_util/test_tool_loader.py b/test/unit/tool_util/test_tool_loader.py
index ce644a510ef..ceedfd51f32 100644
--- a/test/unit/tool_util/test_tool_loader.py
+++ b/test/unit/tool_util/test_tool_loader.py
@@ -62,8 +62,19 @@ def test_loader():
+
+
+
+
+
+
+
+
+
+
+
@@ -71,7 +82,9 @@ def test_loader():
''')
xml = tool_dir.load()
- assert xml.find("inputs").find("input").get("name") == "first_input"
+ assert xml.findall("inputs")[0].find("input").get("name") == "first_input"
+ assert xml.findall("inputs")[1].find("input").get("name") == "second_input"
+ assert xml.findall("inputs")[2].find("input").get("name") == "third_input"
# Test recursive macro applications.
with TestToolDirectory() as tool_dir:
@@ -227,6 +240,8 @@ def test_loader():
tool_dir.write('''
+
+
@@ -236,8 +251,10 @@ def test_loader():
''')
xml = tool_dir.load()
input_els = xml.findall("inputs")
- assert len(input_els) == 1
+ assert len(input_els) == 3
assert input_els[0].attrib["type"] == "the type is hello"
+ assert input_els[1].attrib["type"] == "the type is my awesome"
+ assert input_els[2].attrib["type"] == "the type is doggo"
# Test macros XML macros with @ expansions in text
with TestToolDirectory() as tool_dir:
@@ -259,3 +276,27 @@ def test_loader():
assert input_els[0].text == "hello"
assert input_els[1].text == "world"
assert input_els[2].text == "the_default"
+
+ # Test macros XML macros with @ expansions and recursive
+ with TestToolDirectory() as tool_dir:
+ tool_dir.write('''
+
+
+
+
+
+
+ @FOO@
+
+
+
+
+
+
+''')
+ xml = tool_dir.load()
+ input_els = xml.findall("inputs")
+ assert len(input_els) == 3
+ 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"