Skip to content

Commit

Permalink
Fix empty query of graph issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Oct 6, 2022
1 parent bb3ab5e commit 0969ed9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions walrus/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ def keys_for_query(self, s=None, p=None, o=None):
parts.extend(('pos', p))
elif o:
parts.extend(('osp', o))
else:
parts.extend(('spo',))
return key(parts + ['']), key(parts + ['\xff'])

def query(self, s=None, p=None, o=None):
Expand Down
16 changes: 16 additions & 0 deletions walrus/tests/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ def assertTriples(self, result, expected):

def test_query(self):
self.create_graph_data()
res = self.g.query()
self.assertTriples(res, (
('charlie', 'is', 'human'),
('charlie', 'likes', 'huey'),
('charlie', 'likes', 'mickey'),
('charlie', 'likes', 'zaizee'),
('connor', 'likes', 'huey'),
('connor', 'likes', 'mickey'),
('huey', 'eats', 'catfood'),
('huey', 'is', 'cat'),
('mickey', 'eats', 'anything'),
('mickey', 'is', 'dog'),
('zaizee', 'eats', 'catfood'),
('zaizee', 'is', 'cat'),
))

res = self.g.query('charlie', 'likes')
self.assertTriples(res, (
('charlie', 'likes', 'huey'),
Expand Down

0 comments on commit 0969ed9

Please sign in to comment.