Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusconjeaud committed Dec 10, 2024
1 parent 820556f commit 058f5b8
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
2 changes: 1 addition & 1 deletion doc/source/advanced_query_operations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Options for `subquery` calls are:
.. note::
In the example above, we reference `self` to be included in the initial context. It will actually inject the outer variable corresponding to `Coffee` node.

We know this is confusing to read, but have not found a better wat to do this yet. If you have any suggestions, please let us know.
We know this is confusing to read, but have not found a better way to do this yet. If you have any suggestions, please let us know.

Helpers
-------
Expand Down
2 changes: 1 addition & 1 deletion neomodel/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "5.4.1"
__version__ = "5.4.2"
8 changes: 4 additions & 4 deletions neomodel/typing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Custom types used for annotations."""

from typing import Any, Dict, List, Optional, TypedDict
from typing import Any, Optional, TypedDict

Transformation = TypedDict(
"Transformation",
Expand All @@ -16,8 +16,8 @@
"Subquery",
{
"query": str,
"query_params": Dict,
"return_set": List[str],
"initial_context": Optional[List[Any]],
"query_params": dict,
"return_set": list[str],
"initial_context": Optional[list[Any]],
},
)
29 changes: 27 additions & 2 deletions test/async_/test_match_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime
from test._async_compat import mark_async_test

import numpy as np
from pytest import raises, skip, warns

from neomodel import (
Expand Down Expand Up @@ -880,7 +881,7 @@ async def test_subquery():
await nescafe.suppliers.connect(supplier2)
await nescafe.species.connect(arabica)

result = await Coffee.nodes.subquery(
subquery = await Coffee.nodes.subquery(
Coffee.nodes.traverse_relations(suppliers="suppliers")
.intermediate_transform(
{"suppliers": {"source": "suppliers"}}, ordering=["suppliers.delivery_cost"]
Expand All @@ -889,7 +890,7 @@ async def test_subquery():
["supps"],
[NodeNameResolver("self")],
)
result = await result.all()
result = await subquery.all()
assert len(result) == 1
assert len(result[0]) == 2
assert result[0][0] == supplier2
Expand All @@ -905,6 +906,30 @@ async def test_subquery():
["unknown"],
)

result_string_context = await subquery.subquery(
Coffee.nodes.traverse_relations(supps2="suppliers").annotate(
supps2=Collect("supps")
),
["supps2"],
["supps"],
)
result_string_context = await result_string_context.all()
assert len(result) == 1
additional_elements = [
item for item in result_string_context[0] if item not in result[0]
]
assert len(additional_elements) == 1
assert isinstance(additional_elements[0], list)

with raises(ValueError, match=r"Wrong variable specified in initial context"):
result = await Coffee.nodes.subquery(
Coffee.nodes.traverse_relations(suppliers="suppliers").annotate(
supps=Collect("suppliers")
),
["supps"],
[2],
)


@mark_async_test
async def test_subquery_other_node():
Expand Down
29 changes: 27 additions & 2 deletions test/sync_/test_match_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime
from test._async_compat import mark_sync_test

import numpy as np
from pytest import raises, skip, warns

from neomodel import (
Expand Down Expand Up @@ -864,7 +865,7 @@ def test_subquery():
nescafe.suppliers.connect(supplier2)
nescafe.species.connect(arabica)

result = Coffee.nodes.subquery(
subquery = Coffee.nodes.subquery(
Coffee.nodes.traverse_relations(suppliers="suppliers")
.intermediate_transform(
{"suppliers": {"source": "suppliers"}}, ordering=["suppliers.delivery_cost"]
Expand All @@ -873,7 +874,7 @@ def test_subquery():
["supps"],
[NodeNameResolver("self")],
)
result = result.all()
result = subquery.all()
assert len(result) == 1
assert len(result[0]) == 2
assert result[0][0] == supplier2
Expand All @@ -889,6 +890,30 @@ def test_subquery():
["unknown"],
)

result_string_context = subquery.subquery(
Coffee.nodes.traverse_relations(supps2="suppliers").annotate(
supps2=Collect("supps")
),
["supps2"],
["supps"],
)
result_string_context = result_string_context.all()
assert len(result) == 1
additional_elements = [
item for item in result_string_context[0] if item not in result[0]
]
assert len(additional_elements) == 1
assert isinstance(additional_elements[0], list)

with raises(ValueError, match=r"Wrong variable specified in initial context"):
result = Coffee.nodes.subquery(
Coffee.nodes.traverse_relations(suppliers="suppliers").annotate(
supps=Collect("suppliers")
),
["supps"],
[2],
)


@mark_sync_test
def test_subquery_other_node():
Expand Down

0 comments on commit 058f5b8

Please sign in to comment.