From a2b99e001547b611d80bfb580226ac1dad59d2f0 Mon Sep 17 00:00:00 2001 From: Yang Xiufeng Date: Tue, 13 Jan 2026 16:55:34 +0800 Subject: [PATCH] ci: update tests --- .../python/tests/asyncio/steps/binding.py | 45 ++++++++++++------- .../python/tests/blocking/steps/binding.py | 39 ++++++++++------ bindings/python/tests/cursor/steps/binding.py | 37 ++++++++------- 3 files changed, 73 insertions(+), 48 deletions(-) diff --git a/bindings/python/tests/asyncio/steps/binding.py b/bindings/python/tests/asyncio/steps/binding.py index eddc6296..200eb5f3 100644 --- a/bindings/python/tests/asyncio/steps/binding.py +++ b/bindings/python/tests/asyncio/steps/binding.py @@ -19,6 +19,9 @@ from decimal import Decimal from behave import given, when, then +import unittest + +tc = unittest.TestCase() os.environ["DATABEND_DRIVER_HEARTBEAT_INTERVAL_SECONDS"] = "1" os.environ["RUST_LOG"] = "warn,databend_driver=debug,databend_client=debug" @@ -123,23 +126,28 @@ async def _(context): Decimal("5.0"), ), f"Decimal: {row.values()}" - # Array - row = await context.conn.query_row("select [10::Decimal(15,2), 1.1+2.3]") - assert row.values() == ([Decimal("10.00"), Decimal("3.40")],), ( - f"Array: {row.values()}" - ) + if DRIVER_VERSION >= (0, 33, 1): # quote change to `"` + # Array + row = await context.conn.query_row("select [10::Decimal(15,2), 1.1+2.3]") + assert row.values() == ([Decimal("10.00"), Decimal("3.40")],), ( + f"Array: {row.values()}" + ) - # Map - row = await context.conn.query_row("select {'xx':to_date('2020-01-01')}") - assert row.values() == ({"xx": date(2020, 1, 1)},), f"Map: {row.values()}" + # Map + row = await context.conn.query_row("select {'xx':to_date('2020-01-01')}") + assert row.values() == ({"xx": date(2020, 1, 1)},), f"Map: {row.values()}" - # Tuple - row = await context.conn.query_row( - "select (10, '20', to_datetime('2024-04-16 12:34:56.789'))" - ) - assert row.values() == ( - (10, "20", datetime(2024, 4, 16, 12, 34, 56, 789000, tzinfo=default_tzinfo)), - ), f"Tuple: {row.values()}" + # Tuple + row = await context.conn.query_row( + "select (10, '20', to_datetime('2024-04-16 12:34:56.789'))" + ) + assert row.values() == ( + ( + 10, + "20", + datetime(2024, 4, 16, 12, 34, 56, 789000, tzinfo=default_tzinfo), + ), + ), f"Tuple: {row.values()}" @then("Select numbers should iterate all rows") @@ -267,6 +275,9 @@ async def test_load_file(context, load_method): rows = await context.conn.query_iter("SELECT * FROM test1") ret = [row.values() for row in rows] + + quoted_empty = "" if DB_VERSION >= (1, 2, 866) else None + expected = [ ( -1, @@ -282,7 +293,7 @@ async def test_load_file(context, load_method): 2, 2.0, '"', - None, + quoted_empty, date(2012, 5, 31), datetime(2012, 5, 31, 11, 20, tzinfo=default_tzinfo), ), @@ -296,7 +307,7 @@ async def test_load_file(context, load_method): datetime(2016, 4, 4, 11, 30, tzinfo=default_tzinfo), ), ] - assert ret == expected, f"{load_method} ret: {ret}" + tc.assertEqual(ret, expected, load_method) @then("Load file with Stage and Select should be equal") diff --git a/bindings/python/tests/blocking/steps/binding.py b/bindings/python/tests/blocking/steps/binding.py index fd8f6f2b..bb3dcc3f 100644 --- a/bindings/python/tests/blocking/steps/binding.py +++ b/bindings/python/tests/blocking/steps/binding.py @@ -18,6 +18,9 @@ from decimal import Decimal import time from time import sleep +import unittest + +tc = unittest.TestCase() from behave import given, when, then @@ -125,18 +128,6 @@ def _(context): f"Array: {row.values()}" ) - # Map - row = context.conn.query_row("select {'xx':to_date('2020-01-01')}") - assert row.values() == ({"xx": date(2020, 1, 1)},), f"Map: {row.values()}" - - # Tuple - row = context.conn.query_row( - "select (10, '20', to_datetime('2024-04-16 12:34:56.789'))" - ) - assert row.values() == ( - (10, "20", datetime(2024, 4, 16, 12, 34, 56, 789000, tzinfo=default_tzinfo)), - ), f"Tuple: {row.values()}" - import sys if ( @@ -198,6 +189,23 @@ def _(context): ) assert row.values()[0] == "POINT(60 37)", f"geography: {row.values()}" + if DRIVER_VERSION >= (0, 33, 1): # quote change to `"` + # Map + row = context.conn.query_row("select {'xx':to_date('2020-01-01')}") + assert row.values() == ({"xx": date(2020, 1, 1)},), f"Map: {row.values()}" + + # Tuple + row = context.conn.query_row( + "select (10, '20', to_datetime('2024-04-16 12:34:56.789'))" + ) + assert row.values() == ( + ( + 10, + "20", + datetime(2024, 4, 16, 12, 34, 56, 789000, tzinfo=default_tzinfo), + ), + ), f"Tuple: {row.values()}" + @then("Select numbers should iterate all rows") def _(context): @@ -322,6 +330,9 @@ def test_load_file(context, load_method): rows = context.conn.query_iter("SELECT * FROM test1") ret = [row.values() for row in rows] + + quoted_empty = "" if DB_VERSION >= (1, 2, 866) else None + expected = [ ( -1, @@ -337,7 +348,7 @@ def test_load_file(context, load_method): 2, 2.0, '"', - None, + quoted_empty, date(2012, 5, 31), datetime(2012, 5, 31, 11, 20, tzinfo=default_tzinfo), ), @@ -351,7 +362,7 @@ def test_load_file(context, load_method): datetime(2016, 4, 4, 11, 30, tzinfo=default_tzinfo), ), ] - assert ret == expected, f"{load_method} ret: {ret}" + tc.assertEqual(ret, expected, load_method) @then("Load file with Stage and Select should be equal") diff --git a/bindings/python/tests/cursor/steps/binding.py b/bindings/python/tests/cursor/steps/binding.py index c5e7a2bc..cdeb05fc 100644 --- a/bindings/python/tests/cursor/steps/binding.py +++ b/bindings/python/tests/cursor/steps/binding.py @@ -139,23 +139,26 @@ def _(context): expected = ([Decimal("10.00"), Decimal("3.40")],) assert row.values() == expected, f"Array: {row.values()}" - # Map - context.cursor.execute("select {'xx':to_date('2020-01-01')}") - row = context.cursor.fetchone() - expected = ({"xx": date(2020, 1, 1)},) - assert row.values() == expected, f"Map: {row.values()}" - - # Tuple - context.cursor.execute("select (10, '20', to_datetime('2024-04-16 12:34:56.789'))") - row = context.cursor.fetchone() - expected = ( - ( - 10, - "20", - datetime(2024, 4, 16, 12, 34, 56, 789000, tzinfo=default_tzinfo), - ), - ) - assert row.values() == expected, f"Tuple: {row.values()}" + if DRIVER_VERSION >= (0, 33, 1): # quote change to `"` + # Map + context.cursor.execute("select {'xx':to_date('2020-01-01')}") + row = context.cursor.fetchone() + expected = ({"xx": date(2020, 1, 1)},) + assert row.values() == expected, f"Map: {row.values()}" + + # Tuple + context.cursor.execute( + "select (10, '20', to_datetime('2024-04-16 12:34:56.789'))" + ) + row = context.cursor.fetchone() + expected = ( + ( + 10, + "20", + datetime(2024, 4, 16, 12, 34, 56, 789000, tzinfo=default_tzinfo), + ), + ) + assert row.values() == expected, f"Tuple: {row.values()}" @then("Select numbers should iterate all rows")