Skip to content

Commit

Permalink
fix(bindings/python): behave test for cursor (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc authored Jan 6, 2025
1 parent 7d49de3 commit 7ffc503
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/bindings.python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,15 @@ jobs:
run: |
pip install behave
pip install artifacts/*.whl
- name: Test
- name: Test AsyncIO
working-directory: bindings/python
run: behave tests/*
run: behave tests/asyncio
- name: Test Blocking
working-directory: bindings/python
run: behave tests/blocking
- name: Test Cursor
working-directory: bindings/python
run: behave tests/cursor

publish:
if: startsWith(github.ref, 'refs/tags/v')
Expand Down
5 changes: 4 additions & 1 deletion bindings/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,8 @@ cd bindings/python
uv sync
source .venv/bin/activate
maturin develop --uv
behave tests/*

behave tests/asyncio
behave tests/blocking
behave tests/cursor
```
20 changes: 10 additions & 10 deletions bindings/python/tests/cursor/steps/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,40 @@ def _(context):
@then("Select string {input} should be equal to {output}")
def _(context, input, output):
context.cursor.execute(f"SELECT '{input}'")
row = context.cursor.fetch_one()
row = context.cursor.fetchone()
assert output == row[0], f"output: {output}"


@then("Select types should be expected native types")
async def _(context):
# Binary
context.cursor.execute("select to_binary('xyz')")
row = context.cursor.fetch_one()
row = context.cursor.fetchone()
assert row[0] == b"xyz", f"Binary: {row.values()}"

# Decimal
context.cursor.execute("SELECT 15.7563::Decimal(8,4), 2.0+3.0")
row = context.cursor.fetch_one()
row = context.cursor.fetchone()
assert row.values() == (
Decimal("15.7563"),
Decimal("5.0"),
), f"Decimal: {row.values()}"

# Array
context.cursor.execute("select [10::Decimal(15,2), 1.1+2.3]")
row = context.cursor.fetch_one()
row = context.cursor.fetchone()
assert row.values() == (
[Decimal("10.00"), Decimal("3.40")],
), f"Array: {row.values()}"

# Map
context.cursor.execute("select {'xx':to_date('2020-01-01')}")
row = context.cursor.fetch_one()
row = context.cursor.fetchone()
assert row.values() == ({"xx": date(2020, 1, 1)},), f"Map: {row.values()}"

# Tuple
context.cursor.execute("select (10, '20', to_datetime('2024-04-16 12:34:56.789'))")
row = context.cursor.fetch_one()
row = context.cursor.fetchone()
assert row.values() == (
(10, "20", datetime(2024, 4, 16, 12, 34, 56, 789000)),
), f"Tuple: {row.values()}"
Expand All @@ -93,7 +93,7 @@ async def _(context):
@then("Select numbers should iterate all rows")
def _(context):
context.cursor.execute("SELECT number FROM numbers(5)")
rows = context.cursor.fetch_all()
rows = context.cursor.fetchall()
ret = []
for row in rows:
ret.append(row[0])
Expand All @@ -103,7 +103,7 @@ def _(context):

@then("Insert and Select should be equal")
def _(context):
context.cursor.exec(
context.cursor.execute(
"""
INSERT INTO test VALUES
(-1, 1, 1.0, '1', '1', '2011-03-06', '2011-03-06 06:20:00'),
Expand All @@ -112,7 +112,7 @@ def _(context):
"""
)
context.cursor.execute("SELECT * FROM test")
rows = context.cursor.fetch_all()
rows = context.cursor.fetchall()
ret = []
for row in rows:
ret.append(row.values())
Expand All @@ -135,7 +135,7 @@ def _(context):
assert count == 3, f"count: {count}"

context.cursor.execute("SELECT * FROM test")
rows = context.cursor.fetch_all()
rows = context.cursor.fetchall()
ret = []
for row in rows:
ret.append(row.values())
Expand Down
4 changes: 3 additions & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ test-bendsql: up
cd .. && ./cli/test.sh flight

test-bindings-python: up
cd ../bindings/python && behave tests/*
cd ../bindings/python && behave tests/asyncio
cd ../bindings/python && behave tests/blocking
cd ../bindings/python && behave tests/cursor

test-bindings-nodejs: up
cd ../bindings/nodejs && pnpm run test
Expand Down

0 comments on commit 7ffc503

Please sign in to comment.