Skip to content

Commit

Permalink
[WIP] test LOAD CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
swilly22 committed Mar 17, 2024
1 parent 38ecd52 commit 6092938
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/flow/test_load_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from common import *
import re

GRAPH_ID = "load_csv"

class testLoadCSV():
def __init__(self):
self.env, self.db = Env()
self.graph = self.db.select_graph(GRAPH_ID)

def test01_invalid_call(self):
queries = ["LOAD CSV FROM a AS row RETURN row",
"LOAD CSV FROM 2 AS row RETURN row",
"LOAD CSV FROM $arr AS row RETURN row",
"WITH 2 AS x LOAD CSV FROM x AS row RETURN row"]

for q in queries:
try:
self.graph.query(q, {'arr': []})
self.env.assertFalse(True)
except Exception as e:
self.env.assertEquals(str(e), "path to CSV must be a string")

def test02_project_csv_rows(self):
# project all rows in a CSV file
q = """LOAD CSV FROM 'data.csv' AS row
RETURN row"""

result = self.graph.query(q).result_set
self.env.assertEquals(result[0][0], ['AAA', 'BB', 'C'])

def test03_load_csv_multiple_times(self):
# project the same CSV multiple times
q = """UNWIND [1,2,3] AS x
LOAD CSV FROM 'data.csv' AS row
RETURN x, row
ORDER BY x"""

result = self.graph.query(q).result_set
self.env.assertEquals(result[0], [1, ['AAA', 'BB', 'C']])
self.env.assertEquals(result[1], [2, ['AAA', 'BB', 'C']])
self.env.assertEquals(result[2], [3, ['AAA', 'BB', 'C']])

def test04_dynamic_csv_path(self):
# project all rows in a CSV file
q = """UNWIND ['a', 'b'] AS x
LOAD CSV FROM x + '.csv' AS row
RETURN x, row
ORDER BY x"""

result = self.graph.query(q).result_set
self.env.assertEquals(result[0], ['a', ['AAA', 'BB', 'C']])
self.env.assertEquals(result[1], ['b', ['AAA', 'BB', 'C']])

0 comments on commit 6092938

Please sign in to comment.