Skip to content
65 changes: 5 additions & 60 deletions tests/pyathena/aio/pandas/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
from pyathena.aio.pandas.cursor import AioPandasCursor
from pyathena.error import ProgrammingError
from pyathena.model import AthenaQueryExecution
from pyathena.pandas.result_set import AthenaPandasResultSet
from pyathena.util import RetryConfig
from tests import ENV
from tests.pyathena.aio.conftest import _aio_connect


class TestAioPandasCursor:
Expand All @@ -35,17 +32,15 @@ async def test_binary_null_vs_empty(self, aio_pandas_cursor):
]

async def test_fetchone(self, aio_pandas_cursor):
await aio_pandas_cursor.execute("SELECT * FROM one_row")
assert await aio_pandas_cursor.execute("SELECT * FROM one_row") is aio_pandas_cursor
assert aio_pandas_cursor.description == [
("number_of_rows", "integer", None, None, 10, 0, "UNKNOWN")
]
assert aio_pandas_cursor.rownumber == 0
assert await aio_pandas_cursor.fetchone() == (1,)
assert aio_pandas_cursor.rownumber == 1
assert await aio_pandas_cursor.fetchone() is None

async def test_fetchmany(self, aio_pandas_cursor):
await aio_pandas_cursor.execute("SELECT * FROM many_rows LIMIT 15")
assert len(await aio_pandas_cursor.fetchmany(10)) == 10
assert len(await aio_pandas_cursor.fetchmany(10)) == 5

async def test_fetchall(self, aio_pandas_cursor):
await aio_pandas_cursor.execute("SELECT * FROM one_row")
assert await aio_pandas_cursor.fetchall() == [(1,)]
Expand All @@ -59,10 +54,6 @@ async def test_as_pandas(self, aio_pandas_cursor):
assert df.columns.tolist() == ["number_of_rows"]
assert df["number_of_rows"].iloc[0] == 1

async def test_execute_returns_self(self, aio_pandas_cursor):
result = await aio_pandas_cursor.execute("SELECT * FROM one_row")
assert result is aio_pandas_cursor

async def test_no_result_set_raises(self, aio_pandas_cursor):
with pytest.raises(ProgrammingError):
await aio_pandas_cursor.fetchone()
Expand All @@ -73,73 +64,27 @@ async def test_no_result_set_raises(self, aio_pandas_cursor):
with pytest.raises(ProgrammingError):
aio_pandas_cursor.as_pandas()

async def test_context_manager(self):
from pyathena.aio.pandas.cursor import AioPandasCursor

conn = await _aio_connect(schema_name=ENV.schema, cursor_class=AioPandasCursor)
try:
async with conn.cursor() as cursor:
await cursor.execute("SELECT * FROM one_row")
assert await cursor.fetchone() == (1,)
finally:
conn.close()

async def test_arraysize_default(self, aio_pandas_cursor):
assert aio_pandas_cursor.arraysize == AthenaPandasResultSet.DEFAULT_FETCH_SIZE

async def test_invalid_arraysize(self, aio_pandas_cursor):
aio_pandas_cursor.arraysize = 10000
assert aio_pandas_cursor.arraysize == 10000
with pytest.raises(ProgrammingError):
aio_pandas_cursor.arraysize = -1

async def test_description(self, aio_pandas_cursor):
await aio_pandas_cursor.execute("SELECT CAST(1 AS INT) AS foobar FROM one_row")
assert await aio_pandas_cursor.fetchall() == [(1,)]
assert aio_pandas_cursor.description == [
("foobar", "integer", None, None, 10, 0, "UNKNOWN")
]

async def test_description_initial(self, aio_pandas_cursor):
assert aio_pandas_cursor.description is None

async def test_cancel_initial(self, aio_pandas_cursor):
with pytest.raises(ProgrammingError):
await aio_pandas_cursor.cancel()

async def test_executemany_fetch(self, aio_pandas_cursor):
await aio_pandas_cursor.executemany(
"SELECT %(x)d FROM one_row", [{"x": i} for i in range(1, 2)]
)
with pytest.raises(ProgrammingError):
await aio_pandas_cursor.fetchall()
with pytest.raises(ProgrammingError):
await aio_pandas_cursor.fetchmany()
with pytest.raises(ProgrammingError):
await aio_pandas_cursor.fetchone()
with pytest.raises(ProgrammingError):
aio_pandas_cursor.as_pandas()

@pytest.mark.parametrize(
"aio_pandas_cursor",
[{"cursor_kwargs": {"unload": True}}],
indirect=["aio_pandas_cursor"],
)
async def test_fetchone_unload(self, aio_pandas_cursor):
await aio_pandas_cursor.execute("SELECT * FROM one_row")
assert aio_pandas_cursor.as_pandas()["number_of_rows"].tolist() == [1]
assert await aio_pandas_cursor.fetchone() == (1,)
assert await aio_pandas_cursor.fetchone() is None

@pytest.mark.parametrize(
"aio_pandas_cursor",
[{"cursor_kwargs": {"unload": True}}],
indirect=["aio_pandas_cursor"],
)
async def test_as_pandas_unload(self, aio_pandas_cursor):
await aio_pandas_cursor.execute("SELECT * FROM one_row")
df = aio_pandas_cursor.as_pandas()
assert len(df) == 1

@pytest.mark.parametrize(
"execute_kwargs",
[
Expand Down
Loading
Loading