diff --git a/test/unit/data/dataset_collections/test_matching.py b/test/unit/data/dataset_collections/test_matching.py index a7bb1985569c..3ea1747d38df 100644 --- a/test/unit/data/dataset_collections/test_matching.py +++ b/test/unit/data/dataset_collections/test_matching.py @@ -17,14 +17,7 @@ def test_lists_of_same_cardinality_match(): def test_nested_lists_match(): - nested_list = list_instance( - elements=[ - pair_element("data1"), - pair_element("data2"), - pair_element("data3"), - ], - collection_type="list:paired", - ) + nested_list = list_paired_instance() assert_can_match(nested_list, nested_list) @@ -86,6 +79,19 @@ def pair_element(element_identifier): return collection_element(element_identifier, pair_instance().collection) +def list_element(element_identifier, list_collection=None): + return collection_element(element_identifier, list_collection or list_instance().collection) + + +def list_of_lists_instance(): + return list_instance( + elements=[ + list_element("outer1"), + list_element("outer2"), + ] + ) + + def pair_instance(): paired_collection_instance = collection_instance( collection_type="paired", @@ -97,6 +103,17 @@ def pair_instance(): return paired_collection_instance +def list_paired_instance(): + return list_instance( + elements=[ + pair_element("data1"), + pair_element("data2"), + pair_element("data3"), + ], + collection_type="list:paired", + ) + + def list_instance(collection_type="list", elements=None, ids=None): if not elements: if ids is None: diff --git a/test/unit/data/dataset_collections/test_structure.py b/test/unit/data/dataset_collections/test_structure.py new file mode 100644 index 000000000000..1c97d353a768 --- /dev/null +++ b/test/unit/data/dataset_collections/test_structure.py @@ -0,0 +1,43 @@ +from galaxy.model.dataset_collections.structure import get_structure +from galaxy.model.dataset_collections.type_description import CollectionTypeDescriptionFactory +from .test_matching import ( + list_of_lists_instance, + list_paired_instance, + pair_instance, +) + +factory = CollectionTypeDescriptionFactory(None) + + +def test_get_structure_simple(): + paired_type_description = factory.for_collection_type("paired") + tree = get_structure(pair_instance(), paired_type_description) + assert len(tree.children) == 2 + assert tree.children[0][0] == "left" # why not forward? + assert tree.children[0][1].is_leaf + + +def test_get_structure_list_paired_over_paired(): + paired_type_description = factory.for_collection_type("list:paired") + tree = get_structure(list_paired_instance(), paired_type_description, "paired") + assert tree.collection_type_description.collection_type == "list" + assert len(tree.children) == 3 + assert tree.children[0][0] == "data1" + assert tree.children[0][1].is_leaf + +def test_get_structure_list_of_lists(): + list_of_lists_type_description = factory.for_collection_type("list:list") + tree = get_structure(list_of_lists_instance(), list_of_lists_type_description) + assert tree.collection_type_description.collection_type == "list:list" + assert len(tree.children) == 2 + assert tree.children[0][0] == "outer1" + assert not tree.children[0][1].is_leaf + + +def test_get_structure_list_of_lists_over_list(): + list_of_lists_type_description = factory.for_collection_type("list:list") + tree = get_structure(list_of_lists_instance(), list_of_lists_type_description, "list") + assert tree.collection_type_description.collection_type == "list" + assert len(tree.children) == 2 + assert tree.children[0][0] == "outer1" + assert tree.children[0][1].is_leaf