55import csv
66import redis
77import unittest
8- from redisgraph import Graph
8+ from redis import Redis
99from click .testing import CliRunner
1010from redisgraph_bulk_loader .bulk_insert import bulk_insert
1111
@@ -39,10 +39,13 @@ def setUpClass(cls):
3939 @classmethod
4040 def tearDownClass (cls ):
4141 """Delete temporary files"""
42- os .remove ('/tmp/nodes.tmp' )
43- os .remove ('/tmp/relations.tmp' )
44- os .remove ('/tmp/nodes_index.tmp' )
45- os .remove ('/tmp/nodes_full_text_index.tmp' )
42+ try :
43+ os .remove ('/tmp/nodes.tmp' )
44+ os .remove ('/tmp/relations.tmp' )
45+ os .remove ('/tmp/nodes_index.tmp' )
46+ os .remove ('/tmp/nodes_full_text_index.tmp' )
47+ except OSError :
48+ pass
4649 cls .redis_con .flushall ()
4750
4851 def validate_exception (self , res , expected_msg ):
@@ -89,7 +92,7 @@ def test01_social_graph(self):
8992 self .assertIn (visited_count + " relations created for type 'VISITED'" , res .output )
9093
9194 # Open the constructed graph.
92- graph = Graph ('social' , self . redis_con )
95+ graph = self . redis_con . graph ('social' )
9396 query_result = graph .query ("MATCH (p:Person) RETURN p.name, p.age, p.gender, p.status ORDER BY p.name" )
9497 # Verify that the Person label exists, has the correct attributes, and is properly populated.
9598 expected_result = [['Ailon Velger' , 32 , 'male' , 'married' ],
@@ -207,7 +210,7 @@ def test02_private_identifiers(self):
207210 self .assertIn ('3 nodes created' , res .output )
208211 self .assertIn ('2 relations created' , res .output )
209212
210- tmp_graph = Graph ( graphname , self .redis_con )
213+ tmp_graph = self .redis_con . graph ( graphname )
211214 # The field "_identifier" should not be a property in the graph
212215 query_result = tmp_graph .query ('MATCH (a) RETURN a' )
213216
@@ -280,8 +283,8 @@ def test04_batched_build(self):
280283 self .assertIn (knows_count + " relations created for type 'KNOWS'" , res .output )
281284 self .assertIn (visited_count + " relations created for type 'VISITED'" , res .output )
282285
283- original_graph = Graph ('social' , self . redis_con )
284- new_graph = Graph ( graphname , self .redis_con )
286+ original_graph = self . redis_con . graph ('social' )
287+ new_graph = self .redis_con . graph ( graphname )
285288
286289 # Newly-created graph should be identical to graph created in single bulk command
287290 original_result = original_graph .query ('MATCH (p:Person) RETURN p, ID(p) ORDER BY p.name' )
@@ -368,7 +371,7 @@ def test06_property_types(self):
368371 self .assertIn ('3 nodes created' , res .output )
369372 self .assertIn ('3 relations created' , res .output )
370373
371- graph = Graph ( graphname , self .redis_con )
374+ graph = self .redis_con . graph ( graphname )
372375 query_result = graph .query ('MATCH (a)-[e]->() RETURN a.numeric, a.mixed, a.bool, e.prop ORDER BY a.numeric, e.prop' )
373376 expected_result = [[0.2 , 'string_prop_1' , True , True ],
374377 [5 , 'notnull' , False , 3.5 ],
@@ -401,7 +404,7 @@ def test07_utf8(self):
401404 assert res .exit_code == 0
402405 assert '9 nodes created' in res .output
403406
404- graph = Graph ( graphname , self .redis_con )
407+ graph = self .redis_con . graph ( graphname )
405408 # The non-ASCII property string must be escaped backticks to parse correctly
406409 query_result = graph .query ("""MATCH (a) RETURN a.`utf8_str_ß` ORDER BY a.id""" )
407410 expected_strs = [['Straße' ],
@@ -439,7 +442,7 @@ def test08_nonstandard_separators(self):
439442 self .assertEqual (res .exit_code , 0 )
440443 self .assertIn ('2 nodes created' , res .output )
441444
442- graph = Graph ( graphname , self .redis_con )
445+ graph = self .redis_con . graph ( graphname )
443446 query_result = graph .query ('MATCH (a) RETURN a.prop_a, a.prop_b, a.prop_c ORDER BY a.prop_a, a.prop_b, a.prop_c' )
444447 expected_result = [['val1' , 5 , True ],
445448 [10.5 , 'a' , False ]]
@@ -465,7 +468,7 @@ def test09_schema(self):
465468 self .assertEqual (res .exit_code , 0 )
466469 self .assertIn ('2 nodes created' , res .output )
467470
468- graph = Graph ( graphname , self .redis_con )
471+ graph = self .redis_con . graph ( graphname )
469472 query_result = graph .query ('MATCH (a) RETURN a.str_col, a.num_col, a.bool_col ORDER BY a.num_col' )
470473 expected_result = [['0' , 0 , True ],
471474 ['1' , 1 , False ]]
@@ -512,7 +515,7 @@ def test11_schema_ignore_columns(self):
512515 self .assertEqual (res .exit_code , 0 )
513516 self .assertIn ('2 nodes created' , res .output )
514517
515- graph = Graph ( graphname , self .redis_con )
518+ graph = self .redis_con . graph ( graphname )
516519 query_result = graph .query ('MATCH (a) RETURN a ORDER BY a.str_col' )
517520
518521 # The nodes should only have the 'str_col' property
@@ -538,7 +541,7 @@ def test12_no_null_values(self):
538541 self .assertEqual (res .exit_code , 0 )
539542 self .assertIn ('2 nodes created' , res .output )
540543
541- graph = Graph ( graphname , self .redis_con )
544+ graph = self .redis_con . graph ( graphname )
542545 query_result = graph .query ('MATCH (a) RETURN a ORDER BY a.str_col' )
543546
544547 # Only the first node should only have the 'mixed_col' property
@@ -580,7 +583,7 @@ def test13_id_namespaces(self):
580583 self .assertIn ('4 nodes created' , res .output )
581584 self .assertIn ("2 relations created" , res .output )
582585
583- graph = Graph ( graphname , self .redis_con )
586+ graph = self .redis_con . graph ( graphname )
584587 query_result = graph .query ('MATCH (src)-[]->(dest) RETURN src.id, src.name, LABELS(src), dest.id, dest.views, LABELS(dest) ORDER BY src.id' )
585588
586589 expected_result = [['0' , 'Jeffrey' , ['User' ], '0' , 20 , ['Post' ]],
@@ -605,7 +608,7 @@ def test14_array_properties_inferred(self):
605608 self .assertEqual (res .exit_code , 0 )
606609 self .assertIn ('2 nodes created' , res .output )
607610
608- graph = Graph ( graphname , self .redis_con )
611+ graph = self .redis_con . graph ( graphname )
609612 query_result = graph .query ('MATCH (a) RETURN a ORDER BY a.str_col' )
610613
611614 node_1 = {'str_col' : 'str1' , 'arr_col' : [1 , 0.2 , 'nested_str' , False ]}
@@ -632,7 +635,7 @@ def test15_array_properties_schema_enforced(self):
632635 self .assertEqual (res .exit_code , 0 )
633636 self .assertIn ('2 nodes created' , res .output )
634637
635- graph = Graph ( graphname , self .redis_con )
638+ graph = self .redis_con . graph ( graphname )
636639 query_result = graph .query ('MATCH (a) RETURN a ORDER BY a.str_col' )
637640
638641 node_1 = {'str_col' : 'str1' , 'arr_col' : [1 , 0.2 , 'nested_str' , False ]}
@@ -707,7 +710,7 @@ def test18_ensure_full_text_index_is_created(self):
707710 self .assertIn ('4 nodes created' , res .output )
708711 self .assertIn ('Indices created: 1' , res .output )
709712
710- graph = Graph ( graphname , self .redis_con )
713+ graph = self .redis_con . graph ( graphname )
711714 query_result = graph .query ("CALL db.idx.fulltext.queryNodes('Monkeys', 'tamarin') YIELD node RETURN node.name" )
712715 expected_result = [['Emperor Tamarin' ], ['Golden Lion Tamarin' ], ['Cotton-top Tamarin' ]]
713716
@@ -748,7 +751,7 @@ def test19_integer_ids(self):
748751 self .assertIn ('4 nodes created' , res .output )
749752 self .assertIn ("2 relations created" , res .output )
750753
751- graph = Graph ( graphname , self .redis_con )
754+ graph = self .redis_con . graph ( graphname )
752755 query_result = graph .query ('MATCH (src)-[]->(dest) RETURN src.id, src.name, LABELS(src), dest.id, dest.views, LABELS(dest) ORDER BY src.id' )
753756
754757 # The IDs of the results should be parsed as integers
0 commit comments