Skip to content

Commit

Permalink
Merge pull request #388 from tcmitchell/385-variable-component
Browse files Browse the repository at this point in the history
Add variable component unit testing
  • Loading branch information
tcmitchell authored Sep 16, 2020
2 parents 1d8ca79 + 287d6a7 commit a8294fd
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sbol2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions test/test_combderiv.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 7 additions & 1 deletion test/test_partshop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a8294fd

Please sign in to comment.