mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Merge pull request #11043 from bernt-matthias/topic/validator-negate
Add `negate` attribute to validators .. and tests for all
This commit is contained in:
@@ -19,12 +19,12 @@ FILTER_TYPES = [
|
||||
|
||||
ATTRIB_VALIDATOR_COMPATIBILITY = {
|
||||
"check": ["metadata"],
|
||||
"expression": ["regex"],
|
||||
"expression": ["regex", "substitute_value_in_message"],
|
||||
"table_name": ["dataset_metadata_in_data_table", "dataset_metadata_not_in_data_table", "value_in_data_table", "value_not_in_data_table"],
|
||||
"filename": ["dataset_metadata_in_file"],
|
||||
"metadata_name": ["dataset_metadata_in_data_table", "dataset_metadata_not_in_data_table", "dataset_metadata_in_file"],
|
||||
"metadata_column": ["dataset_metadata_in_data_table", "dataset_metadata_not_in_data_table", "value_in_data_table", "value_not_in_data_table", "dataset_metadata_in_file options"],
|
||||
"line_startswith": ["dataset_metadata_in_file", "dataset_metadata_in_data_table", "dataset_metadata_not_in_data_table", "value_in_data_table", "value_not_in_data_table"],
|
||||
"line_startswith": ["dataset_metadata_in_file"],
|
||||
"min": ["in_range", "length"],
|
||||
"max": ["in_range", "length"],
|
||||
"exclude_min": ["in_range"],
|
||||
|
||||
@@ -3726,10 +3726,14 @@ parameters a ``metadata`` validator is added automatically.
|
||||
- ``dataset_ok_validator``: Check if the data set is in state OK.
|
||||
- ``dataset_metadata_in_range``: Check if a numeric metadata value is within
|
||||
a given range.
|
||||
- ``dataset_metadata_in_file``: Check if a metadata value is contained in a
|
||||
specific column of another data set.
|
||||
- ``dataset_metadata_in_data_table`` (``dataset_metadata_not_in_data_table``):
|
||||
Check if a metadata value is contained in a column of a data table.
|
||||
- ``dataset_metadata_in_data_table``: Check if a metadata value is contained in a column of a data table.
|
||||
- ``dataset_metadata_not_in_data_table``: Equivalent to ``dataset_metadata_in_data_table`` with ``negate="true"``.
|
||||
|
||||
Deprecated data validators:
|
||||
|
||||
- ``dataset_metadata_in_file``: Use data tables with ``dataset_metadata_in_data_table``.
|
||||
Check if a metadata value is contained in a specific column of a file in the ``tool_data_path``
|
||||
(which is set in Galaxy's config).
|
||||
|
||||
### Validators for textual inputs (``text``, ``select``, ...)
|
||||
|
||||
@@ -3749,8 +3753,9 @@ For ``text`` inputs the following validators are useful:
|
||||
|
||||
- ``length``: Check if the length of the value is within a range.
|
||||
- ``empty_field``: Check if the string is not empty
|
||||
- ``value_in_data_table`` (``value_not_in_data_table``): Check if the value is
|
||||
- ``value_in_data_table``: Check if the value is
|
||||
contained in a column of a given data table.
|
||||
- ``value_not_in_data_table``: Equivalent to ``value_in_data_table`` with ``negate="true"``.
|
||||
|
||||
### Validators for numeric inputs (``integer``, ``float``)
|
||||
|
||||
@@ -3808,21 +3813,29 @@ use in filenames may not contain ``..``.
|
||||
<xs:extension base="xs:string">
|
||||
<xs:attribute name="type" type="ValidatorType" use="required">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en"><.
|
||||
Valid values include: ``expression``, ``regex``, ``in_range``, ``length``,
|
||||
<xs:documentation xml:lang="en"><![CDATA[
|
||||
Valid values are: ``expression``, ``regex``, ``in_range``, ``length``,
|
||||
``metadata``, ``unspecified_build``, ``no_options``, ``empty_field``,
|
||||
``dataset_metadata_in_file``,
|
||||
``dataset_metadata_in_data_table``, ``dataset_metadata_not_in_data_table``,
|
||||
``value_in_data_table``, ``value_not_in_data_table``,
|
||||
``dataset_ok_validator``, ``dataset_metadata_in_range``]]></xs:documentation>
|
||||
``dataset_ok_validator``, ``dataset_metadata_in_range``.
|
||||
Deprecated validator: ``dataset_metadata_in_file``.
|
||||
The list of supported
|
||||
validators is in the ``validator_types`` dictionary in
|
||||
[/lib/galaxy/tools/parameters/validation.py](https://github.com/galaxyproject/galaxy/blob/dev/lib/galaxy/tools/parameters/validation.py).
|
||||
]]></xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="message" type="xs:string">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">
|
||||
The error message displayed on the tool form if validation fails.</xs:documentation>
|
||||
The error message displayed on the tool form if validation fails. A placeholder string ``%s`` will be repaced by the ``value``</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="negate" type="xs:boolean" default="false">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">
|
||||
Negates the result of the validator.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="check" type="xs:string">
|
||||
@@ -3844,7 +3857,7 @@ more information.</xs:documentation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="filename" type="xs:string">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Tool data filename to check against
|
||||
<xs:documentation xml:lang="en">Deprecated: use ``dataset_metadata_in_data_table``. Tool data filename to check against
|
||||
if ``type`` is ``dataset_metadata_in_file``. File should be present Galaxy's
|
||||
``tool-data`` directory.</xs:documentation>
|
||||
</xs:annotation>
|
||||
@@ -3862,13 +3875,6 @@ in ``dataset_metadata_in_data_table``, ``dataset_metadata_not_in_data_table``, `
|
||||
This can be an integer index to the column or a column name.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="line_startswith" type="xs:string">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Used to indicate lines in the file
|
||||
being used for validation start with a this attribute value.
|
||||
For use with validators of type ``dataset_metadata_in_file``, ``dataset_metadata_in_data_table``, ``dataset_metadata_not_in_data_table``, ``value_in_data_table``, ``value_not_in_data_tabl``</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="min" type="xs:decimal">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">When the ``type`` attribute value is
|
||||
@@ -3908,6 +3914,18 @@ fields to skip if type is ``metadata``. If not specified, all non-optional
|
||||
metadata fields will be checked unless ``check`` attribute is specified.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="line_startswith" type="xs:string">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Deprecated. Used to indicate lines in the file
|
||||
being used for validation start with a this attribute value.
|
||||
For use with validator ``dataset_metadata_in_file``</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="substitute_value_in_message" type="xs:string">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Deprecated. This is now always done.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
|
||||
@@ -586,6 +586,9 @@ class DynamicOptions:
|
||||
@property
|
||||
def tool_data_table(self):
|
||||
if self.tool_data_table_name:
|
||||
# this is needed for the validator unit tests and should not happen in real life
|
||||
if self.tool_param.tool is None:
|
||||
return None
|
||||
tool_data_table = self.tool_param.tool.app.tool_data_tables.get(self.tool_data_table_name, None)
|
||||
if tool_data_table:
|
||||
# Column definitions are optional, but if provided override those from the table
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../test-data/1.tabular
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../test-data/empty.txt
|
||||
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -ex
|
||||
|
||||
# Don't display the pip progress bar when running under CI
|
||||
[ "$CI" = 'true' ] && export PIP_PROGRESS_BAR=off
|
||||
|
||||
@@ -136,6 +136,9 @@
|
||||
<tool file="validation_sanitizer.xml" />
|
||||
<tool file="validation_repeat.xml" />
|
||||
<tool file="validation_metadata_in_range.xml"/>
|
||||
<tool file="validation_metadata_in_datatable.xml"/>
|
||||
<tool file="validation_metadata_in_file.xml"/>
|
||||
<tool file="validation_value_in_datatable.xml"/>
|
||||
<tool file="empty_output.xml" />
|
||||
<tool file="validation_empty_dataset.xml" />
|
||||
<tool file="implicit_conversion.xml" />
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<tool id="validation_dataset_metadata_in_file" name="validation_dataset_metadata_in_file" profile="21.09" version="0.1">
|
||||
<command><![CDATA[
|
||||
echo 'Hello World' > out1
|
||||
]]></command>
|
||||
<inputs>
|
||||
<!-- test dataset_metadata_in_file validator with and without negation
|
||||
the test also uses the data table fasta_indexes.loc, but it could be any file in the tool data dir -->
|
||||
<param name="value" type="data" format="data">
|
||||
<validator type="dataset_metadata_in_file" filename="fasta_indexes.loc" metadata_name="dbkey" metadata_column="1"/>
|
||||
</param>
|
||||
<param name="value_neg" type="data" format="data">
|
||||
<validator type="dataset_metadata_in_file" filename="fasta_indexes.loc" line_startswith="h" metadata_name="dbkey" metadata_column="1" negate="true"/>
|
||||
</param>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<data name="out_file1" format="txt" from_work_dir="out1"/>
|
||||
</outputs>
|
||||
<tests>
|
||||
<!-- hg19 is in the file and hg38 isn't -->
|
||||
<test expect_failure="false">
|
||||
<param name="value" value="1.fasta" dbkey="hg19"/>
|
||||
<param name="value_neg" value="2.fasta" dbkey="hg38"/>
|
||||
</test>
|
||||
<test expect_failure="true">
|
||||
<param name="value" value="1.fasta" dbkey="hg38"/>
|
||||
<param name="value_neg" value="2.fasta" dbkey="hg19"/>
|
||||
</test>
|
||||
</tests>
|
||||
<help>
|
||||
</help>
|
||||
</tool>
|
||||
@@ -0,0 +1,37 @@
|
||||
<tool id="validation_metadata_in_datatable" name="validation_metadata_in_datatable" profile="21.09" version="0.1">
|
||||
<command><![CDATA[
|
||||
echo 'Hello World' > out1
|
||||
]]></command>
|
||||
<inputs>
|
||||
<!-- test dataset_metadata_in_data_table validator with and without negation
|
||||
we simply use dbkey as metadata field here -->
|
||||
<param name="value" type="data" format="data">
|
||||
<validator type="dataset_metadata_in_data_table" table_name="test_fasta_indexes" metadata_column="1" metadata_name="dbkey"/>
|
||||
</param>
|
||||
<param name="value_neg" type="data" format="data">
|
||||
<validator type="dataset_metadata_in_data_table" table_name="test_fasta_indexes" metadata_column="1" metadata_name="dbkey" negate="true"/>
|
||||
</param>
|
||||
<!-- also test deprecated dataset_metadata_not_in_data_table validator-->
|
||||
<param name="value_neg_deprecated" type="data" format="data">
|
||||
<validator type="dataset_metadata_not_in_data_table" table_name="test_fasta_indexes" metadata_column="1" metadata_name="dbkey"/>
|
||||
</param>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<data name="out_file1" format="txt" from_work_dir="out1"/>
|
||||
</outputs>
|
||||
<tests>
|
||||
<!-- hg19 is in the test data table and hg38 not-->
|
||||
<test expect_failure="false">
|
||||
<param name="value" value="1.fasta" dbkey="hg19"/>
|
||||
<param name="value_neg" value="2.fasta" dbkey="hg38"/>
|
||||
<param name="value_neg_deprecated" value="3.bed" dbkey="hg38"/>
|
||||
</test>
|
||||
<test expect_failure="true">
|
||||
<param name="value" value="1.fasta" dbkey="hg38"/> <!-- hg38 is not in the test data table-->
|
||||
<param name="value_neg" value="2.fasta" dbkey="hg19"/>
|
||||
<param name="value_neg_deprecated" value="3.bed" dbkey="hg19"/>
|
||||
</test>
|
||||
</tests>
|
||||
<help>
|
||||
</help>
|
||||
</tool>
|
||||
@@ -0,0 +1,35 @@
|
||||
<tool id="validation_value_in_datatable" name="validation_value_in_datatable" profile="21.09" version="0.1">
|
||||
<command><![CDATA[
|
||||
echo 'Hello World' > out1
|
||||
]]></command>
|
||||
<inputs>
|
||||
<!-- test value_in_data_table validator with and without negation-->
|
||||
<param name="value" type="text">
|
||||
<validator type="value_in_data_table" table_name="test_fasta_indexes" metadata_column="1"/>
|
||||
</param>
|
||||
<param name="value_neg" type="text">
|
||||
<validator type="value_in_data_table" table_name="test_fasta_indexes" metadata_column="1" negate="true"/>
|
||||
</param>
|
||||
<!-- also test deprecated value_not_in_data_table validator-->
|
||||
<param name="value_neg_deprecated" type="text">
|
||||
<validator type="value_not_in_data_table" table_name="test_fasta_indexes" metadata_column="1"/>
|
||||
</param>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<data name="out_file1" format="txt" from_work_dir="out1"/>
|
||||
</outputs>
|
||||
<tests>
|
||||
<test expect_failure="false">
|
||||
<param name="value" value="hg19"/>
|
||||
<param name="value_neg" value="wrongvalue"/>
|
||||
<param name="value_neg_deprecated" value="wrongvalue"/>
|
||||
</test>
|
||||
<test expect_failure="true">
|
||||
<param name="value" value="wrongvalue"/>
|
||||
<param name="value_neg" value="hg19"/>
|
||||
<param name="value_deprecated" value="hg19"/>
|
||||
</test>
|
||||
</tests>
|
||||
<help>
|
||||
</help>
|
||||
</tool>
|
||||
Reference in New Issue
Block a user