From 3b8d0a68ae13027387b3eb3b18cfeb404f4fceec Mon Sep 17 00:00:00 2001 From: Tom Mitchell Date: Wed, 16 Sep 2020 10:14:17 -0400 Subject: [PATCH 1/2] Fix VariableComponent and add unit tests --- sbol2/__init__.py | 2 +- test/test_combderiv.py | 48 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 test/test_combderiv.py diff --git a/sbol2/__init__.py b/sbol2/__init__.py index 8b924b6..e4545b6 100644 --- a/sbol2/__init__.py +++ b/sbol2/__init__.py @@ -10,7 +10,7 @@ # symbols are also exported. from .attachment import Attachment from .collection import Collection -from .combinatorialderivation import CombinatorialDerivation +from .combinatorialderivation import CombinatorialDerivation, VariableComponent from .component import Component from .component import FunctionalComponent from .componentdefinition import ComponentDefinition diff --git a/test/test_combderiv.py b/test/test_combderiv.py new file mode 100644 index 0000000..9b3ccf6 --- /dev/null +++ b/test/test_combderiv.py @@ -0,0 +1,48 @@ +import os +import posixpath +import unittest + +import sbol2 + +MODULE_LOCATION = os.path.dirname(os.path.abspath(__file__)) +SBOL_TEST_SUITE = os.path.join(MODULE_LOCATION, 'SBOLTestSuite') + + +class MyTestCase(unittest.TestCase): + + def test_exported(self): + self.assertIn('CombinatorialDerivation', dir(sbol2)) + self.assertIn('VariableComponent', dir(sbol2)) + + def test_read(self): + fname = os.path.join(SBOL_TEST_SUITE, + 'SBOL2_ic/gfp_reporter_template.xml') + doc = sbol2.Document(fname) + uri = 'http://michael.zhang/GFP_Reporter_Template_CombinatorialDerivation' + cd: sbol2.CombinatorialDerivation = doc.find(uri) + self.assertIsNotNone(cd) + self.assertEqual(1, len(cd.variableComponents)) + vc_uri = posixpath.join(uri, 'CDS_Component_VariableComponent') + vc: sbol2.VariableComponent = doc.find(vc_uri) + self.assertEqual(vc.identity, cd.variableComponents[0].identity) + self.assertIsInstance(vc, sbol2.VariableComponent) + self.assertEqual(3, len(vc.variants)) + + def test_read2(self): + fname = os.path.join(SBOL_TEST_SUITE, + 'SBOL2_ic/eukaryotic_transcriptional_unit.xml') + doc = sbol2.Document(fname) + uri = posixpath.join('http://michael.zhang', + 'Eukaryotic_Transcriptional_Unit_CombinatorialDerivation') + cd: sbol2.CombinatorialDerivation = doc.find(uri) + self.assertIsNotNone(cd) + self.assertEqual(2, len(cd.variableComponents)) + vc_uri = posixpath.join(uri, 'Pro_Component_VariableComponent') + vc: sbol2.VariableComponent = doc.find(vc_uri) + self.assertIsNotNone(vc) + self.assertIsInstance(vc, sbol2.VariableComponent) + self.assertEqual(1, len(vc.variantDerivations)) + + +if __name__ == '__main__': + unittest.main() From 287d6a7dc2211f967e4474f40a919ea6e1134b1f Mon Sep 17 00:00:00 2001 From: Tom Mitchell Date: Wed, 16 Sep 2020 10:15:03 -0400 Subject: [PATCH 2/2] Anticipate service unavailable on a unit test We're using resources outside our control and sometimes they are not available. Anticipate that and do not fail the unit test as a result. --- test/test_partshop.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/test_partshop.py b/test/test_partshop.py index 5f32f8c..7a582cf 100644 --- a/test/test_partshop.py +++ b/test/test_partshop.py @@ -160,7 +160,13 @@ def test_submit(self): doc.name = "SBOL Test Collection" doc.description = "A scratch collection for automated testing of the sbol." sbh = sbol.PartShop(RESOURCE, SPOOFED_RESOURCE) - sbh.login(username, password) + try: + sbh.login(username, password) + except sbol2.SBOLError as sbol_error: + if sbol_error.error_code() == sbol2.SBOLErrorCode.SBOL_ERROR_BAD_HTTP_REQUEST: + if '503' in sbol_error.what(): + return + raise try: sbh.submit(doc) except Exception: