diff --git a/cobalt/hierarchical.py b/cobalt/hierarchical.py
index 2c78a7c..c39336f 100644
--- a/cobalt/hierarchical.py
+++ b/cobalt/hierarchical.py
@@ -23,12 +23,6 @@ def empty_document_content(cls, E):
eId="sec_nn_1")
)
- @classmethod
- def empty_document_attrs(cls):
- attrs = super().empty_document_attrs()
- attrs['contains'] = 'originalVersion'
- return attrs
-
@property
def publication_name(self):
""" Name of the publication in which this act was published.
@@ -90,18 +84,24 @@ def amendments(self):
@amendments.setter
def amendments(self, value):
# delete existing entries
- for e in self.meta.iterfind(f'.//{{{self.namespace}}}lifecycle/{{{self.namespace}}}eventRef[@type="amendment"]'):
- # delete the passive ref elements
- eid = e.get('source')[1:]
- for node in self.meta.iterfind(f'.//{{{self.namespace}}}references/{{{self.namespace}}}passiveRef[@eId="{eid}"]'):
- node.getparent().remove(node)
-
- # delete the event
- e.getparent().remove(e)
+ lifecycle = self.meta.find(f'{{{self.namespace}}}lifecycle')
+ if lifecycle is not None:
+ for e in lifecycle.findall(f'./{{{self.namespace}}}eventRef[@type="amendment"]'):
+ # delete the passive ref elements
+ eid = e.get('source')[1:]
+ for node in self.meta.iterfind(f'.//{{{self.namespace}}}references/{{{self.namespace}}}passiveRef[@eId="{eid}"]'):
+ node.getparent().remove(node)
+ # delete the event
+ lifecycle.remove(e)
if not value:
- # no amendments
- self.act.set('contains', 'originalVersion')
+ # no amendments, default is originalVersion so it doesn't need to be set explicitly
+ if 'contains' in self.act.attrib:
+ del self.act.attrib['contains']
+ # lifecycle cannot be empty§
+ if lifecycle is not None and not lifecycle.getchildren():
+ lifecycle.getparent().remove(lifecycle)
+
else:
self.act.set('contains', 'singleVersion')
lifecycle = self._ensure_lifecycle()
diff --git a/tests/test_act.py b/tests/test_act.py
index da810f1..a70d055 100644
--- a/tests/test_act.py
+++ b/tests/test_act.py
@@ -169,6 +169,54 @@ def test_set_amendments(self):
assert_validates(a)
+ # clear them
+ a.amendments = []
+ xml = a.to_xml(encoding='unicode', pretty_print=True)
+ xml = xml.replace(datestring(date.today()), 'TODAY')
+
+ self.assertMultiLineEqual(
+ """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+""", xml)
+
def test_set_repeal(self):
a = Act()
a.frbr_uri = "/akn/za/act/1900/1"
@@ -178,7 +226,7 @@ def test_set_repeal(self):
self.assertMultiLineEqual(
"""
-
+