forked from wikimedia/pywikibot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bugfix] Context manager depends on pymysql version, not Python release
If installing pymysql its version depends on Python release. But if pymysql is already installed it may be outdated. pymysql >= 1.0.0 gives a context manager with the connection but older don't. Therefore check for the pymysql.__version__ and use closing context manager wrapper if necessary. - check for pymysql.__version__ instead Python release - add mysql_tests.py to test this behaviour mentioned above - yield 'test' if we just run test - increase min version that defer_connect parameter can be used for tests - add mysql to coverage Bug: T279753 Change-Id: Ia1b1857f42661e76693e75a0260ac8841d9e6a91
- Loading branch information
Showing
5 changed files
with
42 additions
and
5 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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Tests for mysql module.""" | ||
# | ||
# (C) Pywikibot team, 2021 | ||
# | ||
# Distributed under the terms of the MIT license. | ||
# | ||
from contextlib import suppress | ||
from types import GeneratorType | ||
|
||
import unittest | ||
|
||
from pywikibot import data | ||
|
||
from tests.aspects import TestCase, require_modules | ||
|
||
|
||
@require_modules('pymysql') | ||
class TestMySQL(TestCase): | ||
|
||
"""Test data.mysql.""" | ||
|
||
net = False | ||
|
||
def test_mysql(self): | ||
"""Test data.mysql.mysql_query function.""" | ||
result = data.mysql.mysql_query('test') | ||
self.assertIsInstance(result, GeneratorType) | ||
self.assertEqual(next(result), 'test') | ||
|
||
|
||
if __name__ == '__main__': # pragma: no cover | ||
with suppress(SystemExit): | ||
unittest.main() |