Skip to content

Commit

Permalink
Improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tonioo committed Oct 22, 2024
1 parent 29f8bfa commit 212b349
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
27 changes: 25 additions & 2 deletions test/async_/test_match_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
AsyncTraversal,
Collect,
Last,
NodeNameResolver,
Optional,
RawCypher,
RelationNameResolver,
Expand Down Expand Up @@ -768,6 +769,19 @@ async def test_annotate_and_collect():
)
assert len(result[0][1][0]) == 2 # 2 species must be there

result = (
await Supplier.nodes.traverse_relations("coffees__species")
.annotate(
all_species=Collect(NodeNameResolver("coffees__species"), distinct=True),
all_species_rels=Collect(
RelationNameResolver("coffees__species"), distinct=True
),
)
.all()
)
assert len(result[0][1][0]) == 2 # 2 species must be there
assert len(result[0][2][0]) == 3 # 3 species relations must be there


@mark_async_test
async def test_resolve_subgraph():
Expand Down Expand Up @@ -900,11 +914,11 @@ async def test_intermediate_transform():
await nescafe.species.connect(arabica)

result = (
await Coffee.nodes.traverse_relations(suppliers="suppliers")
await Coffee.nodes.fetch_relations("suppliers")
.intermediate_transform(
{
"coffee": "coffee",
"suppliers": "suppliers",
"suppliers": NodeNameResolver("suppliers"),
"r": RelationNameResolver("suppliers"),
},
ordering=["-r.since"],
Expand All @@ -927,6 +941,15 @@ async def test_intermediate_transform():
"test": Collect("suppliers"),
}
)
with raises(
ValueError,
match=re.escape(
r"You must provide one variable at least when calling intermediate_transform()"
),
):
Coffee.nodes.traverse_relations(suppliers="suppliers").intermediate_transform(
{}
)


@mark_async_test
Expand Down
27 changes: 25 additions & 2 deletions test/sync_/test_match_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from neomodel.sync_.match import (
Collect,
Last,
NodeNameResolver,
NodeSet,
Optional,
QueryBuilder,
Expand Down Expand Up @@ -756,6 +757,19 @@ def test_annotate_and_collect():
)
assert len(result[0][1][0]) == 2 # 2 species must be there

result = (
Supplier.nodes.traverse_relations("coffees__species")
.annotate(
all_species=Collect(NodeNameResolver("coffees__species"), distinct=True),
all_species_rels=Collect(
RelationNameResolver("coffees__species"), distinct=True
),
)
.all()
)
assert len(result[0][1][0]) == 2 # 2 species must be there
assert len(result[0][2][0]) == 3 # 3 species relations must be there


@mark_sync_test
def test_resolve_subgraph():
Expand Down Expand Up @@ -888,11 +902,11 @@ def test_intermediate_transform():
nescafe.species.connect(arabica)

result = (
Coffee.nodes.traverse_relations(suppliers="suppliers")
Coffee.nodes.fetch_relations("suppliers")
.intermediate_transform(
{
"coffee": "coffee",
"suppliers": "suppliers",
"suppliers": NodeNameResolver("suppliers"),
"r": RelationNameResolver("suppliers"),
},
ordering=["-r.since"],
Expand All @@ -915,6 +929,15 @@ def test_intermediate_transform():
"test": Collect("suppliers"),
}
)
with raises(
ValueError,
match=re.escape(
r"You must provide one variable at least when calling intermediate_transform()"
),
):
Coffee.nodes.traverse_relations(suppliers="suppliers").intermediate_transform(
{}
)


@mark_sync_test
Expand Down

0 comments on commit 212b349

Please sign in to comment.