Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Interaction constructor to put uri first #120

Merged
merged 1 commit into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sbol/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions sbol/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,6 +35,7 @@ def runTests(test_list=None):
TestError,
TestIdentified,
TestImplementation,
TestInteraction,
TestModuleDefinition,
TestObject,
TestOwnedObject,
Expand Down
82 changes: 82 additions & 0 deletions sbol/test/test_interaction.py
Original file line number Diff line number Diff line change
@@ -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)