5
5
import csv
6
6
import redis
7
7
import unittest
8
- from redisgraph import Graph
8
+ from redis import Redis
9
9
from click .testing import CliRunner
10
10
from redisgraph_bulk_loader .bulk_insert import bulk_insert
11
11
@@ -39,10 +39,13 @@ def setUpClass(cls):
39
39
@classmethod
40
40
def tearDownClass (cls ):
41
41
"""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
46
49
cls .redis_con .flushall ()
47
50
48
51
def validate_exception (self , res , expected_msg ):
@@ -89,7 +92,7 @@ def test01_social_graph(self):
89
92
self .assertIn (visited_count + " relations created for type 'VISITED'" , res .output )
90
93
91
94
# Open the constructed graph.
92
- graph = Graph ('social' , self . redis_con )
95
+ graph = self . redis_con . graph ('social' )
93
96
query_result = graph .query ("MATCH (p:Person) RETURN p.name, p.age, p.gender, p.status ORDER BY p.name" )
94
97
# Verify that the Person label exists, has the correct attributes, and is properly populated.
95
98
expected_result = [['Ailon Velger' , 32 , 'male' , 'married' ],
@@ -207,7 +210,7 @@ def test02_private_identifiers(self):
207
210
self .assertIn ('3 nodes created' , res .output )
208
211
self .assertIn ('2 relations created' , res .output )
209
212
210
- tmp_graph = Graph ( graphname , self .redis_con )
213
+ tmp_graph = self .redis_con . graph ( graphname )
211
214
# The field "_identifier" should not be a property in the graph
212
215
query_result = tmp_graph .query ('MATCH (a) RETURN a' )
213
216
@@ -280,8 +283,8 @@ def test04_batched_build(self):
280
283
self .assertIn (knows_count + " relations created for type 'KNOWS'" , res .output )
281
284
self .assertIn (visited_count + " relations created for type 'VISITED'" , res .output )
282
285
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 )
285
288
286
289
# Newly-created graph should be identical to graph created in single bulk command
287
290
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):
368
371
self .assertIn ('3 nodes created' , res .output )
369
372
self .assertIn ('3 relations created' , res .output )
370
373
371
- graph = Graph ( graphname , self .redis_con )
374
+ graph = self .redis_con . graph ( graphname )
372
375
query_result = graph .query ('MATCH (a)-[e]->() RETURN a.numeric, a.mixed, a.bool, e.prop ORDER BY a.numeric, e.prop' )
373
376
expected_result = [[0.2 , 'string_prop_1' , True , True ],
374
377
[5 , 'notnull' , False , 3.5 ],
@@ -401,7 +404,7 @@ def test07_utf8(self):
401
404
assert res .exit_code == 0
402
405
assert '9 nodes created' in res .output
403
406
404
- graph = Graph ( graphname , self .redis_con )
407
+ graph = self .redis_con . graph ( graphname )
405
408
# The non-ASCII property string must be escaped backticks to parse correctly
406
409
query_result = graph .query ("""MATCH (a) RETURN a.`utf8_str_ß` ORDER BY a.id""" )
407
410
expected_strs = [['Straße' ],
@@ -439,7 +442,7 @@ def test08_nonstandard_separators(self):
439
442
self .assertEqual (res .exit_code , 0 )
440
443
self .assertIn ('2 nodes created' , res .output )
441
444
442
- graph = Graph ( graphname , self .redis_con )
445
+ graph = self .redis_con . graph ( graphname )
443
446
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' )
444
447
expected_result = [['val1' , 5 , True ],
445
448
[10.5 , 'a' , False ]]
@@ -465,7 +468,7 @@ def test09_schema(self):
465
468
self .assertEqual (res .exit_code , 0 )
466
469
self .assertIn ('2 nodes created' , res .output )
467
470
468
- graph = Graph ( graphname , self .redis_con )
471
+ graph = self .redis_con . graph ( graphname )
469
472
query_result = graph .query ('MATCH (a) RETURN a.str_col, a.num_col, a.bool_col ORDER BY a.num_col' )
470
473
expected_result = [['0' , 0 , True ],
471
474
['1' , 1 , False ]]
@@ -512,7 +515,7 @@ def test11_schema_ignore_columns(self):
512
515
self .assertEqual (res .exit_code , 0 )
513
516
self .assertIn ('2 nodes created' , res .output )
514
517
515
- graph = Graph ( graphname , self .redis_con )
518
+ graph = self .redis_con . graph ( graphname )
516
519
query_result = graph .query ('MATCH (a) RETURN a ORDER BY a.str_col' )
517
520
518
521
# The nodes should only have the 'str_col' property
@@ -538,7 +541,7 @@ def test12_no_null_values(self):
538
541
self .assertEqual (res .exit_code , 0 )
539
542
self .assertIn ('2 nodes created' , res .output )
540
543
541
- graph = Graph ( graphname , self .redis_con )
544
+ graph = self .redis_con . graph ( graphname )
542
545
query_result = graph .query ('MATCH (a) RETURN a ORDER BY a.str_col' )
543
546
544
547
# Only the first node should only have the 'mixed_col' property
@@ -580,7 +583,7 @@ def test13_id_namespaces(self):
580
583
self .assertIn ('4 nodes created' , res .output )
581
584
self .assertIn ("2 relations created" , res .output )
582
585
583
- graph = Graph ( graphname , self .redis_con )
586
+ graph = self .redis_con . graph ( graphname )
584
587
query_result = graph .query ('MATCH (src)-[]->(dest) RETURN src.id, src.name, LABELS(src), dest.id, dest.views, LABELS(dest) ORDER BY src.id' )
585
588
586
589
expected_result = [['0' , 'Jeffrey' , ['User' ], '0' , 20 , ['Post' ]],
@@ -605,7 +608,7 @@ def test14_array_properties_inferred(self):
605
608
self .assertEqual (res .exit_code , 0 )
606
609
self .assertIn ('2 nodes created' , res .output )
607
610
608
- graph = Graph ( graphname , self .redis_con )
611
+ graph = self .redis_con . graph ( graphname )
609
612
query_result = graph .query ('MATCH (a) RETURN a ORDER BY a.str_col' )
610
613
611
614
node_1 = {'str_col' : 'str1' , 'arr_col' : [1 , 0.2 , 'nested_str' , False ]}
@@ -632,7 +635,7 @@ def test15_array_properties_schema_enforced(self):
632
635
self .assertEqual (res .exit_code , 0 )
633
636
self .assertIn ('2 nodes created' , res .output )
634
637
635
- graph = Graph ( graphname , self .redis_con )
638
+ graph = self .redis_con . graph ( graphname )
636
639
query_result = graph .query ('MATCH (a) RETURN a ORDER BY a.str_col' )
637
640
638
641
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):
707
710
self .assertIn ('4 nodes created' , res .output )
708
711
self .assertIn ('Indices created: 1' , res .output )
709
712
710
- graph = Graph ( graphname , self .redis_con )
713
+ graph = self .redis_con . graph ( graphname )
711
714
query_result = graph .query ("CALL db.idx.fulltext.queryNodes('Monkeys', 'tamarin') YIELD node RETURN node.name" )
712
715
expected_result = [['Emperor Tamarin' ], ['Golden Lion Tamarin' ], ['Cotton-top Tamarin' ]]
713
716
@@ -748,7 +751,7 @@ def test19_integer_ids(self):
748
751
self .assertIn ('4 nodes created' , res .output )
749
752
self .assertIn ("2 relations created" , res .output )
750
753
751
- graph = Graph ( graphname , self .redis_con )
754
+ graph = self .redis_con . graph ( graphname )
752
755
query_result = graph .query ('MATCH (src)-[]->(dest) RETURN src.id, src.name, LABELS(src), dest.id, dest.views, LABELS(dest) ORDER BY src.id' )
753
756
754
757
# The IDs of the results should be parsed as integers
0 commit comments