|
13 | 13 |
|
14 | 14 |
|
15 | 15 | class TestDirectSBOL2SBOL3Conversion(unittest.TestCase): |
16 | | - |
17 | 16 | # TODO: turn on validation |
18 | 17 |
|
19 | 18 | # J23101.xml is not SBOL compliant. Leaving conversions involving it for after the compliant converter is done |
@@ -150,100 +149,119 @@ def test_2to3_collection_conversion(self): |
150 | 149 | ''' |
151 | 150 |
|
152 | 151 | def test_empty_componentDefinition(self): |
153 | | - """Test ability to convert a simple part from SBOL2 to SBOL3""" |
154 | | - # Load an SBOL2 document and check its contents |
155 | | - doc2 = sbol2.Document() |
156 | | - doc2.read(TEST_FILES / 'empty_componentDefinition.xml') |
157 | | - # Convert to SBOL3 and check contents |
158 | | - doc3 = convert2to3(doc2, use_native_converter=True) |
159 | | - self.assertEqual(len(doc3.validate()), 0) |
160 | | - with tempfile.TemporaryDirectory() as tmpdir: |
161 | | - tmp3 = Path(tmpdir) / 'doc3.nt' |
162 | | - doc3.write(tmp3) |
163 | | - self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'empty_componentDefinition.nt'))) |
164 | | - doc2_loop = convert3to2(doc3, True) |
165 | | - # report = doc2.validate() |
166 | | - # self.assertEqual(len(report), 0, f'Validation failed: {report}') |
167 | | - tmp2 = Path(tmpdir) / 'doc2_loop.xml' |
168 | | - doc2_loop.write(tmp2) |
169 | | - self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'empty_componentDefinition.xml'))) |
170 | | - |
171 | | - # Do the same for a file without versioning |
172 | | - doc2 = sbol2.Document() |
173 | | - doc2.read(TEST_FILES / 'empty_componentDefinition_nover.xml') |
174 | | - # Convert to SBOL3 and check contents |
175 | | - doc3 = convert2to3(doc2, use_native_converter=True) |
176 | | - self.assertEqual(len(doc3.validate()), 0) |
177 | | - with tempfile.TemporaryDirectory() as tmpdir: |
178 | | - tmp3 = Path(tmpdir) / 'doc3.nt' |
179 | | - doc3.write(tmp3) |
180 | | - self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'empty_componentDefinition_nover.nt'))) |
181 | | - doc2_loop = convert3to2(doc3, True) |
182 | | - # report = doc2.validate() |
183 | | - # self.assertEqual(len(report), 0, f'Validation failed: {report}') |
184 | | - tmp2 = Path(tmpdir) / 'doc2_loop.xml' |
185 | | - doc2_loop.write(tmp2) |
186 | | - self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'empty_componentDefinition_nover.xml'))) |
187 | | - |
| 152 | + """Test ability to convert a simple part from SBOL2 to SBOL3""" |
| 153 | + # Load an SBOL2 document and check its contents |
| 154 | + doc2 = sbol2.Document() |
| 155 | + doc2.read(TEST_FILES / 'empty_componentDefinition.xml') |
| 156 | + # Convert to SBOL3 and check contents |
| 157 | + doc3 = convert2to3(doc2, use_native_converter=True) |
| 158 | + self.assertEqual(len(doc3.validate()), 0) |
| 159 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 160 | + tmp3 = Path(tmpdir) / 'doc3.nt' |
| 161 | + doc3.write(tmp3) |
| 162 | + self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'empty_componentDefinition.nt'))) |
| 163 | + doc2_loop = convert3to2(doc3, True) |
| 164 | + # report = doc2.validate() |
| 165 | + # self.assertEqual(len(report), 0, f'Validation failed: {report}') |
| 166 | + tmp2 = Path(tmpdir) / 'doc2_loop.xml' |
| 167 | + doc2_loop.write(tmp2) |
| 168 | + self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'empty_componentDefinition.xml'))) |
| 169 | + |
| 170 | + # Do the same for a file without versioning |
| 171 | + doc2 = sbol2.Document() |
| 172 | + doc2.read(TEST_FILES / 'empty_componentDefinition_nover.xml') |
| 173 | + # Convert to SBOL3 and check contents |
| 174 | + doc3 = convert2to3(doc2, use_native_converter=True) |
| 175 | + self.assertEqual(len(doc3.validate()), 0) |
| 176 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 177 | + tmp3 = Path(tmpdir) / 'doc3.nt' |
| 178 | + doc3.write(tmp3) |
| 179 | + self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'empty_componentDefinition_nover.nt'))) |
| 180 | + doc2_loop = convert3to2(doc3, True) |
| 181 | + # report = doc2.validate() |
| 182 | + # self.assertEqual(len(report), 0, f'Validation failed: {report}') |
| 183 | + tmp2 = Path(tmpdir) / 'doc2_loop.xml' |
| 184 | + doc2_loop.write(tmp2) |
| 185 | + self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'empty_componentDefinition_nover.xml'))) |
| 186 | + |
188 | 187 | def test_minimal_sbol2_collection(self): |
189 | | - """Test ability to convert a collection of simple parts from SBOL2 to SBOL3""" |
190 | | - # Depends on working Component Definition conversion |
191 | | - # Load an SBOL2 document and check its contents |
192 | | - doc2 = sbol2.Document() |
193 | | - doc2.read(TEST_FILES / 'minimal_sbol2_collection.xml') |
194 | | - # Convert to SBOL3 and check contents |
195 | | - doc3 = convert2to3(doc2, use_native_converter=True) |
196 | | - self.assertEqual(len(doc3.validate()), 0) |
197 | | - with tempfile.TemporaryDirectory() as tmpdir: |
198 | | - tmp3 = Path(tmpdir) / 'doc3.nt' |
199 | | - doc3.write(tmp3) |
200 | | - self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'minimal_sbol2_collection.nt'))) |
201 | | - doc2_loop = convert3to2(doc3, True) |
202 | | - # report = doc2.validate() |
203 | | - # self.assertEqual(len(report), 0, f'Validation failed: {report}') |
204 | | - tmp2 = Path(tmpdir) / 'doc2_loop.xml' |
205 | | - doc2_loop.write(tmp2) |
206 | | - self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'minimal_sbol2_collection.xml'))) |
207 | | - |
208 | | - |
| 188 | + """Test ability to convert a collection of simple parts from SBOL2 to SBOL3""" |
| 189 | + # Depends on working Component Definition conversion |
| 190 | + # Load an SBOL2 document and check its contents |
| 191 | + doc2 = sbol2.Document() |
| 192 | + doc2.read(TEST_FILES / 'minimal_sbol2_collection.xml') |
| 193 | + # Convert to SBOL3 and check contents |
| 194 | + doc3 = convert2to3(doc2, use_native_converter=True) |
| 195 | + self.assertEqual(len(doc3.validate()), 0) |
| 196 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 197 | + tmp3 = Path(tmpdir) / 'doc3.nt' |
| 198 | + doc3.write(tmp3) |
| 199 | + self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'minimal_sbol2_collection.nt'))) |
| 200 | + doc2_loop = convert3to2(doc3, True) |
| 201 | + # report = doc2.validate() |
| 202 | + # self.assertEqual(len(report), 0, f'Validation failed: {report}') |
| 203 | + tmp2 = Path(tmpdir) / 'doc2_loop.xml' |
| 204 | + doc2_loop.write(tmp2) |
| 205 | + self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'minimal_sbol2_collection.xml'))) |
| 206 | + |
209 | 207 | def test_sbol2_implementation(self): |
210 | | - """Test ability to convert an implementation from SBOL2 to SBOL3""" |
211 | | - # Load an SBOL2 document and check its contents |
212 | | - doc2 = sbol2.Document() |
213 | | - doc2.read(TEST_FILES / 'sbol_3to2_implementation_compliant.xml') |
214 | | - # Convert to SBOL3 and check contents |
215 | | - doc3 = convert2to3(doc2, use_native_converter=True) |
216 | | - self.assertEqual(len(doc3.validate()), 0) |
217 | | - with tempfile.TemporaryDirectory() as tmpdir: |
218 | | - tmp3 = Path(tmpdir) / 'doc3.nt' |
219 | | - doc3.write(tmp3) |
220 | | - self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'sbol_3to2_implementation_compliant.nt'))) |
221 | | - doc2_loop = convert3to2(doc3, True) |
222 | | - # report = doc2.validate() |
223 | | - # self.assertEqual(len(report), 0, f'Validation failed: {report}') |
224 | | - tmp2 = Path(tmpdir) / 'doc2_loop.xml' |
225 | | - doc2_loop.write(tmp2) |
226 | | - self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'sbol_3to2_implementation_compliant.xml'))) |
| 208 | + """Test ability to convert an implementation from SBOL2 to SBOL3""" |
| 209 | + # Load an SBOL2 document and check its contents |
| 210 | + doc2 = sbol2.Document() |
| 211 | + doc2.read(TEST_FILES / 'sbol_3to2_implementation_compliant.xml') |
| 212 | + # Convert to SBOL3 and check contents |
| 213 | + doc3 = convert2to3(doc2, use_native_converter=True) |
| 214 | + self.assertEqual(len(doc3.validate()), 0) |
| 215 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 216 | + tmp3 = Path(tmpdir) / 'doc3.nt' |
| 217 | + doc3.write(tmp3) |
| 218 | + self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'sbol_3to2_implementation_compliant.nt'))) |
| 219 | + doc2_loop = convert3to2(doc3, True) |
| 220 | + # report = doc2.validate() |
| 221 | + # self.assertEqual(len(report), 0, f'Validation failed: {report}') |
| 222 | + tmp2 = Path(tmpdir) / 'doc2_loop.xml' |
| 223 | + doc2_loop.write(tmp2) |
| 224 | + self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'sbol_3to2_implementation_compliant.xml'))) |
227 | 225 |
|
228 | 226 | def test_seq_componentDefinition(self): |
229 | | - """Test ability to convert a Component Definition with a Sequence from SBOL2 to SBOL3""" |
230 | | - # Depends on working Component Definition conversion |
231 | | - # Load an SBOL2 document and check its contents |
232 | | - doc2 = sbol2.Document() |
233 | | - doc2.read(TEST_FILES / 'seq_componentDefinition.xml') |
234 | | - # Convert to SBOL3 and check contents |
235 | | - doc3 = convert2to3(doc2, use_native_converter=True) |
236 | | - self.assertEqual(len(doc3.validate()), 0) |
237 | | - with tempfile.TemporaryDirectory() as tmpdir: |
238 | | - tmp3 = Path(tmpdir) / 'doc3.nt' |
239 | | - doc3.write(tmp3) |
240 | | - self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'seq_componentDefinition.nt'))) |
241 | | - doc2_loop = convert3to2(doc3, True) |
242 | | - # report = doc2.validate() |
243 | | - # self.assertEqual(len(report), 0, f'Validation failed: {report}') |
244 | | - tmp2 = Path(tmpdir) / 'doc2_loop.xml' |
245 | | - doc2_loop.write(tmp2) |
246 | | - self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'seq_componentDefinition.xml'))) |
247 | | - |
| 227 | + """Test ability to convert a Component Definition with a Sequence from SBOL2 to SBOL3""" |
| 228 | + # Depends on working Component Definition conversion |
| 229 | + # Load an SBOL2 document and check its contents |
| 230 | + doc2 = sbol2.Document() |
| 231 | + doc2.read(TEST_FILES / 'seq_componentDefinition.xml') |
| 232 | + # Convert to SBOL3 and check contents |
| 233 | + doc3 = convert2to3(doc2, use_native_converter=True) |
| 234 | + self.assertEqual(len(doc3.validate()), 0) |
| 235 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 236 | + tmp3 = Path(tmpdir) / 'doc3.nt' |
| 237 | + doc3.write(tmp3) |
| 238 | + self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'seq_componentDefinition.nt'))) |
| 239 | + doc2_loop = convert3to2(doc3, True) |
| 240 | + # report = doc2.validate() |
| 241 | + # self.assertEqual(len(report), 0, f'Validation failed: {report}') |
| 242 | + tmp2 = Path(tmpdir) / 'doc2_loop.xml' |
| 243 | + doc2_loop.write(tmp2) |
| 244 | + self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'seq_componentDefinition.xml'))) |
| 245 | + |
| 246 | + def test_sequenceConstraint(self): |
| 247 | + """Test ability to convert a SequenceConstraint from SBOL2 to SBOL3""" |
| 248 | + # Load an SBOL2 document and check its contents |
| 249 | + doc2 = sbol2.Document() |
| 250 | + doc2.read(TEST_FILES / 'SequenceConstraintOutput.xml') |
| 251 | + # Convert to SBOL3 and check contents |
| 252 | + doc3 = convert2to3(doc2, use_native_converter=True) |
| 253 | + self.assertEqual(len(doc3.validate()), 0) |
| 254 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 255 | + tmp3 = Path(tmpdir) / 'doc3.nt' |
| 256 | + doc3.write(tmp3) |
| 257 | + self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'SequenceConstraintOutput.nt'))) |
| 258 | + doc2_loop = convert3to2(doc3, True) |
| 259 | + # report = doc2.validate() |
| 260 | + # self.assertEqual(len(report), 0, f'Validation failed: {report}') |
| 261 | + tmp2 = Path(tmpdir) / 'doc2_loop.xml' |
| 262 | + doc2_loop.write(tmp2) |
| 263 | + self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'SequenceConstraintOutput.xml'))) |
| 264 | + |
| 265 | + |
248 | 266 | if __name__ == '__main__': |
249 | 267 | unittest.main() |
0 commit comments