From c93ebc0cebff04a762f8a6d90d45805426018b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Sat, 26 Oct 2024 12:03:10 +0100 Subject: [PATCH] :art: implement CodeRabbit suggestions --- src/sqlite3_to_mysql/mysql_utils.py | 10 ++++-- tests/func/sqlite3_to_mysql_test.py | 2 +- tests/unit/mysql_utils_test.py | 56 +++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 tests/unit/mysql_utils_test.py diff --git a/src/sqlite3_to_mysql/mysql_utils.py b/src/sqlite3_to_mysql/mysql_utils.py index 32495ed..703470c 100644 --- a/src/sqlite3_to_mysql/mysql_utils.py +++ b/src/sqlite3_to_mysql/mysql_utils.py @@ -114,8 +114,10 @@ def check_mysql_json_support(version_string: str) -> bool: """Check for MySQL JSON support.""" mysql_version: Version = get_mysql_version(version_string) if "mariadb" in version_string.lower(): - if mysql_version.major >= 10 and mysql_version.minor >= 2 and mysql_version.micro >= 7: + if mysql_version.major > 10: return True + if mysql_version.major == 10: + return mysql_version.minor > 2 or (mysql_version.minor >= 2 and mysql_version.micro >= 7) else: if mysql_version.major >= 8: return True @@ -145,9 +147,11 @@ def check_mysql_values_alias_support(version_string: str) -> bool: def check_mysql_fulltext_support(version_string: str) -> bool: """Check for FULLTEXT indexing support.""" mysql_version: Version = get_mysql_version(version_string) - if version_string.lower().endswith("-mariadb"): - if mysql_version.major >= 10 and mysql_version.minor >= 0 and mysql_version.micro >= 5: + if "mariadb" in version_string.lower(): + if mysql_version.major > 10: return True + if mysql_version.major == 10: + return mysql_version.minor > 0 or (mysql_version.minor >= 0 and mysql_version.micro >= 5) else: if mysql_version.major >= 8: return True diff --git a/tests/func/sqlite3_to_mysql_test.py b/tests/func/sqlite3_to_mysql_test.py index a259554..bb887cb 100644 --- a/tests/func/sqlite3_to_mysql_test.py +++ b/tests/func/sqlite3_to_mysql_test.py @@ -59,7 +59,7 @@ def test_valid_sqlite_file_and_valid_mysql_credentials( mysql_credentials: MySQLCredentials, helpers: Helpers, quiet: bool, - ): + ) -> None: with helpers.not_raises(FileNotFoundError): SQLite3toMySQL( # type: ignore sqlite_file=sqlite_database, diff --git a/tests/unit/mysql_utils_test.py b/tests/unit/mysql_utils_test.py new file mode 100644 index 0000000..cd9a9ce --- /dev/null +++ b/tests/unit/mysql_utils_test.py @@ -0,0 +1,56 @@ +import pytest + +from sqlite3_to_mysql.mysql_utils import ( + check_mysql_fulltext_support, + check_mysql_json_support, + check_mysql_values_alias_support, +) + + +class TestMySQLUtils: + @pytest.mark.parametrize( + "version_string,expected", + [ + ("5.7.7", False), + ("5.7.8", True), + ("8.0.0", True), + ("9.0.0", True), + ("10.2.6-mariadb", False), + ("10.2.7-mariadb", True), + ("11.4.0-mariadb", True), + ], + ) + def test_check_mysql_json_support(self, version_string: str, expected: bool) -> None: + assert check_mysql_json_support(version_string) == expected + + @pytest.mark.parametrize( + "version_string,expected", + [ + ("5.7.8", False), + ("8.0.0", False), + ("8.0.18", False), + ("8.0.19", True), + ("9.0.0", True), + ("10.2.6-mariadb", False), + ("10.2.7-mariadb", False), + ("11.4.0-mariadb", False), + ], + ) + def test_check_mysql_values_alias_support(self, version_string: str, expected: bool) -> None: + assert check_mysql_values_alias_support(version_string) == expected + + @pytest.mark.parametrize( + "version_string,expected", + [ + ("5.0.0", False), + ("5.5.0", False), + ("5.6.0", True), + ("8.0.0", True), + ("10.0.4-mariadb", False), + ("10.0.5-mariadb", True), + ("10.2.6-mariadb", True), + ("11.4.0-mariadb", True), + ], + ) + def test_check_mysql_fulltext_support(self, version_string: str, expected: bool) -> None: + assert check_mysql_fulltext_support(version_string) == expected