Commit 7dc42708 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fixed resoursive adding of sections to resources.

parent 2207138a
......@@ -521,8 +521,23 @@ class MResource():
return cast(MSectionBound, result)
def add(self, section):
section.m_resource = self
self.__data.setdefault(section.m_def, []).append(section)
Add the given section to this resource. Will also add all its contents to the
resource and make all contest available for :func:`all`. Will also remove
all contents from possible other resources. A section can only be contained in
one resource at a time.
This is potentially expensive. Do not add a section that already has a deep tree
of sub-sections. Ideally, add the root section first. If you create sub sections
afterwards, they will be automatically added to this resource.
if section.m_resource is not None:
for content in section.m_all_contents(include_self=True):
content.m_resource = self
self.__data.setdefault(content.m_def, []).append(content)
if section.m_parent is None:
......@@ -414,7 +414,7 @@ class Calc(Proc):
information in section_encyclopedia as well as the DFT domain metadata.
logger = self.get_logger(**context)
logger = self.get_logger(parser=self.parser, step=self.parser)
# Open the archive of the phonon calculation.
upload_files = StagingUploadFiles(self.upload_id, is_authorized=lambda: True)
......@@ -425,7 +425,6 @@ class Calc(Proc):
self._calc_proc_logs = phonon_archive.processing_logs
# Re-create a backend
context = dict(parser=self.parser, step=self.parser)
metainfo = phonopyparser.metainfo.m_env
self._parser_backend = Backend(metainfo, logger=logger, domain="dft")
self._parser_backend.entry_archive = phonon_archive
......@@ -519,6 +519,22 @@ class TestM1:
assert len(resource.all(System)) == 2
def test_resource_add(self):
# adding
resource = MResource()
run = Run()
assert len(resource.all(Run)) == 1
assert len(resource.all(System)) == 2
# implicitly moving to another resource
resource = MResource()
assert len(resource.all(Run)) == 1
assert len(resource.all(System)) == 2
def test_resource_move(self):
resource = MResource()
run = resource.create(Run)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment