@@ -1585,6 +1585,57 @@ def __getitem__(self, idx):
15851585 )
15861586
15871587
1588+ def test_joint_dataset_rejects_overlay_metadata_mismatch ():
1589+ """JointDataset should reject matching keys with conflicting metadata."""
1590+
1591+ class DummyDataset :
1592+ data_types = {"index" : "scalar" }
1593+
1594+ def __init__ (self , overlay_methods ):
1595+ self .overlay_methods = overlay_methods
1596+
1597+ def __len__ (self ):
1598+ return 1
1599+
1600+ def __getitem__ (self , idx ):
1601+ return {"index" : idx }
1602+
1603+ with pytest .raises (ValueError , match = "overlay mismatch" ):
1604+ joint_dataset_module .JointDataset (
1605+ primary = DummyDataset ({"index" : "cat" }),
1606+ secondary = DummyDataset ({"index" : "first" }),
1607+ )
1608+
1609+
1610+ def test_joint_dataset_rejects_empty_sources ():
1611+ """JointDataset should require both primary and secondary samples."""
1612+
1613+ class DummyDataset :
1614+ data_types = {"index" : "scalar" }
1615+ overlay_methods = {"index" : "cat" }
1616+
1617+ def __init__ (self , size ):
1618+ self .size = size
1619+
1620+ def __len__ (self ):
1621+ return self .size
1622+
1623+ def __getitem__ (self , idx ):
1624+ return {"index" : idx }
1625+
1626+ with pytest .raises (ValueError , match = "primary dataset must expose" ):
1627+ joint_dataset_module .JointDataset (
1628+ primary = DummyDataset (0 ),
1629+ secondary = DummyDataset (1 ),
1630+ )
1631+
1632+ with pytest .raises (ValueError , match = "secondary dataset must expose" ):
1633+ joint_dataset_module .JointDataset (
1634+ primary = DummyDataset (1 ),
1635+ secondary = DummyDataset (0 ),
1636+ )
1637+
1638+
15881639def test_joint_dataset_accepts_explicit_pair_index ():
15891640 """Pair indexes should let an external sampler own secondary pairing."""
15901641
@@ -1611,6 +1662,34 @@ def __getitem__(self, idx):
16111662 assert dataset [(1 , None )]["index" ] == 1
16121663
16131664
1665+ def test_joint_dataset_rejects_bad_pair_indexes ():
1666+ """JointDataset should validate tuple shape and secondary bounds."""
1667+
1668+ class DummyDataset :
1669+ data_types = {"index" : "scalar" }
1670+ overlay_methods = {"index" : "cat" }
1671+
1672+ def __init__ (self , indexes ):
1673+ self .indexes = indexes
1674+
1675+ def __len__ (self ):
1676+ return len (self .indexes )
1677+
1678+ def __getitem__ (self , idx ):
1679+ return {"index" : self .indexes [idx ]}
1680+
1681+ dataset = joint_dataset_module .JointDataset (
1682+ primary = DummyDataset ([0 , 1 ]),
1683+ secondary = DummyDataset ([10 ]),
1684+ )
1685+
1686+ with pytest .raises (ValueError , match = "length 2" ):
1687+ dataset [(0 , 1 , 2 )]
1688+
1689+ with pytest .raises (ValueError , match = "outside of bounds" ):
1690+ dataset [(0 , 4 )]
1691+
1692+
16141693def test_joint_dataset_merges_shared_dataset_config (monkeypatch ):
16151694 """Shared dataset config should let source blocks override only paths."""
16161695
@@ -1675,6 +1754,48 @@ def build_dataset(source, dtype):
16751754 ]
16761755
16771756
1757+ def test_joint_dataset_resolve_source_config_rejects_string_base ():
1758+ """A string base cannot be merged into mapping source overrides."""
1759+ with pytest .raises (ValueError , match = "shared `base`" ):
1760+ joint_dataset_module .JointDataset .resolve_source_config (
1761+ "hdf5" , {"file_keys" : "input.h5" }
1762+ )
1763+
1764+
1765+ def test_joint_dataset_build_dataset_uses_factory (monkeypatch ):
1766+ """Mapping-based source configs should instantiate through dataset_factory."""
1767+
1768+ class DummyDataset :
1769+ data_types = {"index" : "scalar" }
1770+ overlay_methods = {"index" : "cat" }
1771+
1772+ def __len__ (self ):
1773+ return 1
1774+
1775+ def __getitem__ (self , idx ):
1776+ return {"index" : idx }
1777+
1778+ calls = []
1779+
1780+ def fake_dataset_factory (source , entry_list = None , dtype = None ):
1781+ calls .append ((source , entry_list , dtype ))
1782+ return DummyDataset ()
1783+
1784+ monkeypatch .setattr ("spine.io.factories.dataset_factory" , fake_dataset_factory )
1785+
1786+ dataset = joint_dataset_module .JointDataset (
1787+ primary = {"name" : "hdf5" , "file_keys" : "a.h5" },
1788+ secondary = {"name" : "hdf5" , "file_keys" : "b.h5" },
1789+ dtype = "float32" ,
1790+ )
1791+
1792+ assert len (dataset ) == 1
1793+ assert calls == [
1794+ ({"name" : "hdf5" , "file_keys" : "a.h5" }, None , "float32" ),
1795+ ({"name" : "hdf5" , "file_keys" : "b.h5" }, None , "float32" ),
1796+ ]
1797+
1798+
16781799def test_larcv_dataset_uses_augmenter_and_length (monkeypatch ):
16791800 """The LArCV dataset should initialize and apply the configured augmenter."""
16801801 seen = {}
0 commit comments