-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #317 from gaphor/copy-paste-with-parent-items
Copy paste with parent items
- Loading branch information
Showing
8 changed files
with
101 additions
and
25 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
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
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
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,59 @@ | ||
import pytest | ||
|
||
from gaphor import UML | ||
from gaphor.diagram.copypaste import copy, paste | ||
from gaphor.diagram.grouping import Group | ||
from gaphor.diagram.tests.fixtures import copy_clear_and_paste | ||
from gaphor.UML.components import ComponentItem, NodeItem | ||
|
||
|
||
@pytest.fixture | ||
def node_with_component(diagram, element_factory): | ||
node = element_factory.create(UML.Node) | ||
comp = element_factory.create(UML.Component) | ||
node_item = diagram.create(NodeItem, subject=node) | ||
comp_item = diagram.create(ComponentItem, subject=comp) | ||
|
||
Group(node_item, comp_item).group() | ||
diagram.canvas.reparent(comp_item, parent=node_item) | ||
|
||
assert diagram.canvas.get_parent(comp_item) is node_item | ||
|
||
return node_item, comp_item | ||
|
||
|
||
def test_copy_paste_of_nested_item(diagram, element_factory, node_with_component): | ||
node_item, comp_item = node_with_component | ||
|
||
buffer = copy({comp_item}) | ||
|
||
(new_comp_item,) = paste(buffer, diagram, element_factory.lookup) | ||
|
||
assert diagram.canvas.get_parent(new_comp_item) is node_item | ||
|
||
|
||
def test_copy_paste_of_item_with_nested_item( | ||
diagram, element_factory, node_with_component | ||
): | ||
node_item, comp_item = node_with_component | ||
|
||
buffer = copy(set(node_with_component)) | ||
|
||
new_items = paste(buffer, diagram, element_factory.lookup) | ||
|
||
new_node_item = next(i for i in new_items if isinstance(i, NodeItem)) | ||
new_comp_item = next(i for i in new_items if isinstance(i, ComponentItem)) | ||
|
||
assert diagram.canvas.get_parent(new_comp_item) is new_node_item | ||
|
||
|
||
def test_copy_remove_paste_of_item_with_nested_item( | ||
diagram, element_factory, node_with_component | ||
): | ||
|
||
new_items = copy_clear_and_paste(set(node_with_component), diagram, element_factory) | ||
|
||
new_node_item = next(i for i in new_items if isinstance(i, NodeItem)) | ||
new_comp_item = next(i for i in new_items if isinstance(i, ComponentItem)) | ||
|
||
assert diagram.canvas.get_parent(new_comp_item) is new_node_item |
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