-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Switch to mysqlclient from pymysql (#8)
Switch to mysqlclient from pymysql Fix failing tests and run linting
- Loading branch information
1 parent
376cb3e
commit 3ce8679
Showing
10 changed files
with
492 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,19 +16,19 @@ | |
from tap_mysql.tap import TapMySQL | ||
|
||
from .test_replication_key import TABLE_NAME, TapTestReplicationKey | ||
from .test_selected_columns_only import ( | ||
TABLE_NAME_SELECTED_COLUMNS_ONLY, | ||
TapTestSelectedColumnsOnly, | ||
) | ||
|
||
SAMPLE_CONFIG = { | ||
"start_date": pendulum.datetime(2022, 11, 1).to_iso8601_string(), | ||
"sqlalchemy_url": "mysql+pymysql://root:password@localhost:3306/melty", | ||
# Using 127.0.0.1 instead of localhost because of mysqlclient dialect. | ||
# See: https://stackoverflow.com/questions/72294279/how-to-connect-to-mysql-databas-using-github-actions | ||
"sqlalchemy_url": "mysql+mysqldb://root:[email protected]:3306/melty", | ||
} | ||
|
||
NO_SQLALCHEMY_CONFIG = { | ||
"start_date": pendulum.datetime(2022, 11, 1).to_iso8601_string(), | ||
"host": "localhost", | ||
# Using 127.0.0.1 instead of localhost because of mysqlclient dialect. | ||
# See: https://stackoverflow.com/questions/72294279/how-to-connect-to-mysql-databas-using-github-actions | ||
"host": "127.0.0.1", | ||
"port": 3306, | ||
"user": "root", | ||
"password": "password", | ||
|
@@ -73,10 +73,6 @@ def teardown_test_table(table_name, sqlalchemy_url): | |
tests=[TapTestReplicationKey], | ||
) | ||
|
||
custom_test_selected_columns_only = suites.TestSuite( | ||
kind="tap", | ||
tests=[TapTestSelectedColumnsOnly], | ||
) | ||
|
||
TapMySQLTest = get_tap_test_class( | ||
tap_class=TapMySQL, | ||
|
@@ -93,15 +89,6 @@ def teardown_test_table(table_name, sqlalchemy_url): | |
) | ||
|
||
|
||
# creating testing instance for isolated table in mysql | ||
TapMySQLTestSelectedColumnsOnly = get_tap_test_class( | ||
tap_class=TapMySQL, | ||
config=SAMPLE_CONFIG, | ||
catalog="tests/resources/data_selected_columns_only.json", | ||
custom_suites=[custom_test_selected_columns_only], | ||
) | ||
|
||
|
||
class TestTapMySQL(TapMySQLTest): | ||
table_name = TABLE_NAME | ||
sqlalchemy_url = SAMPLE_CONFIG["sqlalchemy_url"] | ||
|
@@ -124,17 +111,6 @@ def resource(self): | |
teardown_test_table(self.table_name, self.sqlalchemy_url) | ||
|
||
|
||
class TestTapMySQLSelectedColumnsOnly(TapMySQLTestSelectedColumnsOnly): | ||
table_name = TABLE_NAME_SELECTED_COLUMNS_ONLY | ||
sqlalchemy_url = SAMPLE_CONFIG["sqlalchemy_url"] | ||
|
||
@pytest.fixture(scope="class") | ||
def resource(self): | ||
setup_test_table(self.table_name, self.sqlalchemy_url) | ||
yield | ||
teardown_test_table(self.table_name, self.sqlalchemy_url) | ||
|
||
|
||
def test_temporal_datatypes(): | ||
"""Dates were being incorrectly parsed as date times (issue #171). | ||
|
@@ -149,7 +125,7 @@ def test_temporal_datatypes(): | |
table_name, | ||
metadata_obj, | ||
Column("column_date", DATE), | ||
Column("column_time", TIME), | ||
Column("column_time", TIME(timezone=False, fsp=6)), | ||
Column("column_timestamp", DATETIME), | ||
) | ||
with engine.connect() as conn: | ||
|
@@ -164,7 +140,7 @@ def test_temporal_datatypes(): | |
conn.execute(insert) | ||
tap = TapMySQL(config=SAMPLE_CONFIG) | ||
tap_catalog = json.loads(tap.catalog_json_text) | ||
altered_table_name = f"public_{table_name}" | ||
altered_table_name = f"melty-{table_name}" | ||
for stream in tap_catalog["streams"]: | ||
if stream.get("stream") and altered_table_name not in stream["stream"]: | ||
for metadata in stream["metadata"]: | ||
|
@@ -221,7 +197,7 @@ def test_jsonb_json(): | |
conn.execute(insert) | ||
tap = TapMySQL(config=SAMPLE_CONFIG) | ||
tap_catalog = json.loads(tap.catalog_json_text) | ||
altered_table_name = f"public_{table_name}" | ||
altered_table_name = f"melty-{table_name}" | ||
for stream in tap_catalog["streams"]: | ||
if stream.get("stream") and altered_table_name not in stream["stream"]: | ||
for metadata in stream["metadata"]: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,9 @@ | |
TABLE_NAME = "test_replication_key" | ||
SAMPLE_CONFIG = { | ||
"start_date": pendulum.datetime(2022, 11, 1).to_iso8601_string(), | ||
"sqlalchemy_url": "mysql+pymysql://root:password@localhost:3307/melty", | ||
# Using 127.0.0.1 instead of localhost because of mysqlclient dialect. | ||
# See: https://stackoverflow.com/questions/72294279/how-to-connect-to-mysql-databas-using-github-actions | ||
"sqlalchemy_url": f"mysql+mysqldb://root:[email protected]:3306/melty", | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,19 @@ | |
# flake8: noqa | ||
import json | ||
|
||
import pytest | ||
from singer_sdk.testing import get_tap_test_class, suites | ||
from singer_sdk.testing.templates import TapTestTemplate | ||
|
||
from tap_mysql.tap import TapMySQL | ||
|
||
from .test_core import setup_test_table, teardown_test_table | ||
|
||
TABLE_NAME_SELECTED_COLUMNS_ONLY = "test_selected_columns_only" | ||
SAMPLE_CONFIG = { | ||
"sqlalchemy_url": "mysql+pymysql://root:password@localhost:3307/melty", | ||
# Using 127.0.0.1 instead of localhost because of mysqlclient dialect. | ||
# See: https://stackoverflow.com/questions/72294279/how-to-connect-to-mysql-databas-using-github-actions | ||
"sqlalchemy_url": f"mysql+mysqldb://root:[email protected]:3306/melty", | ||
} | ||
|
||
|
||
|
@@ -40,5 +46,27 @@ class TapTestSelectedColumnsOnly(TapTestTemplate): | |
name = "selected_columns_only" | ||
table_name = TABLE_NAME_SELECTED_COLUMNS_ONLY | ||
|
||
def test(self): | ||
selected_columns_only_test(self.tap, self.table_name) | ||
|
||
custom_test_selected_columns_only = suites.TestSuite( | ||
kind="tap", | ||
tests=[TapTestSelectedColumnsOnly], | ||
) | ||
|
||
# creating testing instance for isolated table in mysql | ||
TapMySQLTestSelectedColumnsOnly = get_tap_test_class( | ||
tap_class=TapMySQL, | ||
config=SAMPLE_CONFIG, | ||
catalog="tests/resources/data_selected_columns_only.json", | ||
custom_suites=[custom_test_selected_columns_only], | ||
) | ||
|
||
|
||
class TestTapMySQLSelectedColumnsOnly(TapMySQLTestSelectedColumnsOnly): | ||
table_name = TABLE_NAME_SELECTED_COLUMNS_ONLY | ||
sqlalchemy_url = SAMPLE_CONFIG["sqlalchemy_url"] | ||
|
||
@pytest.fixture(scope="class") | ||
def resource(self): | ||
setup_test_table(self.table_name, self.sqlalchemy_url) | ||
yield | ||
teardown_test_table(self.table_name, self.sqlalchemy_url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
TABLE_NAME = "test_replication_key" | ||
SAMPLE_CONFIG = { | ||
"sqlalchemy_url": "mysql+pymysql://root:[email protected]:3306/melty", | ||
"sqlalchemy_url": "mysql+mysqldb://root:[email protected]:3306/melty", | ||
"ssh_tunnel": { | ||
"enable": True, | ||
"host": "127.0.0.1", | ||
|
@@ -15,7 +15,8 @@ | |
}, | ||
} | ||
|
||
def test_ssh_tunnel(): | ||
"""We expect the SSH environment to already be up""" | ||
|
||
def test_ssh_tunnel() -> None: | ||
"""We expect the SSH environment to already be up.""" | ||
tap = TapMySQL(config=SAMPLE_CONFIG) | ||
tap.sync_all() | ||
tap.sync_all() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,48 @@ | ||
# This file can be used to customize tox tests as well as other test frameworks like flake8 and mypy | ||
|
||
[tox] | ||
envlist = py37, py38, py39, py310, py311 | ||
envlist = py39 | ||
; envlist = py37, py38, py39 | ||
isolated_build = true | ||
|
||
[testenv] | ||
allowlist_externals = poetry | ||
whitelist_externals = poetry | ||
|
||
commands = | ||
poetry install -v | ||
poetry run pytest | ||
poetry run black --check tap_mysql | ||
poetry run flake8 tap_mysql | ||
|
||
[testenv:pytest] | ||
# Run the python tests. | ||
# To execute, run `tox -e pytest` | ||
envlist = py37, py38, py39, py310, py311 | ||
envlist = py37, py38, py39 | ||
commands = | ||
poetry install -v | ||
poetry run pytest | ||
|
||
[testenv:format] | ||
# Attempt to auto-resolve lint errors before they are raised. | ||
# To execute, run `tox -e format` | ||
commands = | ||
poetry install -v | ||
poetry run black tap_mysql | ||
poetry run isort tap_mysql | ||
|
||
[testenv:lint] | ||
# Raise an error if lint and style standards are not met. | ||
# To execute, run `tox -e lint` | ||
commands = | ||
poetry install -v | ||
poetry run black --check --diff tap_mysql/ | ||
poetry run isort --check tap_mysql | ||
poetry run flake8 tap_mysql | ||
|
||
[flake8] | ||
ignore = W503 | ||
max-line-length = 88 | ||
max-complexity = 10 | ||
|
||
[pydocstyle] | ||
ignore = D105,D203,D213 |