Skip to content

Commit 978aa96

Browse files
gkorlandswilly22
authored andcommitted
python3 support (#35)
* python3 support * set decode_responses=True
1 parent 0c78b1a commit 978aa96

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed

redisgraph/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from node import Node
2-
from edge import Edge
3-
from graph import Graph
1+
from .node import Node
2+
from .edge import Edge
3+
from .graph import Graph

redisgraph/edge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from util import *
1+
from .util import *
22

33
class Edge(object):
44
"""

redisgraph/graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from util import *
2-
from query_result import QueryResult
1+
from .util import *
2+
from .query_result import QueryResult
33
class Graph(object):
44
"""
55
Graph, collection of nodes and edges.

redisgraph/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from util import *
1+
from .util import *
22

33
class Node(object):
44
"""

redisgraph/query_result.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from node import Node
2-
from edge import Edge
1+
from .node import Node
2+
from .edge import Edge
33
from prettytable import PrettyTable
44

55
class ResultSetColumnTypes(object):
@@ -72,7 +72,7 @@ def parse_records(self, raw_result_set):
7272
elif self.header[idx][0] == ResultSetColumnTypes.COLUMN_RELATION:
7373
record.append(self.parse_edge(cell))
7474
else:
75-
print "Unknown column type.\n"
75+
print("Unknown column type.\n")
7676
records.append(record)
7777

7878
return records
@@ -132,13 +132,13 @@ def parse_scalar(self, cell):
132132
elif value == "false":
133133
scalar = False
134134
else:
135-
print "Unknown boolean type\n"
135+
print("Unknown boolean type\n")
136136

137137
elif scalar_type == ResultSetScalarTypes.PROPERTY_DOUBLE:
138138
scalar = float(value)
139139

140140
elif scalar_type == ResultSetScalarTypes.PROPERTY_UNKNOWN:
141-
print "Unknown scalar type\n"
141+
print("Unknown scalar type\n")
142142

143143
return scalar
144144

@@ -170,7 +170,7 @@ def pretty_print(self):
170170
print(str(tbl) + '\n')
171171

172172
for stat in self.statistics:
173-
print "%s %s" %(stat, self.statistics[stat])
173+
print("%s %s" %(stat, self.statistics[stat]))
174174

175175
def is_empty(self):
176176
return len(self.result_set) == 0

test.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,39 @@
22
import unittest
33
from redisgraph import *
44

5+
56
class TestStringMethods(unittest.TestCase):
67
def setUp(self):
7-
self.r = redis.Redis(host='localhost', port=6379)
8+
self.r = redis.Redis(host='localhost', port=6379, decode_responses=True)
89

910
def test_graph_creation(self):
10-
redis_graph = Graph('social', self.r)
11-
12-
john = Node(label='person', properties={'name': 'John Doe', 'age': 33, 'gender': 'male', 'status': 'single'})
13-
redis_graph.add_node(john)
14-
15-
japan = Node(label='country', properties={'name': 'Japan'})
16-
redis_graph.add_node(japan)
17-
18-
edge = Edge(john, 'visited', japan, properties={'purpose': 'pleasure'})
19-
redis_graph.add_edge(edge)
20-
21-
redis_graph.commit()
22-
23-
query = """MATCH (p:person)-[v:visited {purpose:"pleasure"}]->(c:country)
11+
redis_graph = Graph('social', self.r)
12+
13+
john = Node(label='person', properties={'name': 'John Doe', 'age': 33, 'gender': 'male', 'status': 'single'})
14+
redis_graph.add_node(john)
15+
japan = Node(label='country', properties={'name': 'Japan'})
16+
17+
redis_graph.add_node(japan)
18+
edge = Edge(john, 'visited', japan, properties={'purpose': 'pleasure'})
19+
redis_graph.add_edge(edge)
20+
21+
redis_graph.commit()
22+
23+
query = """MATCH (p:person)-[v:visited {purpose:"pleasure"}]->(c:country)
2424
RETURN p, v, c"""
25-
26-
result = redis_graph.query(query)
27-
28-
person = result.result_set[0][0]
29-
visit = result.result_set[0][1]
30-
country = result.result_set[0][2]
31-
32-
self.assertEqual(person, john)
33-
self.assertEqual(visit.properties, edge.properties)
34-
self.assertEqual(country, japan)
25+
26+
result = redis_graph.query(query)
27+
28+
person = result.result_set[0][0]
29+
visit = result.result_set[0][1]
30+
country = result.result_set[0][2]
31+
32+
self.assertEqual(person, john)
33+
self.assertEqual(visit.properties, edge.properties)
34+
self.assertEqual(country, japan)
3535

3636
# All done, remove graph.
37-
redis_graph.delete()
37+
redis_graph.delete()
3838

3939
if __name__ == '__main__':
4040
unittest.main()

0 commit comments

Comments
 (0)