mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-21 13:50:20 +08:00
Merge pull request #1808 from jmchilton/empty_dataset
Implement dataset empty input validator.
This commit is contained in:
@@ -229,6 +229,23 @@ class DatasetOkValidator( Validator ):
|
||||
raise ValueError( self.message )
|
||||
|
||||
|
||||
class DatasetEmptyValidator( Validator ):
|
||||
"""Validator that checks if a dataset has a positive file size."""
|
||||
def __init__( self, message=None ):
|
||||
self.message = message
|
||||
|
||||
@classmethod
|
||||
def from_element( cls, param, elem ):
|
||||
return cls( elem.get( 'message', None ) )
|
||||
|
||||
def validate( self, value, trans=None ):
|
||||
if value:
|
||||
if value.get_size() == 0:
|
||||
if self.message is None:
|
||||
self.message = "The selected dataset is empty, this tool expects non-empty files."
|
||||
raise ValueError( self.message )
|
||||
|
||||
|
||||
class MetadataValidator( Validator ):
|
||||
"""
|
||||
Validator that checks for missing metadata
|
||||
@@ -416,9 +433,10 @@ validator_types = dict( expression=ExpressionValidator,
|
||||
unspecified_build=UnspecifiedBuildValidator,
|
||||
no_options=NoOptionsValidator,
|
||||
empty_field=EmptyTextfieldValidator,
|
||||
empty_dataset=DatasetEmptyValidator,
|
||||
dataset_metadata_in_file=MetadataInFileColumnValidator,
|
||||
dataset_metadata_in_data_table=MetadataInDataTableColumnValidator,
|
||||
dataset_ok_validator=DatasetOkValidator )
|
||||
dataset_ok_validator=DatasetOkValidator, )
|
||||
|
||||
|
||||
def get_suite():
|
||||
|
||||
@@ -237,6 +237,20 @@ class ToolsTestCase( api.ApiTestCase ):
|
||||
response = self._run( "validation_default", history_id, inputs )
|
||||
self._assert_status_code_is( response, 400 )
|
||||
|
||||
@skip_without_tool( "validation_empty_dataset" )
|
||||
def test_validation_empty_dataset( self ):
|
||||
history_id = self.dataset_populator.new_history()
|
||||
inputs = {
|
||||
}
|
||||
outputs = self._run_and_get_outputs( 'empty_output', history_id, inputs )
|
||||
empty_dataset = outputs[0]
|
||||
inputs = {
|
||||
'input1': dataset_to_param(empty_dataset),
|
||||
}
|
||||
self.dataset_populator.wait_for_history( history_id, assert_ok=True )
|
||||
response = self._run( "validation_empty_dataset", history_id, inputs )
|
||||
self._assert_status_code_is( response, 400 )
|
||||
|
||||
@skip_without_tool( "validation_repeat" )
|
||||
def test_validation_in_repeat( self ):
|
||||
history_id = self.dataset_populator.new_history()
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<tool id="empty_output" name="empty_output" version="1.0.0">
|
||||
<command>
|
||||
touch $out_file1;
|
||||
</command>
|
||||
<inputs>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<data name="out_file1" format="txt" />
|
||||
</outputs>
|
||||
<tests>
|
||||
</tests>
|
||||
</tool>
|
||||
@@ -55,6 +55,8 @@
|
||||
<tool file="validation_default.xml" />
|
||||
<tool file="validation_sanitizer.xml" />
|
||||
<tool file="validation_repeat.xml" />
|
||||
<tool file="empty_output.xml" />
|
||||
<tool file="validation_empty_dataset.xml" />
|
||||
<tool file="identifier_single.xml" />
|
||||
<tool file="identifier_multiple.xml" />
|
||||
<tool file="tool_directory.xml" />
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<tool id="validation_empty_dataset" name="validation_empty_dataset">
|
||||
<command>
|
||||
echo "Hello World" > out1;
|
||||
</command>
|
||||
<inputs>
|
||||
<param name="input1" type="data" label="non-empty input">
|
||||
<validator type="empty_dataset" />
|
||||
</param>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<data name="out_file1" from_work_dir="out1" />
|
||||
</outputs>
|
||||
<tests>
|
||||
</tests>
|
||||
<help>
|
||||
</help>
|
||||
</tool>
|
||||
Reference in New Issue
Block a user