From c79e4dcc40d00ce367d8efd74317319d762c4f17 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Tue, 13 May 2014 17:47:57 -0500 Subject: [PATCH] Fix duplicated names in on_text when using multiple data inputs. Unit tests verifing the fixed, correct behavior included. Bug introduced in e8c84dd715782e7c1d709d8068e6033b835f7f39 as an unintended consequence of duplicating the first dataset in the dictionary of input datasets generated by the tool action code. Fixes https://trello.com/c/LCEKxImR. --- lib/galaxy/tools/actions/__init__.py | 9 +++++++++ test/unit/tools/test_actions.py | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/galaxy/tools/actions/__init__.py b/lib/galaxy/tools/actions/__init__.py index 666a1c1709c..a51fe310de5 100644 --- a/lib/galaxy/tools/actions/__init__.py +++ b/lib/galaxy/tools/actions/__init__.py @@ -472,6 +472,15 @@ class DefaultToolAction( object ): def on_text_for_names( input_names ): + # input_names may contain duplicates... this is because the first value in + # multiple input dataset parameters will appear twice once as param_name + # and once as param_name1. + unique_names = [] + for name in input_names: + if name not in unique_names: + unique_names.append( name ) + input_names = unique_names + # Build name for output datasets based on tool name and input names if len( input_names ) == 1: on_text = input_names[0] diff --git a/test/unit/tools/test_actions.py b/test/unit/tools/test_actions.py index 52ae7bc3416..710452ffb24 100644 --- a/test/unit/tools/test_actions.py +++ b/test/unit/tools/test_actions.py @@ -2,6 +2,7 @@ import unittest from galaxy import model from galaxy.tools.actions import DefaultToolAction +from galaxy.tools.actions import on_text_for_names import tools_support @@ -25,6 +26,19 @@ DATA_IN_LABEL_TOOL_CONTENTS = ''' ''' +def test_on_text_for_names(): + def assert_on_text_is( expected, *names ): + on_text = on_text_for_names( names ) + assert on_text == expected, "Wrong on text value %s, expected %s" % ( on_text, expected ) + + assert_on_text_is( "data 1", "data 1" ) + assert_on_text_is( "data 1 and data 2", "data 1", "data 2" ) + assert_on_text_is( "data 1, data 2, and data 3", "data 1", "data 2", "data 3" ) + assert_on_text_is( "data 1, data 2, and others", "data 1", "data 2", "data 3", "data 4" ) + + assert_on_text_is( "data 1 and data 2", "data 1", "data 1", "data 2" ) + + class DefaultToolActionTestCase( unittest.TestCase, tools_support.UsesApp, tools_support.UsesTools ): def setUp( self ):