Skip to content

Commit

Permalink
assert that data_column parameters have a valid data_ref
Browse files Browse the repository at this point in the history
- it needs to be specified in the XML
- needs to refer to an existing parameter
  • Loading branch information
bernt-matthias committed Oct 8, 2024
1 parent c1bf181 commit d040bfb
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/tool_shed/tools/tool_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def load_tool_from_config(self, repository_id, full_path):
tool = None
valid = False
error_message = (
f'This file requires an entry for "{str(e)}" in the tool_data_table_conf.xml file. Upload a file '
f'This file requires an entry for "{str(e)}" in the tool_data_table_conf.xml file. Upload a file '
)
error_message += (
"named tool_data_table_conf.xml.sample to the repository that includes the required entry to correct "
Expand Down
3 changes: 1 addition & 2 deletions lib/galaxy/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1660,8 +1660,7 @@ def parse_param_elem(self, input_source: InputSource, enctypes, context) -> Tool
# form when it changes
for name in param.get_dependencies():
# Let it throw exception, but give some hint what the problem might be
if name not in context:
log.error(f"Tool with id '{self.id}': Could not find dependency '{name}' of parameter '{param.name}'")
assert name in context, f"Tool with id '{self.id}': Could not find dependency '{name}' of parameter '{param.name}'"
context[name].refresh_on_change = True
return param

Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/tools/parameters/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,7 @@ def __init__(self, tool, input_source):
if self.accept_default:
self.optional = True
self.data_ref = input_source.get("data_ref", None)
assert self.data_ref is not None, f'data_column parameter {self.name} requires a valid data_ref attribute'
self.ref_input = None
# Legacy style default value specification...
self.default_value = input_source.get("default_value", None)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<tool id="missing_data_ref" name="missing_data_ref" version="1.0" profile="23.0">
<requirements>
</requirements>
<command detect_errors="aggressive">
<![CDATA[
echo $column
]]>
</command>
<inputs>
<param name="input" type="data" format="tabular"/>
<param name="column" type="data_column" />
</inputs>
<outputs>
<data name="output" format="text"/>
</outputs>
<tests>
</tests>
<help/>
</tool>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<tool id="wrong_data_ref" name="wrong_data_ref" version="1.0" profile="23.0">
<requirements>
</requirements>
<command detect_errors="aggressive">
<![CDATA[
echo $column
]]>
</command>
<inputs>
<param name="input" type="data" format="tabular"/>
<param name="column" type="data_column" data_ref="nonsense" />
</inputs>
<outputs>
<data name="output" format="text"/>
</outputs>
<tests>
</tests>
<help/>
</tool>
18 changes: 18 additions & 0 deletions test/unit/tool_shed/test_tool_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
BOWTIE2_INDICES = os.path.join(
galaxy_directory(), "lib/tool_shed/test/test_data/bowtie2_loc_sample/bowtie2_indices.loc.sample"
)
MISSING_DATA_REF_DIR = os.path.join(galaxy_directory(), "lib/tool_shed/test/test_data/repos/missing_data_ref")
WRONG_DATA_REF_DIR = os.path.join(galaxy_directory(), "lib/tool_shed/test/test_data/repos/wrong_data_ref")


def test_validate_valid_tool():
Expand Down Expand Up @@ -64,6 +66,22 @@ def test_validate_tool_without_index():
assert not tool.params_with_missing_index_file


def test_validate_missing_data_ref():
repo_dir = MISSING_DATA_REF_DIR
with get_tool_validator() as tv:
full_path = os.path.join(repo_dir, "missing_data_ref.xml")
tool, valid, message = tv.load_tool_from_config(repository_id=None, full_path=full_path)
assert valid is False


def test_validate_wrong_data_ref():
repo_dir = WRONG_DATA_REF_DIR
with get_tool_validator() as tv:
full_path = os.path.join(repo_dir, "wrong_data_ref.xml")
tool, valid, message = tv.load_tool_from_config(repository_id=None, full_path=full_path)
assert valid is True


@contextmanager
def get_tool_validator():
app = MockApp()
Expand Down

0 comments on commit d040bfb

Please sign in to comment.