Skip to content

Commit

Permalink
SQLAlchemy: Test suite adjustments for pandas software tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jul 5, 2023
1 parent 7aadc33 commit 827c63c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


linkcheck_anchors = True
linkcheck_ignore = [r"https://github.com/crate/cratedb-examples/blob/main/by-language/python-sqlalchemy/.*"]


rst_prolog = """
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 4 additions & 2 deletions src/crate/client/sqlalchemy/tests/bulk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
16 changes: 14 additions & 2 deletions src/crate/client/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import json
import os
import socket
import sys
import unittest
import doctest
from pprint import pprint
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 827c63c

Please sign in to comment.