-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix configure() cycle error when selecting new top
- Loading branch information
Showing
2 changed files
with
107 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
import pytest | ||
|
||
from penman.exceptions import LayoutError | ||
from penman.model import Model | ||
from penman.tree import Tree | ||
from penman.graph import Graph | ||
from penman.codec import PENMANCodec | ||
from penman.layout import ( | ||
interpret, | ||
configure, | ||
reconfigure, | ||
has_valid_layout, | ||
) | ||
|
||
|
||
codec = PENMANCodec() | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def amr_model(mini_amr): | ||
return Model.from_dict(mini_amr) | ||
|
||
|
||
def test_interpret(amr_model): | ||
t = codec.parse('(a / A)') | ||
assert interpret(t) == Graph([('a', ':instance', 'A')], top='a') | ||
|
||
t = codec.parse('(a / A :consist-of (b / B))') | ||
assert interpret(t) == Graph( | ||
[('a', ':instance', 'A'), | ||
('b', ':consist', 'a'), | ||
('b', ':instance', 'B')], | ||
top='a') | ||
assert interpret(t, model=amr_model) == Graph( | ||
[('a', ':instance', 'A'), | ||
('a', ':consist-of', 'b'), | ||
('b', ':instance', 'B')], | ||
top='a') | ||
|
||
|
||
def test_configure(amr_model): | ||
g = codec.decode('(a / A)') | ||
assert configure(g) == Tree(('a', [('/', 'A', [])])) | ||
with pytest.raises(LayoutError): | ||
configure(g, top='A') | ||
|
||
g = codec.decode('(a / A :consist-of (b / B))') | ||
assert configure(g) == Tree( | ||
('a', [ | ||
('/', 'A', []), | ||
(':consist-of', ('b', [('/', 'B', [])]), []) | ||
]) | ||
) | ||
assert configure(g, top='b') == Tree( | ||
('b', [ | ||
('/', 'B', []), | ||
(':consist', ('a', [('/', 'A', [])]), []) | ||
]) | ||
) | ||
|
||
amr_codec = PENMANCodec(model=amr_model) | ||
g = amr_codec.decode('(a / A :consist-of (b / B))') | ||
assert configure(g, model=amr_model) == Tree( | ||
('a', [ | ||
('/', 'A', []), | ||
(':consist-of', ('b', [('/', 'B', [])]), []) | ||
]) | ||
) | ||
assert configure(g, top='b', model=amr_model) == Tree( | ||
('b', [ | ||
('/', 'B', []), | ||
(':consist-of-of', ('a', [('/', 'A', [])]), []) | ||
]) | ||
) | ||
|