diff --git a/sbol/interaction.py b/sbol/interaction.py index 39e4aa1..2ec6099 100644 --- a/sbol/interaction.py +++ b/sbol/interaction.py @@ -9,9 +9,9 @@ class Interaction(Identified): - def __init__(self, rdf_type=SBOL_INTERACTION, - uri='example', interaction_type=SBO_INTERACTION): - super().__init__(rdf_type, uri) + def __init__(self, uri='example', interaction_type=SBO_INTERACTION, + *, type_uri=SBOL_INTERACTION): + super().__init__(type_uri, uri) self.functionalComponents = OwnedObject(self, SBOL_FUNCTIONAL_COMPONENTS, FunctionalComponent, diff --git a/sbol/test/__init__.py b/sbol/test/__init__.py index 348be87..6fc7153 100644 --- a/sbol/test/__init__.py +++ b/sbol/test/__init__.py @@ -8,6 +8,7 @@ from .test_error import TestError from .test_identified import TestIdentified from .test_implementation import TestImplementation +from .test_interaction import TestInteraction from .test_config import TestConfig from .test_moduledefinition import TestModuleDefinition from .test_object import TestObject @@ -34,6 +35,7 @@ def runTests(test_list=None): TestError, TestIdentified, TestImplementation, + TestInteraction, TestModuleDefinition, TestObject, TestOwnedObject, diff --git a/sbol/test/test_interaction.py b/sbol/test/test_interaction.py new file mode 100644 index 0000000..b6de07d --- /dev/null +++ b/sbol/test/test_interaction.py @@ -0,0 +1,82 @@ +import unittest + +import rdflib + +import sbol + + +class TestInteraction(unittest.TestCase): + + def __init__(self, *args): + super().__init__(*args) + self.homespace = 'http://example.org' + + def make_identity(self, homespace, name, version, tipe='Interaction'): + uri = '{}/{}/{}/{}' + return uri.format(homespace, tipe, name, version) + + def setUp(self): + # Always reset homespace + sbol.setHomespace(self.homespace) + sbol.Config.setOption('sbol_typed_uris', True) + sbol.Config.setOption('sbol_compliant_uris', True) + + def testEmptyConstructor(self): + # This is the default name in the interaction constructor + name = 'example' + i = sbol.Interaction() + expected_identity = self.make_identity(self.homespace, name, + sbol.VERSION_STRING) + self.assertEqual(i.identity, rdflib.URIRef(expected_identity)) + self.assertEqual(i.displayId, rdflib.Literal(name)) + self.assertEqual(i.version, rdflib.Literal(sbol.VERSION_STRING)) + self.assertEqual(i.rdf_type, sbol.SBOL_INTERACTION) + md = sbol.ModuleDefinition() + md.interactions.add(i) + self.assertEqual(len(md.interactions), 1) + + def test1ArgConstructor(self): + name = 'foo' + i = sbol.Interaction(name) + expected_identity = self.make_identity(self.homespace, name, + sbol.VERSION_STRING) + self.assertEqual(i.identity, rdflib.URIRef(expected_identity)) + self.assertEqual(i.displayId, rdflib.Literal(name)) + self.assertEqual(i.version, rdflib.Literal(sbol.VERSION_STRING)) + self.assertEqual(i.rdf_type, sbol.SBOL_INTERACTION) + md = sbol.ModuleDefinition() + md.interactions.add(i) + self.assertEqual(len(md.interactions), 1) + + def test2ArgConstructor(self): + name = 'foo' + i = sbol.Interaction(name, sbol.SBO_INHIBITION) + expected_identity = self.make_identity(self.homespace, name, + sbol.VERSION_STRING) + self.assertEqual(i.identity, rdflib.URIRef(expected_identity)) + self.assertEqual(i.displayId, rdflib.Literal(name)) + self.assertEqual(i.types, [sbol.SBO_INHIBITION]) + self.assertEqual(i.rdf_type, sbol.SBOL_INTERACTION) + md = sbol.ModuleDefinition() + md.interactions.add(i) + self.assertEqual(len(md.interactions), 1) + + def test3ArgConstructor(self): + name = 'foo' + rdf_type = sbol.SBOL_INTERACTION + '2' + i = sbol.Interaction(name, sbol.SBO_INHIBITION, type_uri=rdf_type) + expected_identity = self.make_identity(self.homespace, name, + sbol.VERSION_STRING, + 'Interaction2') + self.assertEqual(i.identity, rdflib.URIRef(expected_identity)) + self.assertEqual(i.displayId, rdflib.Literal(name)) + self.assertEqual(i.types, [sbol.SBO_INHIBITION]) + self.assertEqual(i.rdf_type, rdf_type) + # Verify that when added to a module definition, this + # interaction is in the list of interactions despite having a + # different rdf_type. That's because the rdf_type is not taken + # into account when adding to the module definition's + # ineractions property. + md = sbol.ModuleDefinition() + md.interactions.add(i) + self.assertEqual(len(md.interactions), 1)