Skip to content

Commit 364e4e4

Browse files
committed
chore: address comments and fix unit tests
1 parent 5726f11 commit 364e4e4

File tree

5 files changed

+28
-74
lines changed

5 files changed

+28
-74
lines changed

tests/integration/host/build.gradle.kts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ tasks.register<Test>("test-python-3.11-mysql") {
6868
filter.includeTestsMatching("integration.host.TestRunner.runTests")
6969
doFirst {
7070
systemProperty("exclude-performance", "true")
71-
systemProperty("exclude-python-312", "true")
72-
systemProperty("exclude-python-313", "true")
71+
systemProperty("exclude-python-3-12", "true")
72+
systemProperty("exclude-python-3-13", "true")
7373
systemProperty("exclude-multi-az-cluster", "true")
7474
systemProperty("exclude-multi-az-instance", "true")
7575
systemProperty("exclude-bg", "true")
@@ -85,8 +85,8 @@ tasks.register<Test>("test-python-3.11-pg") {
8585
filter.includeTestsMatching("integration.host.TestRunner.runTests")
8686
doFirst {
8787
systemProperty("exclude-performance", "true")
88-
systemProperty("exclude-python-312", "true")
89-
systemProperty("exclude-python-313", "true")
88+
systemProperty("exclude-python-3-12", "true")
89+
systemProperty("exclude-python-3-13", "true")
9090
systemProperty("exclude-multi-az-cluster", "true")
9191
systemProperty("exclude-multi-az-instance", "true")
9292
systemProperty("exclude-bg", "true")
@@ -102,8 +102,8 @@ tasks.register<Test>("test-python-3.12-mysql") {
102102
filter.includeTestsMatching("integration.host.TestRunner.runTests")
103103
doFirst {
104104
systemProperty("exclude-performance", "true")
105-
systemProperty("exclude-python-311", "true")
106-
systemProperty("exclude-python-313", "true")
105+
systemProperty("exclude-python-3-11", "true")
106+
systemProperty("exclude-python-3-13", "true")
107107
systemProperty("exclude-multi-az-cluster", "true")
108108
systemProperty("exclude-multi-az-instance", "true")
109109
systemProperty("exclude-traces-telemetry", "true")
@@ -119,8 +119,8 @@ tasks.register<Test>("test-python-3.12-pg") {
119119
filter.includeTestsMatching("integration.host.TestRunner.runTests")
120120
doFirst {
121121
systemProperty("exclude-performance", "true")
122-
systemProperty("exclude-python-311", "true")
123-
systemProperty("exclude-python-313", "true")
122+
systemProperty("exclude-python-3-11", "true")
123+
systemProperty("exclude-python-3-13", "true")
124124
systemProperty("exclude-multi-az-cluster", "true")
125125
systemProperty("exclude-multi-az-instance", "true")
126126
systemProperty("exclude-bg", "true")
@@ -136,8 +136,8 @@ tasks.register<Test>("test-python-3.13-mysql") {
136136
filter.includeTestsMatching("integration.host.TestRunner.runTests")
137137
doFirst {
138138
systemProperty("exclude-performance", "true")
139-
systemProperty("exclude-python-311", "true")
140-
systemProperty("exclude-python-312", "true")
139+
systemProperty("exclude-python-3-11", "true")
140+
systemProperty("exclude-python-3-12", "true")
141141
systemProperty("exclude-multi-az-cluster", "true")
142142
systemProperty("exclude-multi-az-instance", "true")
143143
systemProperty("exclude-bg", "true")
@@ -153,8 +153,8 @@ tasks.register<Test>("test-python-3.13-pg") {
153153
filter.includeTestsMatching("integration.host.TestRunner.runTests")
154154
doFirst {
155155
systemProperty("exclude-performance", "true")
156-
systemProperty("exclude-python-311", "true")
157-
systemProperty("exclude-python-312", "true")
156+
systemProperty("exclude-python-3-11", "true")
157+
systemProperty("exclude-python-3-12", "true")
158158
systemProperty("exclude-multi-az-cluster", "true")
159159
systemProperty("exclude-multi-az-instance", "true")
160160
systemProperty("exclude-bg", "true")

tests/integration/host/src/test/java/integration/host/TestEnvironmentConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public class TestEnvironmentConfiguration {
7070
Boolean.parseBoolean(System.getProperty("test-bg-only", "false"));
7171

7272
public boolean excludePython311 =
73-
Boolean.parseBoolean(System.getProperty("exclude-python-311", "false"));
73+
Boolean.parseBoolean(System.getProperty("exclude-python-3-11", "false"));
7474
public boolean excludePython312 =
75-
Boolean.parseBoolean(System.getProperty("exclude-python-312", "false"));
75+
Boolean.parseBoolean(System.getProperty("exclude-python-3-12", "false"));
7676
public boolean excludePython313 =
77-
Boolean.parseBoolean(System.getProperty("exclude-python-313", "false"));
77+
Boolean.parseBoolean(System.getProperty("exclude-python-3-13", "false"));
7878

7979
public String testFilter = System.getenv("FILTER");
8080

tests/unit/test_connection_provider.py

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
import psycopg
1616
import pytest
1717

18-
from aws_advanced_python_wrapper.connection_provider import (
19-
ConnectionProviderManager, DriverConnectionProvider)
18+
from aws_advanced_python_wrapper.connection_provider import (ConnectionProviderManager, DriverConnectionProvider)
2019
from aws_advanced_python_wrapper.hostinfo import HostInfo, HostRole
20+
from aws_advanced_python_wrapper.sql_alchemy_connection_provider import SqlAlchemyPooledConnectionProvider
2121
from aws_advanced_python_wrapper.utils.properties import Properties
2222

2323

@@ -28,36 +28,12 @@ def connection_mock(mocker):
2828

2929
@pytest.fixture
3030
def default_provider_mock(mocker):
31-
return mocker.MagicMock()
31+
return mocker.MagicMock(spec=DriverConnectionProvider)
3232

3333

3434
@pytest.fixture
3535
def set_provider_mock(mocker):
36-
# In Python 3.12+, isinstance checks with Protocols are stricter
37-
# Create a real instance that implements the protocol, then wrap release_resources
38-
# with a mock to allow method call tracking
39-
class MockConnectionProviderWithRelease:
40-
"""Mock connection provider that implements CanReleaseResources protocol."""
41-
def accepts_host_info(self, host_info, props):
42-
return True
43-
44-
def accepts_strategy(self, role, strategy):
45-
return True
46-
47-
def get_host_info_by_strategy(self, hosts, role, strategy, props):
48-
return hosts[0] if hosts else None
49-
50-
def connect(self, target_func, driver_dialect, database_dialect, host_info, props):
51-
return None
52-
53-
def release_resources(self):
54-
pass
55-
56-
# Create a real instance
57-
provider = MockConnectionProviderWithRelease()
58-
# Replace release_resources with a MagicMock so we can assert it was called
59-
provider.release_resources = mocker.MagicMock()
60-
return provider
36+
return mocker.MagicMock(spec=SqlAlchemyPooledConnectionProvider)
6137

6238

6339
@pytest.fixture
@@ -196,8 +172,7 @@ def test_manager_get_host_info_by_strategy(connection_mock, default_provider_moc
196172
assert host_info.host == "other"
197173

198174

199-
def test_release_resources(connection_mock, default_provider_mock, set_provider_mock):
200-
connection_provider_manager = ConnectionProviderManager(default_provider_mock)
175+
def test_release_resources(connection_mock, set_provider_mock):
201176
ConnectionProviderManager.set_connection_provider(set_provider_mock)
202177
ConnectionProviderManager.release_resources()
203178

tests/unit/test_mysql_driver_dialect.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,15 @@
1414

1515
import psycopg
1616
import pytest
17+
from mysql.connector import MySQLConnection
18+
from mysql.connector.cursor import MySQLCursor
1719

1820
from aws_advanced_python_wrapper.errors import AwsWrapperError
1921
from aws_advanced_python_wrapper.hostinfo import HostInfo
2022
from aws_advanced_python_wrapper.mysql_driver_dialect import MySQLDriverDialect
2123
from aws_advanced_python_wrapper.utils.properties import (Properties,
2224
WrapperProperties)
2325

24-
try:
25-
from mysql.connector import CMySQLConnection
26-
from mysql.connector.cursor_cext import CMySQLCursor
27-
except ImportError:
28-
# CMySQLConnection not available (e.g., Python 3.13 with mysql-connector-python 9.0.0)
29-
# Skip all tests in this module if C extension is not available
30-
pytest.skip(
31-
"CMySQLConnection not available (C extension not supported on this Python version)",
32-
allow_module_level=True
33-
)
34-
3526

3627
@pytest.fixture
3728
def dialect():
@@ -40,7 +31,7 @@ def dialect():
4031

4132
@pytest.fixture
4233
def mock_conn(mocker):
43-
return mocker.MagicMock(spec=CMySQLConnection)
34+
return mocker.MagicMock(spec=MySQLConnection)
4435

4536

4637
@pytest.fixture
@@ -93,7 +84,7 @@ def test_autocommit(dialect, mock_conn, mock_invalid_conn):
9384

9485
def test_transfer_session_state(dialect, mocker, mock_conn):
9586
mock_conn.autocommit = False
96-
new_conn = mocker.MagicMock(spec=CMySQLConnection)
87+
new_conn = mocker.MagicMock(spec=MySQLConnection)
9788

9889
new_conn.autocommit = True
9990
dialect.transfer_session_state(mock_conn, new_conn)
@@ -104,8 +95,8 @@ def test_transfer_session_state(dialect, mocker, mock_conn):
10495
def test_get_connection_from_obj(dialect, mocker, mock_conn, mock_invalid_conn):
10596
assert dialect.get_connection_from_obj(mock_conn) == mock_conn
10697

107-
mock_cursor = mocker.MagicMock(spec=CMySQLCursor)
108-
mock_cursor._cnx = mock_conn
98+
mock_cursor = mocker.MagicMock(spec=MySQLCursor)
99+
mock_cursor._connection = mock_conn
109100
assert dialect.get_connection_from_obj(mock_cursor) == mock_conn
110101

111102
assert dialect.get_connection_from_obj(mock_invalid_conn) is None

tests/unit/test_pg_driver_dialect.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import psycopg
1616
import pytest
17+
from mysql.connector import MySQLConnection
1718
from sqlalchemy import PoolProxiedConnection
1819

1920
from aws_advanced_python_wrapper.errors import AwsWrapperError
@@ -22,14 +23,6 @@
2223
from aws_advanced_python_wrapper.utils.properties import (Properties,
2324
WrapperProperties)
2425

25-
try:
26-
from mysql.connector import CMySQLConnection
27-
HAS_C_MYSQL_CONNECTION = True
28-
except ImportError:
29-
# CMySQLConnection not available (e.g., Python 3.13 with mysql-connector-python 9.0.0)
30-
HAS_C_MYSQL_CONNECTION = False
31-
CMySQLConnection = None
32-
3326

3427
@pytest.fixture
3528
def mock_conn(mocker):
@@ -47,12 +40,7 @@ def mock_pool_conn(mocker, mock_conn):
4740

4841
@pytest.fixture
4942
def mock_invalid_conn(mocker):
50-
if HAS_C_MYSQL_CONNECTION:
51-
return mocker.MagicMock(spec=CMySQLConnection)
52-
else:
53-
# Use a different invalid connection type when CMySQLConnection is not available
54-
# This simulates an invalid connection type for error testing
55-
return mocker.MagicMock(spec=object)
43+
return mocker.MagicMock(spec=MySQLConnection)
5644

5745

5846
@pytest.fixture

0 commit comments

Comments
 (0)