Skip to content
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
25 changes: 23 additions & 2 deletions tests/integration/dbapi/async/V1/test_queries_async.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import math
from datetime import date, datetime
from decimal import Decimal
from random import choice
from typing import Any, Callable, List

from pytest import fixture, mark, raises
Expand Down Expand Up @@ -169,6 +171,24 @@ async def test_select(
)


async def test_select_inf(connection: Connection) -> None:
with connection.cursor() as c:
await c.execute("SELECT 'inf'::float, '-inf'::float")
data = await c.fetchall()
assert len(data) == 1, "Invalid data size returned by fetchall"
assert data[0][0] == float("inf"), "Invalid data returned by fetchall"
assert data[0][1] == float("-inf"), "Invalid data returned by fetchall"


async def test_select_nan(connection: Connection) -> None:
with connection.cursor() as c:
await c.execute("SELECT 'nan'::float, '-nan'::float")
data = await c.fetchall()
assert len(data) == 1, "Invalid data size returned by fetchall"
assert math.isnan(data[0][0]), "Invalid data returned by fetchall"
assert math.isnan(data[0][1]), "Invalid data returned by fetchall"


@mark.slow
@mark.timeout(timeout=1000)
async def test_long_query(
Expand Down Expand Up @@ -485,9 +505,10 @@ async def test_bytea_roundtrip(
async def setup_db(connection_no_engine: Connection, use_db_name: str):
use_db_name = f"{use_db_name}_async"
with connection_no_engine.cursor() as cursor:
await cursor.execute(f"CREATE DATABASE {use_db_name}")
suffix = "".join(choice("0123456789") for _ in range(2))
await cursor.execute(f"CREATE DATABASE {use_db_name}{suffix}")
yield
await cursor.execute(f"DROP DATABASE {use_db_name}")
await cursor.execute(f"DROP DATABASE {use_db_name}{suffix}")


@mark.xfail(reason="USE DATABASE is not yet available in 1.0 Firebolt")
Expand Down
28 changes: 25 additions & 3 deletions tests/integration/dbapi/async/V2/test_queries_async.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import math
from datetime import date, datetime
from decimal import Decimal
from os import environ
from random import choice
from typing import Callable, List

from pytest import fixture, mark, raises
Expand Down Expand Up @@ -100,6 +102,24 @@ async def test_select(
)


async def test_select_inf(connection: Connection) -> None:
with connection.cursor() as c:
await c.execute("SELECT 'inf'::float, '-inf'::float")
data = await c.fetchall()
assert len(data) == 1, "Invalid data size returned by fetchall"
assert data[0][0] == float("inf"), "Invalid data returned by fetchall"
assert data[0][1] == float("-inf"), "Invalid data returned by fetchall"


async def test_select_nan(connection: Connection) -> None:
with connection.cursor() as c:
await c.execute("SELECT 'nan'::float, '-nan'::float")
data = await c.fetchall()
assert len(data) == 1, "Invalid data size returned by fetchall"
assert math.isnan(data[0][0]), "Invalid data returned by fetchall"
assert math.isnan(data[0][1]), "Invalid data returned by fetchall"


@mark.slow
@mark.timeout(timeout=550)
async def test_long_query(
Expand Down Expand Up @@ -408,13 +428,15 @@ async def test_bytea_roundtrip(
), "Invalid bytea data returned after roundtrip"


@fixture(scope="session")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to change this? It's scoped to session if we need to reuse the database, but it's not autoused so only relevant tests will invoke it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixture failed for me since it's using connection_system_engine_no_db, which itself is per test scoped. This causes pytest to fail. I'm not sure how it used to work and if it's related to my changes. I'll take a look

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the error I get locally on the main now: ScopeMismatch: You tried to access the function scoped fixture connection_system_engine_no_db with a session scoped request object, involved factories:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works on github CI because currently the use_database test (which is the one that uses this fixture) is skipped for staging

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. That's annoying :(
My worry here is if we reuse this fixture it might run into race condition when one test is trying to delete a db and another one to use it. Maybe let's add a few random numbers just to be safe?

@fixture
async def setup_db(connection_system_engine_no_db: Connection, use_db_name: str):
use_db_name = use_db_name + "_async"
with connection_system_engine_no_db.cursor() as cursor:
await cursor.execute(f"CREATE DATABASE {use_db_name}")
# randomize the db name to avoid conflicts
suffix = "".join(choice("0123456789") for _ in range(2))
await cursor.execute(f"CREATE DATABASE {use_db_name}{suffix}")
yield
await cursor.execute(f"DROP DATABASE {use_db_name}")
await cursor.execute(f"DROP DATABASE {use_db_name}{suffix}")


@mark.xfail("dev" not in environ[API_ENDPOINT_ENV], reason="Only works on dev")
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/dbapi/sync/V1/test_queries.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
from datetime import date, datetime
from decimal import Decimal
from threading import Thread
Expand Down Expand Up @@ -120,6 +121,24 @@ def test_select(
)


def test_select_inf(connection: Connection) -> None:
with connection.cursor() as c:
c.execute("SELECT 'inf'::float, '-inf'::float")
data = c.fetchall()
assert len(data) == 1, "Invalid data size returned by fetchall"
assert data[0][0] == float("inf"), "Invalid data returned by fetchall"
assert data[0][1] == float("-inf"), "Invalid data returned by fetchall"


def test_select_nan(connection: Connection) -> None:
with connection.cursor() as c:
c.execute("SELECT 'nan'::float, '-nan'::float")
data = c.fetchall()
assert len(data) == 1, "Invalid data size returned by fetchall"
assert math.isnan(data[0][0]), "Invalid data returned by fetchall"
assert math.isnan(data[0][1]), "Invalid data returned by fetchall"


@mark.slow
@mark.timeout(timeout=1000)
def test_long_query(
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/dbapi/sync/V2/test_queries.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
from datetime import date, datetime
from decimal import Decimal
from os import environ
Expand Down Expand Up @@ -106,6 +107,24 @@ def test_select(
)


def test_select_inf(connection: Connection) -> None:
with connection.cursor() as c:
c.execute("SELECT 'inf'::float, '-inf'::float")
data = c.fetchall()
assert len(data) == 1, "Invalid data size returned by fetchall"
assert data[0][0] == float("inf"), "Invalid data returned by fetchall"
assert data[0][1] == float("-inf"), "Invalid data returned by fetchall"


def test_select_nan(connection: Connection) -> None:
with connection.cursor() as c:
c.execute("SELECT 'nan'::float, '-nan'::float")
data = c.fetchall()
assert len(data) == 1, "Invalid data size returned by fetchall"
assert math.isnan(data[0][0]), "Invalid data returned by fetchall"
assert math.isnan(data[0][1]), "Invalid data returned by fetchall"


@mark.slow
@mark.timeout(timeout=550)
def test_long_query(
Expand Down
32 changes: 1 addition & 31 deletions tests/unit/async_db/V1/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from datetime import date, datetime
from json import loads
from re import Pattern, compile
from typing import Dict

import httpx
from pytest import fixture

from firebolt.async_db import ARRAY, DECIMAL, Connection, Cursor, connect
from firebolt.async_db import Connection, Cursor, connect
from firebolt.client import AsyncClientV1 as Client
from firebolt.client.auth.base import Auth
from firebolt.client.auth.username_password import UsernamePassword
Expand Down Expand Up @@ -156,31 +154,3 @@ def check_credentials(
)

return check_credentials


@fixture
def types_map() -> Dict[str, type]:
base_types = {
"int": int,
"long": int,
"float": float,
"double": float,
"text": str,
"date": date,
"pgdate": date,
"timestamp": datetime,
"timestampntz": datetime,
"timestamptz": datetime,
"Nothing null": str,
"Decimal(123, 4)": DECIMAL(123, 4),
"Decimal(38,0)": DECIMAL(38, 0),
# Invalid decimal format
"Decimal(38)": str,
"boolean": bool,
"SomeRandomNotExistingType": str,
"bytea": bytes,
}
array_types = {f"array({k})": ARRAY(v) for k, v in base_types.items()}
nullable_arrays = {f"{k} null": v for k, v in array_types.items()}
nested_arrays = {f"array({k})": ARRAY(v) for k, v in array_types.items()}
return {**base_types, **array_types, **nullable_arrays, **nested_arrays}
35 changes: 1 addition & 34 deletions tests/unit/async_db/V2/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from datetime import date, datetime
from typing import Dict

from pytest import fixture

from firebolt.async_db import ARRAY, DECIMAL, Connection, Cursor, connect
from firebolt.async_db import Connection, Cursor, connect
from firebolt.client.auth import Auth
from tests.unit.db_conftest import * # noqa

Expand Down Expand Up @@ -33,33 +30,3 @@ async def connection(
@fixture
async def cursor(connection: Connection) -> Cursor:
return connection.cursor()


@fixture
def types_map() -> Dict[str, type]:
base_types = {
"int": int,
"long": int,
"float": float,
"double": float,
"text": str,
"date": date,
"date_ext": date,
"pgdate": date,
"timestamp": datetime,
"timestamp_ext": datetime,
"timestampntz": datetime,
"timestamptz": datetime,
"Nothing null": str,
"Decimal(123, 4)": DECIMAL(123, 4),
"Decimal(38,0)": DECIMAL(38, 0),
# Invalid decimal format
"Decimal(38)": str,
"boolean": bool,
"SomeRandomNotExistingType": str,
"bytea": bytes,
}
array_types = {f"array({k})": ARRAY(v) for k, v in base_types.items()}
nullable_arrays = {f"{k} null": v for k, v in array_types.items()}
nested_arrays = {f"array({k})": ARRAY(v) for k, v in array_types.items()}
return {**base_types, **array_types, **nullable_arrays, **nested_arrays}
Loading