Commit 0885402d authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added parent section index parameter to local backends get_setcions method.

parent 8100b926
Pipeline #64219 failed with stages
in 25 minutes and 35 seconds
......@@ -184,8 +184,8 @@ class AbstractParserBackend(metaclass=ABCMeta):
pass
@abstractmethod
def get_sections(self, meta_name: str) -> List[int]:
""" Return all gIndices for existing sections of the given meta_name. """
def get_sections(self, meta_name: str, g_index: int = -1) -> List[int]:
""" Return all gIndices for existing sections of the given meta_name and parent section index. """
pass
@abstractmethod
......@@ -513,9 +513,11 @@ class LocalBackend(LegacyParserBackend, metaclass=DelegatingMeta):
return section[meta_name]
def get_sections(self, meta_name):
def get_sections(self, meta_name, g_index=-1):
sections = self._delegate.results[meta_name]
return [section.gIndex for section in sections]
return [
section.gIndex for section in sections
if g_index == -1 or section.parents[0].gIndex == g_index]
def _write(
self, json_writer: JSONStreamWriter, value: Any,
......
......@@ -108,6 +108,28 @@ class TestLocalBackend(object):
for i in range(0, 3):
assert backend.get_value('program_name', i) == 't%d' % i
def test_sub_section(self, backend, no_warn):
backend.openSection('section_run')
backend.openNonOverlappingSection('section_system')
assert backend.openSection('section_symmetry') == 0
backend.closeSection('section_symmetry', 0)
backend.closeNonOverlappingSection('section_system')
backend.openNonOverlappingSection('section_system')
backend.closeNonOverlappingSection('section_system')
backend.openNonOverlappingSection('section_system')
assert backend.openSection('section_symmetry') == 1
backend.closeSection('section_symmetry', 1)
backend.closeNonOverlappingSection('section_system')
assert backend.get_sections('section_system') == [0, 1, 2]
assert backend.get_sections('section_symmetry') == [0, 1]
assert backend.get_sections('section_symmetry', 0) == [0]
assert backend.get_sections('section_symmetry', 1) == []
assert backend.get_sections('section_symmetry', 2) == [1]
def test_section_override(self, backend, no_warn):
""" Test whether we can overwrite values already in the backend."""
expected_value = ['Cl', 'Zn']
......
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