Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pytest cleanup #2493

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ nodejstest: nodejs
npm test

pytest: python
cd tools/python_api/test
python3 -m pytest -v test_main.py
cmake -E env PYTHONPATH=tools/python_api/build python3 -m pytest -v tools/python_api/test

rusttest: rust
cd tools/rust_api
Expand Down
31 changes: 15 additions & 16 deletions tools/python_api/test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os
import sys
import pytest
import shutil
from test_helper import KUZU_ROOT

sys.path.append('../build/')
import kuzu


Expand All @@ -12,44 +11,44 @@ def init_npy(conn):
'create node table npyoned (i64 INT64,i32 INT32,i16 INT16,f64 DOUBLE,f32 FLOAT, PRIMARY KEY(i64));'
)
conn.execute(
'copy npyoned from ("../../../dataset/npy-1d/one_dim_int64.npy", "../../../dataset/npy-1d/one_dim_int32.npy", '
' "../../../dataset/npy-1d/one_dim_int16.npy", "../../../dataset/npy-1d/one_dim_double.npy", '
'"../../../dataset/npy-1d/one_dim_float.npy") by column;'
f'copy npyoned from ("{KUZU_ROOT}/dataset/npy-1d/one_dim_int64.npy", "{KUZU_ROOT}/dataset/npy-1d/one_dim_int32.npy", '
f' "{KUZU_ROOT}/dataset/npy-1d/one_dim_int16.npy", "{KUZU_ROOT}/dataset/npy-1d/one_dim_double.npy", '
f'"{KUZU_ROOT}/dataset/npy-1d/one_dim_float.npy") by column;'
)
conn.execute(
'create node table npytwod (id INT64, i64 INT64[3], i32 INT32[3], i16 INT16[3], f64 DOUBLE[3], f32 FLOAT[3],'
'PRIMARY KEY(id));'
)
conn.execute(
'copy npytwod from ("../../../dataset/npy-2d/id_int64.npy", "../../../dataset/npy-2d/two_dim_int64.npy", '
'"../../../dataset/npy-2d/two_dim_int32.npy", "../../../dataset/npy-2d/two_dim_int16.npy", '
' "../../../dataset/npy-2d/two_dim_double.npy", "../../../dataset/npy-2d/two_dim_float.npy") by column;'
f'copy npytwod from ("{KUZU_ROOT}/dataset/npy-2d/id_int64.npy", "{KUZU_ROOT}/dataset/npy-2d/two_dim_int64.npy", '
f'"{KUZU_ROOT}/dataset/npy-2d/two_dim_int32.npy", "{KUZU_ROOT}/dataset/npy-2d/two_dim_int16.npy", '
f' "{KUZU_ROOT}/dataset/npy-2d/two_dim_double.npy", "{KUZU_ROOT}/dataset/npy-2d/two_dim_float.npy") by column;'
)


def init_tensor(conn):
conn.execute('create node table tensor (ID INT64, boolTensor BOOLEAN[], doubleTensor DOUBLE[][], '
'intTensor INT64[][][], oneDimInt INT64, PRIMARY KEY (ID));')
conn.execute(
'COPY tensor FROM "../../../dataset/tensor-list/vTensor.csv" (HEADER=true)')
f'COPY tensor FROM "{KUZU_ROOT}/dataset/tensor-list/vTensor.csv" (HEADER=true)')


def init_long_str(conn):
conn.execute(
"CREATE NODE TABLE personLongString (name STRING, spouse STRING, PRIMARY KEY(name))")
f"CREATE NODE TABLE personLongString (name STRING, spouse STRING, PRIMARY KEY(name))")
conn.execute(
'COPY personLongString FROM "../../../dataset/long-string-pk-tests/vPerson.csv"')
f'COPY personLongString FROM "{KUZU_ROOT}/dataset/long-string-pk-tests/vPerson.csv"')
conn.execute(
"CREATE REL TABLE knowsLongString (FROM personLongString TO personLongString, MANY_MANY)")
f"CREATE REL TABLE knowsLongString (FROM personLongString TO personLongString, MANY_MANY)")
conn.execute(
'COPY knowsLongString FROM "../../../dataset/long-string-pk-tests/eKnows.csv"')
f'COPY knowsLongString FROM "{KUZU_ROOT}/dataset/long-string-pk-tests/eKnows.csv"')


