|
| 1 | +from galaxy.util import XML |
| 2 | +from galaxy.util.bunch import Bunch |
| 3 | +from galaxy.app_unittest_utils.galaxy_mock import MockTrans |
| 4 | +from galaxy.app_unittest_utils.tools_support import UsesTools |
| 5 | +from galaxy.tools.parameters import populate_state |
| 6 | +from galaxy.tools.parameters.basic import ( |
| 7 | + BooleanToolParameter, |
| 8 | + TextToolParameter, |
| 9 | +) |
| 10 | +from galaxy.tools.parameters.grouping import ( |
| 11 | + Conditional, |
| 12 | + Repeat, |
| 13 | +) |
| 14 | +from galaxy.tool_util.unittest_utils import functional_test_tool_path |
| 15 | +from galaxy.util.unittest import TestCase |
| 16 | + |
| 17 | + |
| 18 | +trans = Bunch(workflow_building_mode=False) |
| 19 | + |
| 20 | + |
| 21 | +def test_populate_state(): |
| 22 | + |
| 23 | + a = TextToolParameter(None, XML('<param name="a"/>')) |
| 24 | + b = Repeat('b') |
| 25 | + b.min = 0 |
| 26 | + b.max = 1 |
| 27 | + c = TextToolParameter(None, XML('<param name="c"/>')) |
| 28 | + d = Repeat('d') |
| 29 | + d.min = 0 |
| 30 | + d.max = 1 |
| 31 | + e = TextToolParameter(None, XML('<param name="e"/>')) |
| 32 | + f = Conditional('f') |
| 33 | + g = BooleanToolParameter(None, XML('<param name="g"/>')) |
| 34 | + h = TextToolParameter(None, XML('<param name="h"/>')) |
| 35 | + i = TextToolParameter(None, XML('<param name="i"/>')) |
| 36 | + b.inputs = dict([('c', c), ('d', d)]) |
| 37 | + d.inputs = dict([('e', e), ('f', f)]) |
| 38 | + f.test_param = g |
| 39 | + f.cases = [Bunch(value='true', inputs= { 'h': h }), Bunch(value='false', inputs= { 'i': i })] |
| 40 | + inputs = dict([('a',a),('b',b)]) |
| 41 | + flat = dict([('a', 1), ('b_0|c', 2), ('b_0|d_0|e', 3), ('b_0|d_0|f|h', 4), ('b_0|d_0|f|g', True)]) |
| 42 | + state = {} |
| 43 | + populate_state(trans, inputs, flat, state, check=False) |
| 44 | + assert state['a'] == 1 |
| 45 | + assert state['b'][0]['c'] == 2 |
| 46 | + assert state['b'][0]['d'][0]['e'] == 3 |
| 47 | + assert state['b'][0]['d'][0]['f']['h'] == 4 |
| 48 | + # now test with input_format='21.01' |
| 49 | + nested = {'a': 1, 'b': [{'c': 2, 'd': [{'e': 3, 'f': {'h': 4, 'g': True}}]}]} |
| 50 | + state_new = {} |
| 51 | + populate_state(trans, inputs, nested, state_new, check=False, input_format='21.01') |
| 52 | + assert state_new['a'] == 1 |
| 53 | + assert state_new['b'][0]['c'] == 2 |
| 54 | + assert state_new['b'][0]['d'][0]['e'] == 3 |
| 55 | + assert state_new['b'][0]['d'][0]['f']['h'] == 4 |
0 commit comments