mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-11-02 11:48:57 +08:00
Refactor more tool test verification code into galaxy-lib.
Should enable greater reuse from outside the test framework (e.g. standalone scripts and Planemo).
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user