Skip to content

Commit

Permalink
More dataset collection unit testing...
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Dec 22, 2024
1 parent 826ad87 commit a9cec6c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 8 deletions.
33 changes: 25 additions & 8 deletions test/unit/data/dataset_collections/test_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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",
Expand All @@ -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:
Expand Down
43 changes: 43 additions & 0 deletions test/unit/data/dataset_collections/test_structure.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a9cec6c

Please sign in to comment.