diff --git a/NOTICE b/NOTICE index 1e9177b67..85aa79588 100644 --- a/NOTICE +++ b/NOTICE @@ -28,12 +28,14 @@ Parts that remain recognizable in PyAthena: (pyhive/sqlalchemy_presto.py). - tests/pyathena/test_cursor.py: test cases including the escaping input of `test_escape`, the Unicode input of `test_unicode`, and the NULL patterns of - `test_null` follow PyHive's pyhive/tests/dbapi_test_case.py. + `test_null` follow PyHive's pyhive/tests/dbapi_test_case.py. The cursor + tests of the other cursor classes under tests/pyathena/ repeat some of + these test cases, such as `test_arraysize` and `test_fetchone`. - tests/pyathena/sqlalchemy/test_base.py: test cases including `test_unicode`, `test_char_length`, and `test_reflect_no_such_table` follow PyHive's pyhive/tests/sqlalchemy_test_case.py. - tests/pyathena/aio/sqlalchemy/test_base.py ports `test_unicode` to the - asynchronous dialect. + tests/pyathena/aio/sqlalchemy/test_base.py ports `test_basic_query` and + `test_reflect_schemas` to the asynchronous dialect. Parts that have since been replaced: diff --git a/tests/pyathena/aio/pandas/test_cursor.py b/tests/pyathena/aio/pandas/test_cursor.py index a99a52538..af9dcdfde 100644 --- a/tests/pyathena/aio/pandas/test_cursor.py +++ b/tests/pyathena/aio/pandas/test_cursor.py @@ -41,12 +41,6 @@ async def test_fetchone(self, aio_pandas_cursor): assert aio_pandas_cursor.rownumber == 1 assert await aio_pandas_cursor.fetchone() is None - async def test_fetchall(self, aio_pandas_cursor): - await aio_pandas_cursor.execute("SELECT * FROM one_row") - assert await aio_pandas_cursor.fetchall() == [(1,)] - await aio_pandas_cursor.execute("SELECT a FROM many_rows ORDER BY a") - assert await aio_pandas_cursor.fetchall() == [(i,) for i in range(10000)] - async def test_as_pandas(self, aio_pandas_cursor): await aio_pandas_cursor.execute("SELECT * FROM one_row") df = aio_pandas_cursor.as_pandas() diff --git a/tests/pyathena/aio/test_cursor.py b/tests/pyathena/aio/test_cursor.py index 71f0951ea..ab3d5281b 100644 --- a/tests/pyathena/aio/test_cursor.py +++ b/tests/pyathena/aio/test_cursor.py @@ -153,8 +153,6 @@ async def test_fetchmany(self, aio_cursor): assert actual2 == [(i,) for i in range(10, 15)] async def test_fetchall(self, aio_cursor): - await aio_cursor.execute("SELECT * FROM one_row") - assert await aio_cursor.fetchall() == [(1,)] await aio_cursor.execute("SELECT a FROM many_rows ORDER BY a") assert await aio_cursor.fetchall() == [(i,) for i in range(10000)] diff --git a/tests/pyathena/arrow/test_async_cursor.py b/tests/pyathena/arrow/test_async_cursor.py index 30ae8f5ce..2e1606679 100644 --- a/tests/pyathena/arrow/test_async_cursor.py +++ b/tests/pyathena/arrow/test_async_cursor.py @@ -1,4 +1,3 @@ -import contextlib import random import string import time @@ -34,57 +33,6 @@ def test_binary_null_vs_empty(self, async_arrow_cursor): ] assert [row[3] for row in rows] == ["", "", "NULL"] - @pytest.mark.parametrize( - "async_arrow_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["async_arrow_cursor"], - ) - def test_fetchone(self, async_arrow_cursor): - query_id, future = async_arrow_cursor.execute("SELECT * FROM one_row") - result_set = future.result() - assert result_set.rownumber == 0 - assert result_set.fetchone() == (1,) - assert result_set.rownumber == 1 - assert result_set.fetchone() is None - - @pytest.mark.parametrize( - "async_arrow_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["async_arrow_cursor"], - ) - def test_fetchmany(self, async_arrow_cursor): - query_id, future = async_arrow_cursor.execute("SELECT * FROM many_rows LIMIT 15") - result_set = future.result() - assert len(result_set.fetchmany(10)) == 10 - assert len(result_set.fetchmany(10)) == 5 - - @pytest.mark.parametrize( - "async_arrow_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["async_arrow_cursor"], - ) - def test_fetchall(self, async_arrow_cursor): - query_id, future = async_arrow_cursor.execute("SELECT * FROM one_row") - result_set = future.result() - assert result_set.fetchall() == [(1,)] - query_id, future = async_arrow_cursor.execute("SELECT a FROM many_rows ORDER BY a") - result_set = future.result() - if async_arrow_cursor._unload: - assert sorted(result_set.fetchall()) == [(i,) for i in range(10000)] - else: - assert result_set.fetchall() == [(i,) for i in range(10000)] - - @pytest.mark.parametrize( - "async_arrow_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["async_arrow_cursor"], - ) - def test_iterator(self, async_arrow_cursor): - query_id, future = async_arrow_cursor.execute("SELECT * FROM one_row") - result_set = future.result() - assert list(result_set) == [(1,)] - pytest.raises(StopIteration, result_set.__next__) - @pytest.mark.parametrize( "async_arrow_cursor", [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], @@ -274,10 +222,6 @@ def test_cancel(self, async_arrow_cursor): assert result_set.fetchmany() == [] assert result_set.fetchall() == [] - def test_open_close(self): - with contextlib.closing(connect()) as conn, conn.cursor(AsyncArrowCursor): - pass - def test_no_ops(self): conn = connect() cursor = conn.cursor(AsyncArrowCursor) diff --git a/tests/pyathena/arrow/test_cursor.py b/tests/pyathena/arrow/test_cursor.py index 957815784..771fe0fb2 100644 --- a/tests/pyathena/arrow/test_cursor.py +++ b/tests/pyathena/arrow/test_cursor.py @@ -109,52 +109,6 @@ def test_temporal_text_null_with_binary(self, arrow_cursor): ] assert arrow_cursor.fetchall() == [(None, None, None, "", None)] - @pytest.mark.parametrize( - "arrow_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["arrow_cursor"], - ) - def test_fetchone(self, arrow_cursor): - arrow_cursor.execute("SELECT * FROM one_row") - assert arrow_cursor.rownumber == 0 - assert arrow_cursor.fetchone() == (1,) - assert arrow_cursor.rownumber == 1 - assert arrow_cursor.fetchone() is None - - @pytest.mark.parametrize( - "arrow_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["arrow_cursor"], - ) - def test_fetchmany(self, arrow_cursor): - arrow_cursor.execute("SELECT * FROM many_rows LIMIT 15") - assert len(arrow_cursor.fetchmany(10)) == 10 - assert len(arrow_cursor.fetchmany(10)) == 5 - - @pytest.mark.parametrize( - "arrow_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["arrow_cursor"], - ) - def test_fetchall(self, arrow_cursor): - arrow_cursor.execute("SELECT * FROM one_row") - assert arrow_cursor.fetchall() == [(1,)] - arrow_cursor.execute("SELECT a FROM many_rows ORDER BY a") - if arrow_cursor._unload: - assert sorted(arrow_cursor.fetchall()) == [(i,) for i in range(10000)] - else: - assert arrow_cursor.fetchall() == [(i,) for i in range(10000)] - - @pytest.mark.parametrize( - "arrow_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["arrow_cursor"], - ) - def test_iterator(self, arrow_cursor): - arrow_cursor.execute("SELECT * FROM one_row") - assert list(arrow_cursor) == [(1,)] - pytest.raises(StopIteration, arrow_cursor.__next__) - @pytest.mark.parametrize( "arrow_cursor", [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], @@ -593,10 +547,6 @@ def cancel(c): def test_cancel_initial(self, arrow_cursor): pytest.raises(ProgrammingError, arrow_cursor.cancel) - def test_open_close(self): - with contextlib.closing(connect()) as conn, conn.cursor(ArrowCursor): - pass - def test_no_ops(self): conn = connect() cursor = conn.cursor(ArrowCursor) diff --git a/tests/pyathena/pandas/test_async_cursor.py b/tests/pyathena/pandas/test_async_cursor.py index a4ee52b4a..baf2381a3 100644 --- a/tests/pyathena/pandas/test_async_cursor.py +++ b/tests/pyathena/pandas/test_async_cursor.py @@ -1,4 +1,3 @@ -import contextlib import time from datetime import datetime from random import randint @@ -32,44 +31,6 @@ def test_binary_null_vs_empty(self, async_pandas_cursor): (3, b"\x00\xff'\\%", 'comma, quote" and\nnewline'), ] - @pytest.mark.parametrize( - ("async_pandas_cursor", "parquet_engine", "chunksize"), - [ - ({"cursor_kwargs": {"unload": False}}, "auto", None), - ({"cursor_kwargs": {"unload": False}}, "auto", 1_000), - ({"cursor_kwargs": {"unload": True}}, "auto", None), - ], - indirect=["async_pandas_cursor"], - ) - def test_fetchone(self, async_pandas_cursor, parquet_engine, chunksize): - query_id, future = async_pandas_cursor.execute( - "SELECT * FROM one_row", engine=parquet_engine, chunksize=chunksize - ) - result_set = future.result() - assert result_set.rownumber == 0 - assert result_set.fetchone() == (1,) - assert result_set.rownumber == 1 - assert result_set.fetchone() is None - - @pytest.mark.parametrize( - ("async_pandas_cursor", "parquet_engine", "chunksize"), - [ - ({"cursor_kwargs": {"unload": False}}, "auto", None), - ({"cursor_kwargs": {"unload": False}}, "auto", 1_000), - ({"cursor_kwargs": {"unload": True}}, "auto", None), - ], - indirect=["async_pandas_cursor"], - ) - def test_fetchmany(self, async_pandas_cursor, parquet_engine, chunksize): - query_id, future = async_pandas_cursor.execute( - "SELECT * FROM many_rows LIMIT 15", - engine=parquet_engine, - chunksize=chunksize, - ) - result_set = future.result() - assert len(result_set.fetchmany(10)) == 10 - assert len(result_set.fetchmany(10)) == 5 - @pytest.mark.parametrize( ("async_pandas_cursor", "chunksize"), [ @@ -91,46 +52,6 @@ def test_get_chunk(self, async_pandas_cursor, chunksize): else: assert len(df) == 15 - @pytest.mark.parametrize( - ("async_pandas_cursor", "parquet_engine", "chunksize"), - [ - ({"cursor_kwargs": {"unload": False}}, "auto", None), - ({"cursor_kwargs": {"unload": False}}, "auto", 1_000), - ({"cursor_kwargs": {"unload": True}}, "auto", None), - ], - indirect=["async_pandas_cursor"], - ) - def test_fetchall(self, async_pandas_cursor, parquet_engine, chunksize): - query_id, future = async_pandas_cursor.execute( - "SELECT * FROM one_row", - engine=parquet_engine, - chunksize=chunksize, - ) - result_set = future.result() - assert result_set.fetchall() == [(1,)] - query_id, future = async_pandas_cursor.execute("SELECT a FROM many_rows ORDER BY a") - result_set = future.result() - assert result_set.fetchall() == [(i,) for i in range(10000)] - - @pytest.mark.parametrize( - ("async_pandas_cursor", "parquet_engine", "chunksize"), - [ - ({"cursor_kwargs": {"unload": False}}, "auto", None), - ({"cursor_kwargs": {"unload": False}}, "auto", 1_000), - ({"cursor_kwargs": {"unload": True}}, "auto", None), - ], - indirect=["async_pandas_cursor"], - ) - def test_iterator(self, async_pandas_cursor, parquet_engine, chunksize): - query_id, future = async_pandas_cursor.execute( - "SELECT * FROM one_row", - engine=parquet_engine, - chunksize=chunksize, - ) - result_set = future.result() - assert list(result_set) == [(1,)] - pytest.raises(StopIteration, result_set.__next__) - @pytest.mark.parametrize( ("async_pandas_cursor", "parquet_engine", "chunksize"), [ @@ -349,10 +270,6 @@ def test_cancel(self, async_pandas_cursor): assert result_set.fetchmany() == [] assert result_set.fetchall() == [] - def test_open_close(self): - with contextlib.closing(connect()) as conn, conn.cursor(AsyncPandasCursor): - pass - def test_no_ops(self): conn = connect() cursor = conn.cursor(AsyncPandasCursor) diff --git a/tests/pyathena/pandas/test_cursor.py b/tests/pyathena/pandas/test_cursor.py index 32f073aca..20ec7f3a4 100644 --- a/tests/pyathena/pandas/test_cursor.py +++ b/tests/pyathena/pandas/test_cursor.py @@ -313,22 +313,6 @@ def test_binary_single_null(self, pandas_cursor): pandas_cursor.execute("SELECT CAST(NULL AS VARBINARY) AS value") assert pandas_cursor.fetchall() == [(None,)] - @pytest.mark.parametrize( - ("pandas_cursor", "parquet_engine", "chunksize"), - [ - ({"cursor_kwargs": {"unload": False}}, "auto", None), - ({"cursor_kwargs": {"unload": False}}, "auto", 1_000), - ({"cursor_kwargs": {"unload": True}}, "auto", None), - ], - indirect=["pandas_cursor"], - ) - def test_fetchone(self, pandas_cursor, parquet_engine, chunksize): - pandas_cursor.execute("SELECT * FROM one_row", engine=parquet_engine, chunksize=chunksize) - assert pandas_cursor.rownumber == 0 - assert pandas_cursor.fetchone() == (1,) - assert pandas_cursor.rownumber == 1 - assert pandas_cursor.fetchone() is None - @pytest.mark.parametrize( "pandas_cursor", [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], @@ -386,24 +370,6 @@ def test_csv_storage_options(self, pandas_cursor, query, expected): }, ) - @pytest.mark.parametrize( - ("pandas_cursor", "parquet_engine", "chunksize"), - [ - ({"cursor_kwargs": {"unload": False}}, "auto", None), - ({"cursor_kwargs": {"unload": False}}, "auto", 1_000), - ({"cursor_kwargs": {"unload": True}}, "auto", None), - ], - indirect=["pandas_cursor"], - ) - def test_fetchmany(self, pandas_cursor, parquet_engine, chunksize): - pandas_cursor.execute( - "SELECT * FROM many_rows LIMIT 15", - engine=parquet_engine, - chunksize=chunksize, - ) - assert len(pandas_cursor.fetchmany(10)) == 10 - assert len(pandas_cursor.fetchmany(10)) == 5 - @pytest.mark.parametrize( ("pandas_cursor", "ordered"), [ @@ -454,35 +420,6 @@ def test_get_chunk(self, pandas_cursor, chunksize): else: assert len(df) == 15 - @pytest.mark.parametrize( - ("pandas_cursor", "parquet_engine", "chunksize"), - [ - ({"cursor_kwargs": {"unload": False}}, "auto", None), - ({"cursor_kwargs": {"unload": False}}, "auto", 1_000), - ({"cursor_kwargs": {"unload": True}}, "auto", None), - ], - indirect=["pandas_cursor"], - ) - def test_fetchall(self, pandas_cursor, parquet_engine, chunksize): - pandas_cursor.execute("SELECT * FROM one_row", engine=parquet_engine, chunksize=chunksize) - assert pandas_cursor.fetchall() == [(1,)] - pandas_cursor.execute("SELECT a FROM many_rows ORDER BY a", engine=parquet_engine) - assert pandas_cursor.fetchall() == [(i,) for i in range(10000)] - - @pytest.mark.parametrize( - ("pandas_cursor", "parquet_engine", "chunksize"), - [ - ({"cursor_kwargs": {"unload": False}}, "auto", None), - ({"cursor_kwargs": {"unload": False}}, "auto", 1_000), - ({"cursor_kwargs": {"unload": True}}, "auto", None), - ], - indirect=["pandas_cursor"], - ) - def test_iterator(self, pandas_cursor, parquet_engine, chunksize): - pandas_cursor.execute("SELECT * FROM one_row", engine=parquet_engine, chunksize=chunksize) - assert list(pandas_cursor) == [(1,)] - pytest.raises(StopIteration, pandas_cursor.__next__) - @pytest.mark.parametrize( ("pandas_cursor", "parquet_engine", "chunksize"), [ @@ -1170,10 +1107,6 @@ def cancel(c): def test_cancel_initial(self, pandas_cursor): pytest.raises(ProgrammingError, pandas_cursor.cancel) - def test_open_close(self): - with contextlib.closing(connect()) as conn, conn.cursor(PandasCursor): - pass - def test_no_ops(self): conn = connect() cursor = conn.cursor(PandasCursor) diff --git a/tests/pyathena/polars/test_async_cursor.py b/tests/pyathena/polars/test_async_cursor.py index 12673f425..77de3b60e 100644 --- a/tests/pyathena/polars/test_async_cursor.py +++ b/tests/pyathena/polars/test_async_cursor.py @@ -1,4 +1,3 @@ -import contextlib import random import string import time @@ -19,57 +18,6 @@ class TestAsyncPolarsCursor: - @pytest.mark.parametrize( - "async_polars_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["async_polars_cursor"], - ) - def test_fetchone(self, async_polars_cursor): - query_id, future = async_polars_cursor.execute("SELECT * FROM one_row") - result_set = future.result() - assert result_set.rownumber == 0 - assert result_set.fetchone() == (1,) - assert result_set.rownumber == 1 - assert result_set.fetchone() is None - - @pytest.mark.parametrize( - "async_polars_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["async_polars_cursor"], - ) - def test_fetchmany(self, async_polars_cursor): - query_id, future = async_polars_cursor.execute("SELECT * FROM many_rows LIMIT 15") - result_set = future.result() - assert len(result_set.fetchmany(10)) == 10 - assert len(result_set.fetchmany(10)) == 5 - - @pytest.mark.parametrize( - "async_polars_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["async_polars_cursor"], - ) - def test_fetchall(self, async_polars_cursor): - query_id, future = async_polars_cursor.execute("SELECT * FROM one_row") - result_set = future.result() - assert result_set.fetchall() == [(1,)] - query_id, future = async_polars_cursor.execute("SELECT a FROM many_rows ORDER BY a") - result_set = future.result() - if async_polars_cursor._unload: - assert sorted(result_set.fetchall()) == [(i,) for i in range(10000)] - else: - assert result_set.fetchall() == [(i,) for i in range(10000)] - - @pytest.mark.parametrize( - "async_polars_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["async_polars_cursor"], - ) - def test_iterator(self, async_polars_cursor): - query_id, future = async_polars_cursor.execute("SELECT * FROM one_row") - result_set = future.result() - assert list(result_set) == [(1,)] - pytest.raises(StopIteration, result_set.__next__) - @pytest.mark.parametrize( "async_polars_cursor", [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], @@ -260,10 +208,6 @@ def test_cancel(self, async_polars_cursor): assert result_set.fetchmany() == [] assert result_set.fetchall() == [] - def test_open_close(self): - with contextlib.closing(connect()) as conn, conn.cursor(AsyncPolarsCursor): - pass - def test_no_ops(self): conn = connect() cursor = conn.cursor(AsyncPolarsCursor) diff --git a/tests/pyathena/polars/test_cursor.py b/tests/pyathena/polars/test_cursor.py index 59709e140..f106c7afd 100644 --- a/tests/pyathena/polars/test_cursor.py +++ b/tests/pyathena/polars/test_cursor.py @@ -40,18 +40,6 @@ class TestPolarsCursor: - @pytest.mark.parametrize( - "polars_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["polars_cursor"], - ) - def test_fetchone(self, polars_cursor): - polars_cursor.execute("SELECT * FROM one_row") - assert polars_cursor.rownumber == 0 - assert polars_cursor.fetchone() == (1,) - assert polars_cursor.rownumber == 1 - assert polars_cursor.fetchone() is None - def test_result_set_file_system_not_cached(self, polars_cursor): # GH-978: the filesystem that read the CSV results was kept in the fsspec # instance cache with the connection, so the connection was never freed. @@ -59,40 +47,6 @@ def test_result_set_file_system_not_cached(self, polars_cursor): assert polars_cursor.fetchall() == [(1,)] assert not cached_file_systems(polars_cursor.connection) - @pytest.mark.parametrize( - "polars_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["polars_cursor"], - ) - def test_fetchmany(self, polars_cursor): - polars_cursor.execute("SELECT * FROM many_rows LIMIT 15") - assert len(polars_cursor.fetchmany(10)) == 10 - assert len(polars_cursor.fetchmany(10)) == 5 - - @pytest.mark.parametrize( - "polars_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["polars_cursor"], - ) - def test_fetchall(self, polars_cursor): - polars_cursor.execute("SELECT * FROM one_row") - assert polars_cursor.fetchall() == [(1,)] - polars_cursor.execute("SELECT a FROM many_rows ORDER BY a") - if polars_cursor._unload: - assert sorted(polars_cursor.fetchall()) == [(i,) for i in range(10000)] - else: - assert polars_cursor.fetchall() == [(i,) for i in range(10000)] - - @pytest.mark.parametrize( - "polars_cursor", - [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], - indirect=["polars_cursor"], - ) - def test_iterator(self, polars_cursor): - polars_cursor.execute("SELECT * FROM one_row") - assert list(polars_cursor) == [(1,)] - pytest.raises(StopIteration, polars_cursor.__next__) - @pytest.mark.parametrize( "polars_cursor", [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], @@ -540,10 +494,6 @@ def cancel(c): def test_cancel_initial(self, polars_cursor): pytest.raises(ProgrammingError, polars_cursor.cancel) - def test_open_close(self): - with contextlib.closing(connect()) as conn, conn.cursor(PolarsCursor): - pass - def test_no_ops(self): conn = connect() cursor = conn.cursor(PolarsCursor) diff --git a/tests/pyathena/s3fs/test_async_cursor.py b/tests/pyathena/s3fs/test_async_cursor.py index e77a46690..ddc01fb72 100644 --- a/tests/pyathena/s3fs/test_async_cursor.py +++ b/tests/pyathena/s3fs/test_async_cursor.py @@ -5,7 +5,6 @@ # # SPDX-License-Identifier: MIT -import contextlib import random import time from unittest.mock import MagicMock, patch @@ -23,34 +22,12 @@ class TestAsyncS3FSCursor: - def test_fetchone(self, async_s3fs_cursor): - query_id, future = async_s3fs_cursor.execute("SELECT * FROM one_row") - result_set = future.result() - assert result_set.rownumber == 0 - assert result_set.fetchone() == (1,) - assert result_set.rownumber == 1 - assert result_set.fetchone() is None - - def test_fetchmany(self, async_s3fs_cursor): - query_id, future = async_s3fs_cursor.execute("SELECT * FROM many_rows LIMIT 15") - result_set = future.result() - assert len(result_set.fetchmany(10)) == 10 - assert len(result_set.fetchmany(10)) == 5 - - def test_fetchall(self, async_s3fs_cursor): - query_id, future = async_s3fs_cursor.execute("SELECT * FROM one_row") - result_set = future.result() - assert result_set.fetchall() == [(1,)] - - query_id, future = async_s3fs_cursor.execute("SELECT a FROM many_rows ORDER BY a") - result_set = future.result() - assert result_set.fetchall() == [(i,) for i in range(10000)] - def test_arraysize(self, async_s3fs_cursor): async_s3fs_cursor.arraysize = 5 - query_id, future = async_s3fs_cursor.execute("SELECT * FROM many_rows LIMIT 20") + query_id, future = async_s3fs_cursor.execute("SELECT a FROM many_rows ORDER BY a LIMIT 20") result_set = future.result() - assert len(result_set.fetchmany()) == 5 + # The values check that the cursor passes its converter to the result set too. + assert result_set.fetchmany() == [(i,) for i in range(5)] def test_arraysize_default(self, async_s3fs_cursor): assert async_s3fs_cursor.arraysize == AthenaS3FSResultSet.DEFAULT_FETCH_SIZE @@ -78,15 +55,6 @@ def test_cancel(self, async_s3fs_cursor): assert result_set.fetchmany() == [] assert result_set.fetchall() == [] - def test_open_close(self): - with ( - contextlib.closing(connect(schema_name=ENV.schema)) as conn, - conn.cursor(AsyncS3FSCursor) as cursor, - ): - query_id, future = cursor.execute("SELECT * FROM one_row") - result_set = future.result() - assert result_set.fetchall() == [(1,)] - def test_no_ops(self): conn = connect(schema_name=ENV.schema) cursor = conn.cursor(AsyncS3FSCursor) diff --git a/tests/pyathena/s3fs/test_cursor.py b/tests/pyathena/s3fs/test_cursor.py index 904f0ef04..dda2eafc4 100644 --- a/tests/pyathena/s3fs/test_cursor.py +++ b/tests/pyathena/s3fs/test_cursor.py @@ -35,13 +35,6 @@ def _s3fs_converter_with_json_text(): class TestS3FSCursor: - def test_fetchone(self, s3fs_cursor): - s3fs_cursor.execute("SELECT * FROM one_row") - assert s3fs_cursor.rownumber == 0 - assert s3fs_cursor.fetchone() == (1,) - assert s3fs_cursor.rownumber == 1 - assert s3fs_cursor.fetchone() is None - def test_result_set_file_system_not_cached(self, s3fs_cursor): # GH-978: the filesystem that read the results was kept in the fsspec # instance cache with the connection, so the connection was never freed. @@ -49,22 +42,6 @@ def test_result_set_file_system_not_cached(self, s3fs_cursor): assert s3fs_cursor.fetchall() == [(1,)] assert not cached_file_systems(s3fs_cursor.connection) - def test_fetchmany(self, s3fs_cursor): - s3fs_cursor.execute("SELECT * FROM many_rows LIMIT 15") - assert len(s3fs_cursor.fetchmany(10)) == 10 - assert len(s3fs_cursor.fetchmany(10)) == 5 - - def test_fetchall(self, s3fs_cursor): - s3fs_cursor.execute("SELECT * FROM one_row") - assert s3fs_cursor.fetchall() == [(1,)] - s3fs_cursor.execute("SELECT a FROM many_rows ORDER BY a") - assert s3fs_cursor.fetchall() == [(i,) for i in range(10000)] - - def test_iterator(self, s3fs_cursor): - s3fs_cursor.execute("SELECT * FROM one_row") - assert list(s3fs_cursor) == [(1,)] - pytest.raises(StopIteration, s3fs_cursor.__next__) - def test_arraysize(self, s3fs_cursor): s3fs_cursor.arraysize = 5 s3fs_cursor.execute("SELECT * FROM many_rows LIMIT 20") @@ -177,14 +154,6 @@ def cancel(c): def test_cancel_initial(self, s3fs_cursor): pytest.raises(ProgrammingError, s3fs_cursor.cancel) - def test_open_close(self): - with ( - contextlib.closing(connect(schema_name=ENV.schema)) as conn, - conn.cursor(S3FSCursor) as cursor, - ): - cursor.execute("SELECT * FROM one_row") - assert cursor.fetchall() == [(1,)] - def test_no_ops(self): conn = connect(schema_name=ENV.schema) cursor = conn.cursor(S3FSCursor) diff --git a/tests/pyathena/test_async_cursor.py b/tests/pyathena/test_async_cursor.py index d08ed5801..42945ea8b 100644 --- a/tests/pyathena/test_async_cursor.py +++ b/tests/pyathena/test_async_cursor.py @@ -15,60 +15,6 @@ class TestAsyncCursor: - def test_fetchone(self, async_cursor): - query_id, future = async_cursor.execute("SELECT * FROM one_row") - result_set = future.result() - assert result_set.rownumber == 0 - assert result_set.fetchone() == (1,) - assert result_set.rownumber == 1 - assert result_set.fetchone() is None - assert result_set.database == ENV.schema - assert result_set.catalog - assert result_set.query_id - assert result_set.query - assert result_set.statement_type == AthenaQueryExecution.STATEMENT_TYPE_DML - assert result_set.work_group == ENV.default_work_group - assert result_set.state == AthenaQueryExecution.STATE_SUCCEEDED - assert result_set.state_change_reason is None - assert result_set.submission_date_time - assert isinstance(result_set.submission_date_time, datetime) - assert result_set.completion_date_time - assert isinstance(result_set.completion_date_time, datetime) - assert result_set.data_scanned_in_bytes - assert result_set.engine_execution_time_in_millis - assert result_set.query_queue_time_in_millis - assert result_set.total_execution_time_in_millis - # assert result_set.query_planning_time_in_millis # TODO flaky test - # assert result_set.service_processing_time_in_millis # TODO flaky test - assert result_set.output_location - assert result_set.data_manifest_location is None - assert result_set.selected_engine_version - assert result_set.effective_engine_version - - def test_fetchmany(self, async_cursor): - query_id, future = async_cursor.execute("SELECT * FROM many_rows LIMIT 15") - result_set = future.result() - actual1 = result_set.fetchmany(10) - assert len(actual1) == 10 - assert actual1 == [(i,) for i in range(10)] - actual2 = result_set.fetchmany(10) - assert len(actual2) == 5 - assert actual2 == [(i,) for i in range(10, 15)] - - def test_fetchall(self, async_cursor): - query_id, future = async_cursor.execute("SELECT * FROM one_row") - result_set = future.result() - assert result_set.fetchall() == [(1,)] - query_id, future = async_cursor.execute("SELECT a FROM many_rows ORDER BY a") - result_set = future.result() - assert result_set.fetchall() == [(i,) for i in range(10000)] - - def test_iterator(self, async_cursor): - query_id, future = async_cursor.execute("SELECT * FROM one_row") - result_set = future.result() - assert list(result_set) == [(1,)] - pytest.raises(StopIteration, result_set.__next__) - def test_arraysize(self, async_cursor): async_cursor.arraysize = 5 query_id, future = async_cursor.execute("SELECT * FROM many_rows LIMIT 20") @@ -225,29 +171,6 @@ def test_no_ops(self): class TestAsyncDictCursor: - def test_fetchone(self, async_dict_cursor): - query_id, future = async_dict_cursor.execute("SELECT * FROM one_row") - result_set = future.result() - assert result_set.fetchone() == {"number_of_rows": 1} - - def test_fetchmany(self, async_dict_cursor): - query_id, future = async_dict_cursor.execute("SELECT * FROM many_rows LIMIT 15") - result_set = future.result() - actual1 = result_set.fetchmany(10) - assert len(actual1) == 10 - assert actual1 == [{"a": i} for i in range(10)] - actual2 = result_set.fetchmany(10) - assert len(actual2) == 5 - assert actual2 == [{"a": i} for i in range(10, 15)] - - def test_fetchall(self, async_dict_cursor): - query_id, future = async_dict_cursor.execute("SELECT * FROM one_row") - result_set = future.result() - assert result_set.fetchall() == [{"number_of_rows": 1}] - query_id, future = async_dict_cursor.execute("SELECT a FROM many_rows ORDER BY a") - result_set = future.result() - assert result_set.fetchall() == [{"a": i} for i in range(10000)] - def test_dict_type(self, async_dict_cursor): with async_dict_cursor.connection.cursor(dict_type=OrderedDict) as ordered_cursor: _, future = ordered_cursor.execute("SELECT * FROM one_row") diff --git a/tests/pyathena/test_cursor.py b/tests/pyathena/test_cursor.py index 6b3e680ca..766210903 100644 --- a/tests/pyathena/test_cursor.py +++ b/tests/pyathena/test_cursor.py @@ -184,16 +184,9 @@ def test_fetchmany(self, cursor): assert actual2 == [(i,) for i in range(10, 15)] def test_fetchall(self, cursor): - cursor.execute("SELECT * FROM one_row") - assert cursor.fetchall() == [(1,)] cursor.execute("SELECT a FROM many_rows ORDER BY a") assert cursor.fetchall() == [(i,) for i in range(10000)] - def test_iterator(self, cursor): - cursor.execute("SELECT * FROM one_row") - assert list(cursor) == [(1,)] - pytest.raises(StopIteration, cursor.__next__) - # Cache hits are asserted in ENV.work_group: the default work group runs most test # queries, which can push earlier executions out of the cache_size window. @pytest.mark.parametrize("cursor", [{"work_group": ENV.work_group}], indirect=["cursor"]) @@ -1876,25 +1869,6 @@ def test_throttled_metadata_without_glue(self, cursor, monkeypatch, catalog_name class TestDictCursor: - def test_fetchone(self, dict_cursor): - dict_cursor.execute("SELECT * FROM one_row") - assert dict_cursor.fetchone() == {"number_of_rows": 1} - - def test_fetchmany(self, dict_cursor): - dict_cursor.execute("SELECT * FROM many_rows LIMIT 15") - actual1 = dict_cursor.fetchmany(10) - assert len(actual1) == 10 - assert actual1 == [{"a": i} for i in range(10)] - actual2 = dict_cursor.fetchmany(10) - assert len(actual2) == 5 - assert actual2 == [{"a": i} for i in range(10, 15)] - - def test_fetchall(self, dict_cursor): - dict_cursor.execute("SELECT * FROM one_row") - assert dict_cursor.fetchall() == [{"number_of_rows": 1}] - dict_cursor.execute("SELECT a FROM many_rows ORDER BY a") - assert dict_cursor.fetchall() == [{"a": i} for i in range(10000)] - def test_dict_type(self, dict_cursor): with dict_cursor.connection.cursor(dict_type=OrderedDict) as ordered_cursor: ordered_cursor.execute("SELECT * FROM one_row")