From d2c7613a9189c44e60b51fb69027d0fe61569f6f Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Mon, 10 Jun 2024 14:30:14 +0200 Subject: [PATCH] Chore: Fix tests on SQLAlchemy 1.3, by skipping them We don't know which circumstances cause this problem. SQLAlchemy 1.3 is EOL anyway, so we don't care too much. sqlalchemy.exc.InvalidRequestError: When initializing mapper mapped class RootStore->root, expression 'ItemStore' failed to locate a name ('ItemStore'). --- tests/compiler_test.py | 4 +--- tests/datetime_test.py | 7 ++++++- tests/dict_test.py | 6 ++++-- tests/insert_from_select_test.py | 7 +++++-- tests/update_test.py | 6 +++--- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/tests/compiler_test.py b/tests/compiler_test.py index 6773b75e..a40ebb0f 100644 --- a/tests/compiler_test.py +++ b/tests/compiler_test.py @@ -18,7 +18,6 @@ # However, if you have executed another commercial license agreement # 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 sys import warnings from textwrap import dedent from unittest import mock, skipIf, TestCase @@ -289,8 +288,7 @@ def test_for_update(self): FakeCursor = MagicMock(name='FakeCursor', spec=Cursor) -@skipIf(SA_VERSION < SA_1_4 and (3, 9) <= sys.version_info < (3, 10), - "SQLAlchemy 1.3 has problems with these test cases on Python 3.9") +@skipIf(SA_VERSION < SA_1_4, "SQLAlchemy 1.3 suddenly has problems with these test cases") class CompilerTestCase(TestCase): """ A base class for providing mocking infrastructure to validate the DDL compiler. diff --git a/tests/datetime_test.py b/tests/datetime_test.py index 07e98ede..53c30fce 100644 --- a/tests/datetime_test.py +++ b/tests/datetime_test.py @@ -20,13 +20,17 @@ # software solely pursuant to the terms of the relevant commercial agreement. from __future__ import absolute_import + from datetime import datetime, tzinfo, timedelta -from unittest import TestCase +from unittest import TestCase, skipIf from unittest.mock import patch, MagicMock import sqlalchemy as sa from sqlalchemy.exc import DBAPIError from sqlalchemy.orm import Session + +from sqlalchemy_cratedb import SA_VERSION, SA_1_4 + try: from sqlalchemy.orm import declarative_base except ImportError: @@ -52,6 +56,7 @@ def dst(self, date_time): return timedelta(seconds=-7200) +@skipIf(SA_VERSION < SA_1_4, "SQLAlchemy 1.3 suddenly has problems with these test cases") @patch('crate.client.connection.Cursor', FakeCursor) class SqlAlchemyDateAndDateTimeTest(TestCase): diff --git a/tests/dict_test.py b/tests/dict_test.py index 84b6f491..5f2692c1 100644 --- a/tests/dict_test.py +++ b/tests/dict_test.py @@ -20,7 +20,8 @@ # software solely pursuant to the terms of the relevant commercial agreement. from __future__ import absolute_import -from unittest import TestCase + +from unittest import TestCase, skipIf from unittest.mock import patch, MagicMock import sqlalchemy as sa @@ -31,7 +32,7 @@ except ImportError: from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy_cratedb import ObjectArray, ObjectType +from sqlalchemy_cratedb import ObjectArray, ObjectType, SA_VERSION, SA_1_4 from crate.client.cursor import Cursor @@ -40,6 +41,7 @@ FakeCursor.return_value = fake_cursor +@skipIf(SA_VERSION < SA_1_4, "SQLAlchemy 1.3 suddenly has problems with these test cases") class SqlAlchemyDictTypeTest(TestCase): def setUp(self): diff --git a/tests/insert_from_select_test.py b/tests/insert_from_select_test.py index 692dfa55..a4533a55 100644 --- a/tests/insert_from_select_test.py +++ b/tests/insert_from_select_test.py @@ -18,14 +18,16 @@ # However, if you have executed another commercial license agreement # with Crate these terms will supersede the license and you may use the # software solely pursuant to the terms of the relevant commercial agreement. - from datetime import datetime -from unittest import TestCase +from unittest import TestCase, skipIf from unittest.mock import patch, MagicMock import sqlalchemy as sa from sqlalchemy import select, insert from sqlalchemy.orm import Session + +from sqlalchemy_cratedb import SA_VERSION, SA_1_4 + try: from sqlalchemy.orm import declarative_base except ImportError: @@ -40,6 +42,7 @@ FakeCursor.return_value = fake_cursor +@skipIf(SA_VERSION < SA_1_4, "SQLAlchemy 1.3 suddenly has problems with these test cases") class SqlAlchemyInsertFromSelectTest(TestCase): def assertSQL(self, expected_str, actual_expr): diff --git a/tests/update_test.py b/tests/update_test.py index 5062f229..a70b56cb 100644 --- a/tests/update_test.py +++ b/tests/update_test.py @@ -18,12 +18,11 @@ # However, if you have executed another commercial license agreement # with Crate these terms will supersede the license and you may use the # software solely pursuant to the terms of the relevant commercial agreement. - from datetime import datetime -from unittest import TestCase +from unittest import TestCase, skipIf from unittest.mock import patch, MagicMock -from sqlalchemy_cratedb import ObjectType +from sqlalchemy_cratedb import ObjectType, SA_VERSION, SA_1_4 import sqlalchemy as sa from sqlalchemy.orm import Session @@ -41,6 +40,7 @@ FakeCursor.return_value = fake_cursor +@skipIf(SA_VERSION < SA_1_4, "SQLAlchemy 1.3 suddenly has problems with these test cases") class SqlAlchemyUpdateTest(TestCase): def setUp(self):