-
Notifications
You must be signed in to change notification settings - Fork 12
Support EagerResult from driver.execute_query() in from_neo4j() #335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,110 @@ | ||
| import neo4j.graph | ||
|
|
||
| from neo4j_viz.neo4j import find_graph_entity | ||
|
|
||
|
|
||
| def _make_graph() -> neo4j.graph.Graph: | ||
| return neo4j.graph.Graph() | ||
|
|
||
|
|
||
| def _make_node( | ||
| graph: neo4j.graph.Graph, element_id: str, labels: list[str], props: dict[str, object] | ||
| ) -> neo4j.graph.Node: | ||
| return neo4j.graph.Node(graph, element_id, hash(element_id), labels, props) | ||
|
|
||
|
|
||
| def _make_rel( | ||
| graph: neo4j.graph.Graph, | ||
| element_id: str, | ||
| rel_type: str, | ||
| start: neo4j.graph.Node, | ||
| end: neo4j.graph.Node, | ||
| props: dict[str, object] | None = None, | ||
| ) -> neo4j.graph.Relationship: | ||
| RelType = graph.relationship_type(rel_type) | ||
| rel = RelType.__new__(RelType) | ||
| rel.__dict__.update( | ||
| { | ||
| "_graph": graph, | ||
| "_element_id": element_id, | ||
| "_id": hash(element_id), | ||
| "_properties": props or {}, | ||
| "_start_node": start, | ||
| "_end_node": end, | ||
| } | ||
| ) | ||
| return rel | ||
|
|
||
|
|
||
| def test_plain_node() -> None: | ||
| g = _make_graph() | ||
| node = _make_node(g, "n1", ["A"], {"x": 1}) | ||
| assert find_graph_entity(node) is g | ||
|
|
||
|
|
||
| def test_plain_relationship() -> None: | ||
| g = _make_graph() | ||
| a = _make_node(g, "a", ["A"], {}) | ||
| b = _make_node(g, "b", ["B"], {}) | ||
| rel = _make_rel(g, "r1", "KNOWS", a, b) | ||
| assert find_graph_entity(rel) is g | ||
|
|
||
|
|
||
| def test_path() -> None: | ||
| g = _make_graph() | ||
| a = _make_node(g, "a", ["A"], {}) | ||
| b = _make_node(g, "b", ["B"], {}) | ||
| rel = _make_rel(g, "r1", "KNOWS", a, b) | ||
| path = neo4j.graph.Path(a, rel) | ||
| assert find_graph_entity(path) is g | ||
|
|
||
|
|
||
| def test_list_of_nodes() -> None: | ||
| g = _make_graph() | ||
| a = _make_node(g, "a", ["A"], {}) | ||
| b = _make_node(g, "b", ["B"], {}) | ||
| value = [a, b] | ||
| assert find_graph_entity(value) is g | ||
|
|
||
|
|
||
| def test_nested_list() -> None: | ||
| g = _make_graph() | ||
| a = _make_node(g, "a", ["A"], {}) | ||
| value = [[a]] | ||
| assert find_graph_entity(value) is g | ||
|
|
||
|
|
||
| def test_dict_of_nodes() -> None: | ||
| g = _make_graph() | ||
| a = _make_node(g, "a", ["A"], {}) | ||
| value = {"key": a} | ||
| assert find_graph_entity(value) is g | ||
|
|
||
|
|
||
| def test_deduplication() -> None: | ||
| g = _make_graph() | ||
| a = _make_node(g, "a", ["A"], {}) | ||
| value = [a, a] | ||
| assert find_graph_entity(value) is g | ||
|
|
||
|
|
||
| def test_scalar_ignored() -> None: | ||
| assert find_graph_entity("hello") is None | ||
| assert find_graph_entity(42) is None | ||
| assert find_graph_entity(None) is None | ||
|
|
||
|
|
||
| def test_mixed_list_with_graph_entities_and_scalars() -> None: | ||
| g = _make_graph() | ||
| a = _make_node(g, "a", ["A"], {}) | ||
| b = _make_node(g, "b", ["B"], {}) | ||
| rel = _make_rel(g, "r1", "KNOWS", a, b) | ||
| value = ["hello", rel, 42, None] | ||
| assert find_graph_entity(value) is g | ||
|
|
||
|
|
||
| def test_mixed_dict_with_graph_entities_and_scalars() -> None: | ||
| g = _make_graph() | ||
| a = _make_node(g, "a", ["A"], {}) | ||
| value = {"text": "hello", "node": a, "count": 42, "empty": None} | ||
| assert find_graph_entity(value) is g |
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.