|
3 | 3 |
|
4 | 4 | from galaxy.tool_util_models.parameters import ( |
5 | 5 | build_collection_model_for_type, |
| 6 | + collection_runtime_discriminator, |
6 | 7 | DataCollectionListRuntime, |
7 | 8 | DataCollectionPairedRuntime, |
8 | 9 | DataCollectionRecordRuntime, |
@@ -249,3 +250,26 @@ def test_dynamic_model_json_schema_deeply_nested(): |
249 | 250 | defs = schema.get("$defs", {}) |
250 | 251 | assert len(defs) >= 2 |
251 | 252 | assert any("list_paired" in k for k in defs.keys()) |
| 253 | + |
| 254 | + |
| 255 | +def test_collection_runtime_discriminator_known_types(): |
| 256 | + """Known leaf and nested types route correctly.""" |
| 257 | + assert collection_runtime_discriminator({"collection_type": "list"}) == "list" |
| 258 | + assert collection_runtime_discriminator({"collection_type": "paired"}) == "paired" |
| 259 | + assert collection_runtime_discriminator({"collection_type": "record"}) == "record" |
| 260 | + assert collection_runtime_discriminator({"collection_type": "paired_or_unpaired"}) == "paired_or_unpaired" |
| 261 | + assert collection_runtime_discriminator({"collection_type": "sample_sheet"}) == "sample_sheet" |
| 262 | + assert collection_runtime_discriminator({"collection_type": "list:paired"}) == "nested_list" |
| 263 | + assert collection_runtime_discriminator({"collection_type": "record:paired"}) == "nested_record" |
| 264 | + |
| 265 | + |
| 266 | +def test_collection_runtime_discriminator_rejects_unknown(): |
| 267 | + """Unknown collection_type raises ValueError instead of silently defaulting.""" |
| 268 | + with pytest.raises(ValueError, match="Unknown collection_type"): |
| 269 | + collection_runtime_discriminator({"collection_type": "banana"}) |
| 270 | + |
| 271 | + |
| 272 | +def test_collection_runtime_discriminator_missing_routes_to_list(): |
| 273 | + """Missing/empty collection_type routes to list for Pydantic schema rejection.""" |
| 274 | + assert collection_runtime_discriminator({"collection_type": ""}) == "list" |
| 275 | + assert collection_runtime_discriminator({}) == "list" |
0 commit comments