Skip to content

tests: add edge cases unitests for Path class #102

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@ def test_new_empty_path():
assert path._edges == []


def test_wrong_flows():
node_1 = Node(node_id=1)
node_2 = Node(node_id=2)
node_3 = Node(node_id=3)

edge_1 = Edge(node_1, None, node_2)
edge_2 = Edge(node_1, None, node_3)

nodes = [node_1, node_2, node_3]
edges = [edge_1, edge_2]

def test_nodes_and_edges():
node_1 = Node(node_id=1)
node_2 = Node(node_id=2)
Expand All @@ -51,6 +40,13 @@ def test_nodes_and_edges():
assert 1 == p.edge_count()
assert edge_1 == p.get_edge(0)

assert p.get_node(-1) is None
assert p.get_edge(49) is None

path_str = str(p)
assert path_str == "<(node1)-(edge1)->(node2)>"
Comment on lines +46 to +47
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify the expected string representation format.

The test checks for a specific string format, but I can't verify if it matches the actual implementation without seeing the Path class's __str__ method. Ensure that the hardcoded string "<(node1)-(edge1)->(node2)>" matches how nodes and edges are actually represented when converted to strings.


🏁 Script executed:

#!/bin/bash
# Check the __str__ implementation in the Path class
grep -A 10 "__str__" $(fd "path.py" --type f --exclude "test_path.py")

Length of output: 425


I want to confirm the full __str__ logic to ensure the test’s expected output matches exactly. Let's dump the entire method:


🏁 Script executed:

#!/bin/bash
grep -n "def __str__" -A 200 falkordb/path.py

Length of output: 864


I’d like to verify how nodes and edges are set up in the test (their IDs and types). Dumping the relevant portion of tests/test_path.py:


🏁 Script executed:

sed -n '1,200p' tests/test_path.py

Length of output: 1712


I’d like to inspect how Node.id and Edge.id are defined to confirm the string formatting. Dump the class definitions:


🏁 Script executed:

#!/bin/bash
grep -n "class Node" -A 50 falkordb/node.py
grep -n "class Edge" -A 50 falkordb/edge.py

Length of output: 3375


Let’s inspect the __str__ implementations for both Node and Edge to confirm how they format IDs and aliases:


🏁 Script executed:

#!/bin/bash
grep -n "def __str__" -A 20 falkordb/node.py
grep -n "def __str__" -A 20 falkordb/edge.py

Length of output: 1409


To confirm how equality and the edge’s __str__ tail behave, let’s dump any __eq__ methods and the rest of the Edge.__str__ implementation:


🏁 Script executed:

#!/bin/bash
# Check for __eq__ in Node and Edge
grep -R "def __eq__" -n falkordb/node.py falkordb/edge.py || echo "No __eq__ methods found"

# Dump full Edge.__str__ method
sed -n '57,120p' falkordb/edge.py

Length of output: 1925


Mismatch between test’s expected format and Path.str implementation

The Path.__str__ method builds its output using the numeric id values and square brackets around edge IDs, e.g.

"<(1)-[1]->(2)>"

However, the test asserts:

assert str(p) == "<(node1)-(edge1)->(node2)>"

– which doesn’t align with the implementation.

Please update the test in tests/test_path.py accordingly:

  • When creating the edge, supply an integer ID:
  • edge_1 = Edge(node_1, None, node_2)
  • edge_1 = Edge(node_1, None, node_2, edge_id=1)
- Change the expected string to match `Path.__str__`’s output:  
```diff
-   assert path_str == "<(node1)-(edge1)->(node2)>"
+   assert path_str == "<(1)-[1]->(2)>"



def test_compare():
node_1 = Node(node_id=1)
node_2 = Node(node_id=2)
Expand All @@ -65,3 +61,5 @@ def test_compare():
assert Path([node_1], edges=[]) != Path([node_2], [])
assert Path([node_1], [edge_1]) != Path( [node_1], [])
assert Path([node_1], [edge_1]) != Path([node_2], [edge_1])

assert not (Path(nodes, edges) == "this is not a path")