Skip to content

Commit

Permalink
fixing issue #94
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulyalin committed Dec 3, 2022
1 parent aa67022 commit 8a41bc2
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 1 deletion.
106 changes: 105 additions & 1 deletion test/pytest/test_answers_and_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7258,4 +7258,108 @@ def test_issue_77():
'lsp101': {'primary': {'name': {'exclude': {'6': {}}, 'include': {'5': {}}}},
'secondary': {'name': {'exclude': {'8': {}}, 'include': {'7': {}}}}}}}]]

# test_issue_77()
# test_issue_77()

def test_issue_94():
data = """
router isis LAB
flex-algo 128
priority 100
metric-type delay
advertise-definition
prefix-metric
!
address-family ipv4 unicast
metric-style wide
!
!
"""
template = """
<group name="routing.isis.LAB" default="MISSING">
router isis LAB {{ _start_ | _exact_ }}
<group name="fa128" default="MISSING">
flex-algo 128 {{ _start_ | _exact_ }}
priority {{ priority | equal('999') }}
metric-type {{ metric_type | equal('delay') }}
advertise-definition {{ advertise_definition | set('true') }}
prefix-metric {{ prefix_metric | set('true') }}
!{{ _end_ }}
</group>
<group name="LEFTOVER">
{{ LEFTOVER | _line_ | joinmatches }}
</group>
!{{ _end_ }}
</group>
"""
parser = ttp(data, template)
parser.parse()
res = parser.result()
pprint.pprint(res, width=100)
assert res == [[{'routing': {'isis': {'LAB': {'LEFTOVER': [{'LEFTOVER': ' priority 100'},
{'LEFTOVER': 'address-family ipv4 unicast'},
{'LEFTOVER': ' metric-style wide'}],
'fa128': {'advertise_definition': 'true',
'metric_type': 'delay',
'prefix_metric': 'true',
'priority': 'MISSING'}}}}}]]
# test_issue_94()

def test_issue_94_1():
data = """
router isis LAB
flex-algo 128
priority 100
metric-type delay
advertise-definition
prefix-metric
!
address-family ipv4 unicast
metric-style wide
advertise passive-only
mpls traffic-eng level-2-only
!
interface Loopback0
passive
!
"""
template = """
<group name="routing.isis.LAB" default="MISSING">
router isis LAB {{ _start_ | _exact_ }}
<group name="fa128" default="MISSING">
flex-algo 128 {{ _start_ | _exact_ }}
priority {{ priority | equal('999') }}
metric-type {{ metric_type | equal('delay') }}
advertise-definition {{ advertise_definition | set('true') }}
prefix-metric {{ prefix_metric | set('true') }}
{{ LEFTOVER | _line_ | joinmatches }}
!{{ _end_ }}
</group>
<group name="LEFTOVER">
{{ LEFTOVER | _line_ | joinmatches }}
</group>
!{{ _end_ }}
</group>
"""
parser = ttp(data, template)
parser.parse()
res = parser.result()
pprint.pprint(res, width=100)
assert res == [[{'routing': {'isis': {'LAB': {'LEFTOVER': [{'LEFTOVER': 'address-family ipv4 unicast'},
{'LEFTOVER': ' metric-style wide'},
{'LEFTOVER': ' advertise passive-only'},
{'LEFTOVER': ' mpls traffic-eng level-2-only'},
{'LEFTOVER': 'interface Loopback0'},
{'LEFTOVER': ' passive'}],
'fa128': {'LEFTOVER': 'priority 100',
'advertise_definition': 'true',
'metric_type': 'delay',
'prefix_metric': 'true',
'priority': 'MISSING'}}}}}]]

# test_issue_94_1()
10 changes: 10 additions & 0 deletions ttp/ttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3040,6 +3040,11 @@ def start(self, result, PATH, DEFAULTS=None, FUNCTIONS=None, REDICT=""):
if REDICT["GROUP"].parent_group_id == self.started_groups[-1]:
self.started_groups.append(REDICT["GROUP"].group_id)
break
# check if _line_ group started, don't remove previous started
# groups to allow collection of non matched lines - #94
if REDICT.get("IS_LINE"):
self.started_groups.append(REDICT["GROUP"].group_id)
break
_ = self.started_groups.pop()
# meaning top group started
else:
Expand Down Expand Up @@ -3068,6 +3073,11 @@ def startempty(self, result, PATH, DEFAULTS=None, FUNCTIONS=None, REDICT=""):
if REDICT["GROUP"].parent_group_id == self.started_groups[-1]:
self.started_groups.append(REDICT["GROUP"].group_id)
break
# check if _line_ group started, don't remove previous started
# groups to allow collection of non matched lines - #94
if REDICT.get("IS_LINE"):
self.started_groups.append(REDICT["GROUP"].group_id)
break
_ = self.started_groups.pop()
# meaning top group started
else:
Expand Down

0 comments on commit 8a41bc2

Please sign in to comment.