Skip to content

Commit cb3ec1f

Browse files
committed
Refactor parameter unit testing to be more general.
1 parent 2a7e8e1 commit cb3ec1f

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

lib/galaxy/tool_util/unittest_utils/parameters.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
from galaxy.tool_util.parameters import (
44
from_input_source,
5+
input_models_for_tool_source,
56
ToolParameterBundle,
7+
ToolParameterBundleModel,
68
ToolParameterT,
79
)
8-
from galaxy.tool_util.parser.factory import get_tool_source
10+
from galaxy.tool_util.parser import (
11+
get_tool_source,
12+
ToolSource,
13+
)
914
from galaxy.util import galaxy_directory
1015

1116

@@ -19,22 +24,12 @@ def parameter_bundle(parameter: ToolParameterT) -> ParameterBundle:
1924
return ParameterBundle(parameter)
2025

2126

22-
def parameter_bundle_for_file(filename: str) -> ParameterBundle:
23-
return parameter_bundle(tool_parameter(filename))
24-
25-
26-
def tool_parameter(filename: str) -> ToolParameterT:
27-
return from_input_source(parameter_source(filename))
28-
29-
30-
def parameter_source(filename: str):
27+
def parameter_bundle_for_file(filename: str) -> ToolParameterBundleModel:
3128
tool_source = parameter_tool_source(filename)
32-
input_sources = tool_source.parse_input_pages().page_sources[0].parse_input_sources()
33-
assert len(input_sources) == 1
34-
return input_sources[0]
29+
return input_models_for_tool_source(tool_source)
3530

3631

37-
def parameter_tool_source(basename: str):
32+
def parameter_tool_source(basename: str) -> ToolSource:
3833
path_prefix = os.path.join(galaxy_directory(), "test/functional/tools/parameters", basename)
3934
if os.path.exists(f"{path_prefix}.xml"):
4035
path = f"{path_prefix}.xml"

test/unit/tool_util/test_parameter_specification.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from galaxy.tool_util.unittest_utils.parameters import (
2525
parameter_bundle,
2626
parameter_bundle_for_file,
27-
tool_parameter,
2827
)
2928
from galaxy.util.resources import resource_string
3029

@@ -59,7 +58,7 @@ def test_single():
5958
def _test_file(file: str, specification=None):
6059
spec = specification or specification_object()
6160
combos = spec[file]
62-
tool_parameter_model = tool_parameter(file)
61+
parameter_bundle = parameter_bundle_for_file(file)
6362

6463
assertion_functions = {
6564
"request_valid": _assert_requests_validate,
@@ -74,13 +73,13 @@ def _test_file(file: str, specification=None):
7473

7574
for valid_or_invalid, tests in combos.items():
7675
assertion_function = assertion_functions[valid_or_invalid]
77-
assertion_function(tool_parameter_model, tests)
76+
assertion_function(parameter_bundle, tests)
7877

7978
# Assume request validation will work here.
8079
if "request_internal_valid" not in combos and "request_valid" in combos:
81-
_assert_internal_requests_validate(tool_parameter_model, combos["request_valid"])
80+
_assert_internal_requests_validate(parameter_bundle, combos["request_valid"])
8281
if "request_internal_invalid" not in combos and "request_invalid" in combos:
83-
_assert_internal_requests_invalid(tool_parameter_model, combos["request_invalid"])
82+
_assert_internal_requests_invalid(parameter_bundle, combos["request_invalid"])
8483

8584

8685
def _for_each(test: Callable, parameter: ToolParameterT, requests: List[Dict[str, Any]]) -> None:
@@ -90,31 +89,31 @@ def _for_each(test: Callable, parameter: ToolParameterT, requests: List[Dict[str
9089

9190
def _assert_request_validates(parameter: ToolParameterT, request: Dict[str, Any]) -> None:
9291
try:
93-
validate_request(parameter_bundle(parameter), request)
92+
validate_request(parameter, request)
9493
except RequestParameterInvalidException as e:
9594
raise AssertionError(f"Parameter {parameter} failed to validate request {request}. {e}")
9695

9796

9897
def _assert_request_invalid(parameter, request) -> None:
9998
exc = None
10099
try:
101-
validate_request(parameter_bundle(parameter), request)
100+
validate_request(parameter, request)
102101
except RequestParameterInvalidException as e:
103102
exc = e
104103
assert exc is not None, f"Parameter {parameter} didn't result in validation error on request {request} as expected."
105104

106105

107106
def _assert_internal_request_validates(parameter, request) -> None:
108107
try:
109-
validate_internal_request(parameter_bundle(parameter), request)
108+
validate_internal_request(parameter, request)
110109
except RequestParameterInvalidException as e:
111110
raise AssertionError(f"Parameter {parameter} failed to validate internal request {request}. {e}")
112111

113112

114113
def _assert_internal_request_invalid(parameter, request) -> None:
115114
exc = None
116115
try:
117-
validate_internal_request(parameter_bundle(parameter), request)
116+
validate_internal_request(parameter, request)
118117
except RequestParameterInvalidException as e:
119118
exc = e
120119
assert (
@@ -124,15 +123,15 @@ def _assert_internal_request_invalid(parameter, request) -> None:
124123

125124
def _assert_internal_job_validates(parameter, request) -> None:
126125
try:
127-
validate_internal_job(parameter_bundle(parameter), request)
126+
validate_internal_job(parameter, request)
128127
except RequestParameterInvalidException as e:
129128
raise AssertionError(f"Parameter {parameter} failed to validate internal job description {request}. {e}")
130129

131130

132131
def _assert_internal_job_invalid(parameter, request) -> None:
133132
exc = None
134133
try:
135-
validate_internal_job(parameter_bundle(parameter), request)
134+
validate_internal_job(parameter, request)
136135
except RequestParameterInvalidException as e:
137136
exc = e
138137
assert (
@@ -142,15 +141,15 @@ def _assert_internal_job_invalid(parameter, request) -> None:
142141

143142
def _assert_test_case_validates(parameter, test_case) -> None:
144143
try:
145-
validate_test_case(parameter_bundle(parameter), test_case)
144+
validate_test_case(parameter, test_case)
146145
except RequestParameterInvalidException as e:
147146
raise AssertionError(f"Parameter {parameter} failed to validate test_case {test_case}. {e}")
148147

149148

150149
def _assert_test_case_invalid(parameter, test_case) -> None:
151150
exc = None
152151
try:
153-
validate_test_case(parameter_bundle(parameter), test_case)
152+
validate_test_case(parameter, test_case)
154153
except RequestParameterInvalidException as e:
155154
exc = e
156155
assert (
@@ -213,7 +212,7 @@ def encode_val(val: int) -> str:
213212
parameter_spec = specification_object()
214213
parameter_models_json = {}
215214
for file in parameter_spec.keys():
216-
tool_parameter_model = tool_parameter(file)
215+
tool_parameter_model = parameter_bundle_for_file(file)
217216
parameter_models_json[file] = tool_parameter_model.dict()
218217
yaml_str = yaml.safe_dump(parameter_models_json)
219218
with open("client/src/components/Tool/parameter_models.yml", "w") as f:

0 commit comments

Comments
 (0)