예제 #1
0
 def test_boolean_property(self):
     sbol3.set_namespace('https://github.com/synbiodex/pysbol3')
     c = sbol3.Component('c1', sbol3.SBO_DNA)
     c.boolean_attribute = sbol3.BooleanProperty(c, 'http://example.org#foo',
                                                 0, 1, [])
     c.boolean_attribute = True
     self.assertEqual(type(c.boolean_attribute), bool)
예제 #2
0
 def __init__(self, identity, type_uri=PYSBOL3_CUSTOM_TOP):
     super().__init__(identity, type_uri)
     # Also test the boolean list while we're here
     self.foo_bool = sbol3.BooleanProperty(self, PYSBOL3_CUSTOM_BOOL, 0,
                                           math.inf)
     self.children = sbol3.OwnedObject(self, PYSBOL3_CUSTOM_CHILD, 0,
                                       math.inf)
예제 #3
0
 def test_bounds(self):
     sbol3.set_namespace('https://github.com/synbiodex/pysbol3')
     c = sbol3.Component('c1', sbol3.SBO_DNA)
     c.boolean_attribute = sbol3.BooleanProperty(c, 'http://example.org#foo',
                                                 0, math.inf, [])
     self.assertTrue(hasattr(c.boolean_attribute, '__iter__'))
     with self.assertRaises(TypeError):
         c.boolean_attribute = True
     c.int_attribute = sbol3.IntProperty(c, 'http://example.org#foo',
                                         0, math.inf, [])
     self.assertTrue(hasattr(c.int_attribute, '__iter__'))
     with self.assertRaises(TypeError):
         c.int_attribute = 0
예제 #4
0
        def __init__(self, *args, **kwargs):
            base_kwargs = {
                kw: val
                for kw, val in kwargs.items() if kw not in property_names
            }
            if 'type_uri' not in base_kwargs:
                base_kwargs['type_uri'] = CLASS_URI
            Super.__init__(self, *args, **base_kwargs)
            if 'http://sbols.org/v3#' in superclass_uri and not superclass_uri == SBOL_TOP_LEVEL and not superclass_uri == SBOL_IDENTIFIED:
                if class_is_top_level:
                    self._rdf_types.append(SBOL_TOP_LEVEL)
                else:
                    self._rdf_types.append(SBOL_IDENTIFIED)

            # Initialize associative properties
            for property_uri in associative_properties:
                property_name = property_uri_to_name[property_uri]
                lower_bound, upper_bound = property_cardinalities[property_uri]
                self.__dict__[property_name] = sbol.ReferencedObject(
                    self, property_uri, lower_bound, upper_bound)

            # Initialize compositional properties
            for property_uri in compositional_properties:
                property_name = property_uri_to_name[property_uri]
                lower_bound, upper_bound = property_cardinalities[property_uri]
                self.__dict__[property_name] = sbol.OwnedObject(
                    self, property_uri, lower_bound, upper_bound)

            # Initialize datatype properties
            for property_uri in datatype_properties:
                # TODO: Cache query information outside of constructor
                property_name = property_uri_to_name[property_uri]
                # Get the datatype of this property
                datatypes = property_datatypes[property_uri]
                if len(datatypes) == 0:
                    continue
                if len(datatypes
                       ) > 1:  # This might indicate an error in the ontology
                    raise

                # Get the cardinality of this datatype property
                lower_bound, upper_bound = property_cardinalities[property_uri]
                if datatypes[0] == 'http://www.w3.org/2001/XMLSchema#string':
                    self.__dict__[property_name] = sbol.TextProperty(
                        self, property_uri, lower_bound, upper_bound)
                elif datatypes[
                        0] == 'http://www.w3.org/2001/XMLSchema#integer':
                    self.__dict__[property_name] = sbol.IntProperty(
                        self, property_uri, lower_bound, upper_bound)
                elif datatypes[
                        0] == 'http://www.w3.org/2001/XMLSchema#boolean':
                    self.__dict__[property_name] = sbol.BooleanProperty(
                        self, property_uri, lower_bound, upper_bound)
                elif datatypes[0] == 'http://www.w3.org/2001/XMLSchema#anyURI':
                    self.__dict__[property_name] = sbol.URIProperty(
                        self, property_uri, lower_bound, upper_bound)
                elif datatypes[
                        0] == 'http://www.w3.org/2001/XMLSchema#dateTime':
                    self.__dict__[property_name] = sbol.DateTimeProperty(
                        self, property_uri, lower_bound, upper_bound)

            for kw, val in kwargs.items():
                if kw == 'type_uri':
                    continue
                if kw in self.__dict__:
                    try:
                        self.__dict__[kw].set(val)
                    except:
                        pass