Skip to content

Commit

Permalink
Merge pull request #308 from tcmitchell/307-copy-regression
Browse files Browse the repository at this point in the history
Fix copy regression and add test
  • Loading branch information
tcmitchell authored Sep 16, 2021
2 parents 7fb0890 + efce4e7 commit e5179b9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions .idea/pySBOL3.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 9 additions & 11 deletions sbol3/object.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import posixpath
import uuid
import warnings
from collections import defaultdict
from urllib.parse import urlparse
from typing import Dict, Callable, Optional
from typing import Dict, Callable, Optional, Union

from . import *

Expand All @@ -23,14 +22,14 @@ def __setattr__(self, name, value):
self.__dict__[name].set(value)
except AttributeError:
# Attribute set does not exist
object.__setattr__(self, name, value)
super().__setattr__(name, value)
except KeyError:
# property name does not exist
object.__setattr__(self, name, value)
super().__setattr__(name, value)

def __getattribute__(self, name):
# Call the default method
result = object.__getattribute__(self, name)
result = super().__getattribute__(name)
if hasattr(result, '_sbol_singleton'):
result = result.get()
return result
Expand All @@ -41,7 +40,7 @@ def _is_url(name: str) -> bool:
return bool(parsed.scheme and parsed.netloc and parsed.path)

@staticmethod
def _make_identity(name: str) -> str:
def _make_identity(name: str) -> Union[str, None]:
"""Make an identity from the given name.
If the name is a URL, that can be the identity. Or perhaps it
Expand Down Expand Up @@ -108,18 +107,17 @@ def copy(self, target_doc=None, target_namespace=None):
old_uri = self.identity
new_uri = replace_namespace(old_uri, target_namespace, self.getTypeURI())

new_obj = BUILDER_REGISTER[self.type_uri](identity=new_uri,
type_uri=self.type_uri)
new_obj = BUILDER_REGISTER[self.type_uri](**dict(identity=new_uri,
type_uri=self.type_uri))

# Copy properties
for property_uri, value_store in self._properties.items():
new_obj._properties[property_uri] = value_store.copy()

# TODO:
# Map into new namespace
# TODO: Map into new namespace

# Assign the new object to the target Document
if target_doc:
if target_doc is not None:
try:
target_doc.add(new_obj)
except TypeError:
Expand Down
1 change: 1 addition & 0 deletions test/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_copy_child_objects(self):

doc2 = sbol3.Document()
root_copy = root.copy(target_doc=doc2)
self.assertIn(root_copy, doc2.objects)
self.assertEqual([sc.identity for sc in root.features],
[sc.identity for sc in root_copy.features])

Expand Down

0 comments on commit e5179b9

Please sign in to comment.