|
1 | | -from galaxy.util import XML |
2 | | -from galaxy.util.bunch import Bunch |
3 | 1 | from galaxy.app_unittest_utils.galaxy_mock import MockTrans |
4 | 2 | from galaxy.app_unittest_utils.tools_support import UsesTools |
| 3 | +from galaxy.tool_util.unittest_utils import functional_test_tool_path |
5 | 4 | from galaxy.tools.parameters import populate_state |
6 | 5 | from galaxy.tools.parameters.basic import ( |
7 | 6 | BooleanToolParameter, |
|
11 | 10 | Conditional, |
12 | 11 | Repeat, |
13 | 12 | ) |
14 | | -from galaxy.tool_util.unittest_utils import functional_test_tool_path |
| 13 | +from galaxy.util import XML |
| 14 | +from galaxy.util.bunch import Bunch |
15 | 15 | from galaxy.util.unittest import TestCase |
16 | 16 |
|
17 | | - |
18 | 17 | trans = Bunch(workflow_building_mode=False) |
19 | 18 |
|
20 | 19 |
|
21 | 20 | def test_populate_state(): |
22 | | - |
| 21 | + |
23 | 22 | a = TextToolParameter(None, XML('<param name="a"/>')) |
24 | | - b = Repeat('b') |
| 23 | + b = Repeat("b") |
25 | 24 | b.min = 0 |
26 | 25 | b.max = 1 |
27 | 26 | c = TextToolParameter(None, XML('<param name="c"/>')) |
28 | | - d = Repeat('d') |
| 27 | + d = Repeat("d") |
29 | 28 | d.min = 0 |
30 | 29 | d.max = 1 |
31 | 30 | e = TextToolParameter(None, XML('<param name="e"/>')) |
32 | | - f = Conditional('f') |
| 31 | + f = Conditional("f") |
33 | 32 | g = BooleanToolParameter(None, XML('<param name="g"/>')) |
34 | 33 | h = TextToolParameter(None, XML('<param name="h"/>')) |
35 | 34 | i = TextToolParameter(None, XML('<param name="i"/>')) |
36 | | - b.inputs = dict([('c', c), ('d', d)]) |
37 | | - d.inputs = dict([('e', e), ('f', f)]) |
| 35 | + b.inputs = dict([("c", c), ("d", d)]) |
| 36 | + d.inputs = dict([("e", e), ("f", f)]) |
38 | 37 | 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)]) |
| 38 | + f.cases = [Bunch(value="true", inputs={"h": h}), Bunch(value="false", inputs={"i": i})] |
| 39 | + inputs = dict([("a", a), ("b", b)]) |
| 40 | + 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 | 41 | state = {} |
43 | 42 | 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 |
| 43 | + assert state["a"] == 1 |
| 44 | + assert state["b"][0]["c"] == 2 |
| 45 | + assert state["b"][0]["d"][0]["e"] == 3 |
| 46 | + assert state["b"][0]["d"][0]["f"]["h"] == 4 |
48 | 47 | # now test with input_format='21.01' |
49 | | - nested = {'a': 1, 'b': [{'c': 2, 'd': [{'e': 3, 'f': {'h': 4, 'g': True}}]}]} |
| 48 | + nested = {"a": 1, "b": [{"c": 2, "d": [{"e": 3, "f": {"h": 4, "g": True}}]}]} |
50 | 49 | 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 |
| 50 | + populate_state(trans, inputs, nested, state_new, check=False, input_format="21.01") |
| 51 | + assert state_new["a"] == 1 |
| 52 | + assert state_new["b"][0]["c"] == 2 |
| 53 | + assert state_new["b"][0]["d"][0]["e"] == 3 |
| 54 | + assert state_new["b"][0]["d"][0]["f"]["h"] == 4 |
| 55 | + |
| 56 | + |
| 57 | +class TestMetadata(TestCase, UsesTools): |
| 58 | + def setUp(self): |
| 59 | + super().setUp() |
| 60 | + self.setup_app() |
| 61 | + self.trans = MockTrans(app=self.app) |
| 62 | + |
| 63 | + def test_boolean_validation(self): |
| 64 | + source_file_name = functional_test_tool_path("parameters/gx_data_column.xml") |
| 65 | + tool = self._init_tool_for_path(source_file_name) |
| 66 | + incoming = {"ref_parameter": {"src": "hda", "id": 89}, "parameter": "m89"} |
| 67 | + state_new = {} |
| 68 | + errors = {} |
| 69 | + populate_state(self.trans, tool.inputs, incoming, state_new, errors=errors, check=True, input_format="21.01") |
| 70 | + print(state_new) |
| 71 | + assert False |
0 commit comments