|
7 | 7 | import json |
8 | 8 |
|
9 | 9 | from pynwb.spec import ( |
10 | | - NWBNamespaceBuilder, |
11 | | - NWBRefSpec, |
12 | | - NWBLinkSpec, |
| 10 | + NWBNamespaceBuilder, |
| 11 | + NWBRefSpec, |
| 12 | + NWBLinkSpec, |
13 | 13 | NWBDtypeSpec, |
14 | | - NWBGroupSpec, |
| 14 | + NWBGroupSpec, |
15 | 15 | NWBDatasetSpec |
16 | 16 | ) |
17 | 17 | from pynwb.testing import TestCase |
@@ -116,3 +116,74 @@ def test_add_dataset(self): |
116 | 116 | self.assertEqual(len(spec.datasets), 1) |
117 | 117 | self.assertEqual(spec.datasets[0].name, 'dataset1') |
118 | 118 | self.assertIsInstance(spec.datasets[0], NWBDatasetSpec) |
| 119 | + |
| 120 | + def test_set_neurodata_type_inc(self): |
| 121 | + # neurodata_type_inc should be set to NWBContainer if not specified and neurodata_type_def is not a base type |
| 122 | + spec = NWBGroupSpec( |
| 123 | + doc='A test group', |
| 124 | + neurodata_type_def='MyCustomType', |
| 125 | + name='Group1', |
| 126 | + ) |
| 127 | + self.assertEqual(spec.neurodata_type_inc, 'NWBContainer') |
| 128 | + |
| 129 | + # neurodata_type_inc should not be set to NWBContainer if neurodata_type_def is a base type |
| 130 | + spec = NWBGroupSpec( |
| 131 | + doc='A test group', |
| 132 | + neurodata_type_def='Container', |
| 133 | + name='Group1', |
| 134 | + ) |
| 135 | + self.assertIsNone(spec.neurodata_type_inc) |
| 136 | + |
| 137 | + # neurodata_type_inc should not be set to NWBContainer if neurodata_type_def is a base type |
| 138 | + spec = NWBGroupSpec( |
| 139 | + doc='A test group', |
| 140 | + neurodata_type_def='NWBContainer', |
| 141 | + name='Group1', |
| 142 | + ) |
| 143 | + self.assertIsNone(spec.neurodata_type_inc) |
| 144 | + |
| 145 | + # neurodata_type_inc should not be set to NWBContainer if it is explicitly specified |
| 146 | + spec = NWBGroupSpec( |
| 147 | + doc='A test group', |
| 148 | + neurodata_type_def='MyCustomType', |
| 149 | + neurodata_type_inc='SomeOtherType', |
| 150 | + name='Group1', |
| 151 | + ) |
| 152 | + self.assertEqual(spec.neurodata_type_inc, 'SomeOtherType') |
| 153 | + |
| 154 | + |
| 155 | +class NWBDatasetSpecTest(TestCase): |
| 156 | + |
| 157 | + def test_set_neurodata_type_inc(self): |
| 158 | + # neurodata_type_inc should be set to NWBData if not specified and neurodata_type_def is not a base type |
| 159 | + spec = NWBDatasetSpec( |
| 160 | + doc='A test dataset', |
| 161 | + neurodata_type_def='MyCustomType', |
| 162 | + name='dataset1', |
| 163 | + ) |
| 164 | + self.assertEqual(spec.neurodata_type_inc, 'NWBData') |
| 165 | + |
| 166 | + # neurodata_type_inc should not be set to NWBData if neurodata_type_def is a base type |
| 167 | + spec = NWBDatasetSpec( |
| 168 | + doc='A test dataset', |
| 169 | + neurodata_type_def='Data', |
| 170 | + name='dataset1', |
| 171 | + ) |
| 172 | + self.assertIsNone(spec.neurodata_type_inc) |
| 173 | + |
| 174 | + # neurodata_type_inc should not be set to NWBDataset if neurodata_type_def is a base type |
| 175 | + spec = NWBDatasetSpec( |
| 176 | + doc='A test dataset', |
| 177 | + neurodata_type_def='NWBData', |
| 178 | + name='dataset1', |
| 179 | + ) |
| 180 | + self.assertIsNone(spec.neurodata_type_inc) |
| 181 | + |
| 182 | + # neurodata_type_inc should not be set to NWBData if it is explicitly specified |
| 183 | + spec = NWBDatasetSpec( |
| 184 | + doc='A test dataset', |
| 185 | + neurodata_type_def='MyCustomType', |
| 186 | + neurodata_type_inc='SomeOtherType', |
| 187 | + name='dataset1', |
| 188 | + ) |
| 189 | + self.assertEqual(spec.neurodata_type_inc, 'SomeOtherType') |
0 commit comments