def init_tinysnb(conn):
tiny_snb_path = os.path.abspath(
os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"../../../dataset/tinysnb")
f"{KUZU_ROOT}/dataset/tinysnb")
)
schema_path = os.path.join(tiny_snb_path, "schema.cypher")
with open(schema_path, "r") as f:
Expand All @@ -61,7 +60,7 @@ def init_tinysnb(conn):
with open(copy_path, "r") as f:
for line in f.readlines():
line = line.strip()
line = line.replace("dataset/tinysnb", "../../../dataset/tinysnb")
line = line.replace("dataset/tinysnb", f"{KUZU_ROOT}/dataset/tinysnb")
if line:
conn.execute(line)

Expand All @@ -71,7 +70,7 @@ def init_movie_serial(conn):
"create node table moviesSerial (ID SERIAL, name STRING, length INT32, note STRING, PRIMARY KEY (ID));"
)
conn.execute(
'copy moviesSerial from "../../../dataset/tinysnb-serial/vMovies.csv"'
f'copy moviesSerial from "{KUZU_ROOT}/dataset/tinysnb-serial/vMovies.csv"'
)


Expand Down
2 changes: 0 additions & 2 deletions tools/python_api/test/test_arrow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import sys
import time

sys.path.append('../build/')
import kuzu
import pyarrow as pa
import datetime
Expand Down
1 change: 0 additions & 1 deletion tools/python_api/test/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys
from decimal import Decimal

sys.path.append('../build/')
import kuzu
from pandas import Timestamp, Timedelta, isna

Expand Down
1 change: 0 additions & 1 deletion tools/python_api/test/test_exception.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
import sys
sys.path.append('../build/')
import kuzu


Expand Down
8 changes: 8 additions & 0 deletions tools/python_api/test/test_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pathlib import Path
import sys

KUZU_ROOT = Path(__file__).parent.parent.parent.parent

if sys.platform == "win32":
# \ in paths is not supported by kuzu's parser
KUZU_ROOT=str(KUZU_ROOT).replace("\\", "/")
20 changes: 0 additions & 20 deletions tools/python_api/test/test_main.py

This file was deleted.

5 changes: 2 additions & 3 deletions tools/python_api/test/test_query_result_close.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import subprocess
import sys
from test_helper import KUZU_ROOT


def test_query_result_close(get_tmp_path):
code = [
'import sys',
'sys.path.append("../build/")',
'import kuzu',
# Note: Windows paths include backslashes, which need to be raw strings or escaped.
'db = kuzu.Database(r"' + get_tmp_path + '")',
Expand All @@ -15,7 +14,7 @@ def test_query_result_close(get_tmp_path):
birthdate DATE, registerTime TIMESTAMP, lastJobDuration INTERVAL,\
workedHours INT64[], usedNames STRING[], courseScoresPerTerm INT64[][], grades INT64[4], height float, \
PRIMARY KEY (ID))\')',
'conn.execute(\'COPY person FROM \"../../../dataset/tinysnb/vPerson.csv\" (HEADER=true)\')',
f'conn.execute(\'COPY person FROM \"{KUZU_ROOT}/dataset/tinysnb/vPerson.csv\" (HEADER=true)\')',
'result = conn.execute("MATCH (a:person) WHERE a.ID = 0 RETURN a.isStudent;")',
# 'result.close()',
]
Expand Down
2 changes: 0 additions & 2 deletions tools/python_api/test/test_scan_pandas.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import sys
import numpy as np
import pandas as pd
import datetime
import pytest
import re

sys.path.append('../build/')
import kuzu


Expand Down
4 changes: 2 additions & 2 deletions tools/python_api/test/test_torch_geometric_remote_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random
import sys

sys.path.append('../build/')
from test_helper import KUZU_ROOT
import kuzu

TINY_SNB_KNOWS_GROUND_TRUTH = {
Expand Down Expand Up @@ -103,7 +103,7 @@ def test_remote_backend_20k(establish_connection):
_, db = establish_connection
conn = kuzu.Connection(db, num_threads=1)
conn.execute('create node table npy20k (id INT64,f32 FLOAT[10],PRIMARY KEY(id));')
conn.execute('copy npy20k from ("../../../dataset/npy-20k/id_int64.npy", "../../../dataset/npy-20k/two_dim_float.npy") by column;')
conn.execute(f'copy npy20k from ("{KUZU_ROOT}/dataset/npy-20k/id_int64.npy", "{KUZU_ROOT}/dataset/npy-20k/two_dim_float.npy") by column;')
del conn
fs, _ = db.get_torch_geometric_remote_backend(8)
for i in range(20000):
Expand Down