diff --git a/lib/galaxy/tools/verify/__init__.py b/lib/galaxy/tools/verify/__init__.py index 82fbfce9eb4..b3b190c39b4 100644 --- a/lib/galaxy/tools/verify/__init__.py +++ b/lib/galaxy/tools/verify/__init__.py @@ -286,3 +286,58 @@ def files_contains(file1, file2, attributes=None): line_diff_count += 1 if line_diff_count > lines_diff: raise AssertionError("Failed to find '%s' in history data. (lines_diff=%i):\n" % (contains, lines_diff)) + + +# Galaxy specific methods - rest of this can be used with arbitrary files and such. + +def verify_hid(filename, hda_id, attributes, test_data_path_builder, hid="", dataset_fetcher=None, keep_outputs_dir=False): + assert dataset_fetcher is not None + + def verify_extra_files(extra_files): + _verify_extra_files_content(extra_files, hda_id, dataset_fetcher=dataset_fetcher, test_data_path_builder=test_data_path_builder, keep_outputs_dir=keep_outputs_dir) + + data = dataset_fetcher(hda_id) + item_label = "History item %s" % hid + verify( + item_label, + data, + attributes=attributes, + filename=filename, + get_filename=test_data_path_builder, + keep_outputs_dir=keep_outputs_dir, + verify_extra_files=verify_extra_files, + ) + + +def _verify_composite_datatype_file_content(file_name, hda_id, base_name=None, attributes=None, dataset_fetcher=None, test_data_path_builder=None, keep_outputs_dir=False): + assert dataset_fetcher is not None + + data = dataset_fetcher(hda_id, base_name) + item_label = "History item %s" % hda_id + try: + verify( + item_label, + data, + attributes=attributes, + filename=file_name, + get_filename=test_data_path_builder, + keep_outputs_dir=keep_outputs_dir, + ) + except AssertionError as err: + errmsg = 'Composite file (%s) of %s different than expected, difference:\n' % (base_name, item_label) + errmsg += str(err) + raise AssertionError(errmsg) + + +def _verify_extra_files_content(extra_files, hda_id, dataset_fetcher, test_data_path_builder, keep_outputs_dir): + files_list = [] + for extra_type, extra_value, extra_name, extra_attributes in extra_files: + if extra_type == 'file': + files_list.append((extra_name, extra_value, extra_attributes)) + elif extra_type == 'directory': + for filename in os.listdir(test_data_path_builder(extra_value)): + files_list.append((filename, os.path.join(extra_value, filename), extra_attributes)) + else: + raise ValueError('unknown extra_files type: %s' % extra_type) + for filename, filepath, attributes in files_list: + _verify_composite_datatype_file_content(filepath, hda_id, base_name=filename, attributes=attributes, dataset_fetcher=dataset_fetcher, test_data_path_builder=test_data_path_builder, keep_outputs_dir=keep_outputs_dir) diff --git a/test/base/interactor.py b/test/base/interactor.py index 830c9c9c2e0..ac6687cc9ee 100644 --- a/test/base/interactor.py +++ b/test/base/interactor.py @@ -17,6 +17,7 @@ from six import StringIO, text_type from galaxy import util from galaxy.tools.parser.interface import TestCollectionDef +from galaxy.tools.verify import verify_hid from galaxy.util.bunch import Bunch from galaxy.util.odict import odict @@ -58,6 +59,7 @@ class GalaxyInteractorApi(object): self.master_api_key = functional_test_case.master_api_key self.api_key = self.__get_user_key(functional_test_case.user_api_key, functional_test_case.master_api_key, test_user=test_user) self.uploads = {} + self.keep_outputs_dir = functional_test_case.keepOutdir def verify_output(self, history_id, jobs, output_data, output_testdef, tool_id, maxseconds): outfile = output_testdef.outfile @@ -95,12 +97,13 @@ class GalaxyInteractorApi(object): def verify_output_dataset(self, history_id, hda_id, outfile, attributes, tool_id): fetcher = self.__dataset_fetcher(history_id) test_data_path_builder = self.__test_data_path_builder(tool_id) - self.functional_test_case.verify_hid( + verify_hid( outfile, hda_id=hda_id, attributes=attributes, dataset_fetcher=fetcher, test_data_path_builder=test_data_path_builder, + keep_outputs_dir=self.keep_outputs_dir ) self._verify_metadata(history_id, hda_id, attributes) diff --git a/test/base/testcase.py b/test/base/testcase.py index 16c7452920e..d50da350bc7 100644 --- a/test/base/testcase.py +++ b/test/base/testcase.py @@ -5,7 +5,6 @@ import os import time import unittest -from galaxy.tools.verify import verify from galaxy.tools.verify.test_data import TestDataResolver from galaxy.web import security from .driver_util import GalaxyTestDriver @@ -75,54 +74,3 @@ class FunctionalTestCase(unittest.TestCase): message = 'Tool test run exceeded walltime [total %s, max %s], terminating.' % (slept, walltime_exceeded) log.info(message) raise AssertionError(message) - - # TODO: Move verify_xxx into GalaxyInteractor or some relevant mixin. - def verify_hid(self, filename, hda_id, attributes, test_data_path_builder, hid="", dataset_fetcher=None): - assert dataset_fetcher is not None - - def verify_extra_files(extra_files): - self._verify_extra_files_content(extra_files, hda_id, dataset_fetcher=dataset_fetcher, test_data_path_builder=test_data_path_builder) - - data = dataset_fetcher(hda_id) - item_label = "History item %s" % hid - verify( - item_label, - data, - attributes=attributes, - filename=filename, - get_filename=test_data_path_builder, - keep_outputs_dir=self.keepOutdir, - verify_extra_files=verify_extra_files, - ) - - def _verify_composite_datatype_file_content(self, file_name, hda_id, base_name=None, attributes=None, dataset_fetcher=None, test_data_path_builder=None): - assert dataset_fetcher is not None - - data = dataset_fetcher(hda_id, base_name) - item_label = "History item %s" % hda_id - try: - verify( - item_label, - data, - attributes=attributes, - filename=file_name, - get_filename=test_data_path_builder, - keep_outputs_dir=self.keepOutdir, - ) - except AssertionError as err: - errmsg = 'Composite file (%s) of %s different than expected, difference:\n' % (base_name, item_label) - errmsg += str(err) - raise AssertionError(errmsg) - - def _verify_extra_files_content(self, extra_files, hda_id, dataset_fetcher, test_data_path_builder): - files_list = [] - for extra_type, extra_value, extra_name, extra_attributes in extra_files: - if extra_type == 'file': - files_list.append((extra_name, extra_value, extra_attributes)) - elif extra_type == 'directory': - for filename in os.listdir(test_data_path_builder(extra_value)): - files_list.append((filename, os.path.join(extra_value, filename), extra_attributes)) - else: - raise ValueError('unknown extra_files type: %s' % extra_type) - for filename, filepath, attributes in files_list: - self._verify_composite_datatype_file_content(filepath, hda_id, base_name=filename, attributes=attributes, dataset_fetcher=dataset_fetcher, test_data_path_builder=test_data_path_builder)