From 827c63c53f7d84d6aa196e6097e94f38309f4650 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Thu, 11 May 2023 13:30:17 +0200 Subject: [PATCH] SQLAlchemy: Test suite adjustments for pandas software tests --- docs/conf.py | 1 + setup.py | 2 +- src/crate/client/sqlalchemy/tests/bulk_test.py | 6 ++++-- src/crate/client/tests.py | 16 ++++++++++++++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index f8f8465c..6cea16ec 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -18,6 +18,7 @@ linkcheck_anchors = True +linkcheck_ignore = [r"https://github.com/crate/cratedb-examples/blob/main/by-language/python-sqlalchemy/.*"] rst_prolog = """ diff --git a/setup.py b/setup.py index e3d3de47..3055075a 100644 --- a/setup.py +++ b/setup.py @@ -70,7 +70,7 @@ def read(path): 'createcoverage>=1,<2', 'stopit>=1.1.2,<2', 'flake8>=4,<7', - 'pandas>=2,<3', + 'pandas', 'pytz', # `test_http.py` needs `setuptools.ssl_support` 'setuptools<57', diff --git a/src/crate/client/sqlalchemy/tests/bulk_test.py b/src/crate/client/sqlalchemy/tests/bulk_test.py index 317d1fd3..48b3797c 100644 --- a/src/crate/client/sqlalchemy/tests/bulk_test.py +++ b/src/crate/client/sqlalchemy/tests/bulk_test.py @@ -19,13 +19,14 @@ # with Crate these terms will supersede the license and you may use the # software solely pursuant to the terms of the relevant commercial agreement. import math +import sys from unittest import TestCase, skipIf from unittest.mock import patch, MagicMock import sqlalchemy as sa from sqlalchemy.orm import Session -from crate.client.sqlalchemy.sa_version import SA_VERSION, SA_2_0 +from crate.client.sqlalchemy.sa_version import SA_VERSION, SA_2_0, SA_1_4 try: from sqlalchemy.orm import declarative_base @@ -168,12 +169,13 @@ def test_bulk_save_modern(self): ) self.assertSequenceEqual(expected_bulk_args, bulk_args) + @skipIf(sys.version_info < (3, 8), "SQLAlchemy/pandas is not supported on Python <3.8") + @skipIf(SA_VERSION < SA_1_4, "SQLAlchemy 1.3 is not supported by pandas") @patch('crate.client.connection.Cursor', mock_cursor=FakeCursor) def test_bulk_save_pandas(self, mock_cursor): """ Verify bulk INSERT with pandas. """ - import sqlalchemy as sa from pandas._testing import makeTimeDataFrame from crate.client.sqlalchemy.support import insert_bulk diff --git a/src/crate/client/tests.py b/src/crate/client/tests.py index 455a7a4d..4ce9c950 100644 --- a/src/crate/client/tests.py +++ b/src/crate/client/tests.py @@ -24,6 +24,7 @@ import json import os import socket +import sys import unittest import doctest from pprint import pprint @@ -40,6 +41,7 @@ crate_host, crate_path, crate_port, \ crate_transport_port, docs_path, localhost from crate.client import connect +from .sqlalchemy import SA_VERSION, SA_1_4 from .test_cursor import CursorTest from .test_connection import ConnectionTest @@ -382,13 +384,23 @@ def test_suite(): s.layer = ensure_cratedb_layer() suite.addTest(s) - s = doctest.DocFileSuite( + sqlalchemy_integration_tests = [ 'docs/by-example/sqlalchemy/getting-started.rst', 'docs/by-example/sqlalchemy/crud.rst', 'docs/by-example/sqlalchemy/working-with-types.rst', 'docs/by-example/sqlalchemy/advanced-querying.rst', 'docs/by-example/sqlalchemy/inspection-reflection.rst', - 'docs/by-example/sqlalchemy/dataframe.rst', + ] + + # Don't run DataFrame integration tests on SQLAlchemy 1.3 and Python 3.7. + skip_dataframe = SA_VERSION < SA_1_4 or sys.version_info < (3, 8) + if not skip_dataframe: + sqlalchemy_integration_tests += [ + 'docs/by-example/sqlalchemy/dataframe.rst', + ] + + s = doctest.DocFileSuite( + *sqlalchemy_integration_tests, module_relative=False, setUp=setUpCrateLayerSqlAlchemy, tearDown=tearDownDropEntitiesSqlAlchemy,