Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
118 additions
and
76 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
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 |
---|---|---|
@@ -1,42 +1,57 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
import os | ||
from tornado import gen | ||
from tornado.testing import gen_test | ||
from tormysql.cursor import SSDictCursor | ||
from . import BaseTestCase | ||
|
||
from tormysql import ConnectionPool | ||
|
||
class TestWithWith(BaseTestCase): | ||
@gen_test | ||
def test1(self): | ||
@gen.coroutine | ||
def _execute_test1(self): | ||
sql = "select * from test limit 1" | ||
with (yield self.pool.Connection()) as connection: | ||
with connection.cursor() as cursor: | ||
yield cursor.execute(sql) | ||
datas = cursor.fetchall() | ||
self.assertTrue(bool(datas)) | ||
|
||
yield self.pool.close() | ||
|
||
class TestAsyncCursor(BaseTestCase): | ||
PARAMS = dict( | ||
host=os.getenv("MYSQL_HOST", "127.0.0.1"), | ||
user=os.getenv("MYSQL_USER", "root"), | ||
passwd=os.getenv("MYSQL_PASSWD", ""), | ||
db=os.getenv("MYSQL_DB", "test"), | ||
charset=os.getenv("MYSQL_CHARSET", "utf8"), | ||
no_delay=True, | ||
sql_mode="REAL_AS_FLOAT", | ||
init_command="SET max_join_size=DEFAULT", | ||
cursorclass=SSDictCursor | ||
) | ||
def init_params(self): | ||
self.PARAMS = dict( | ||
host=os.getenv("MYSQL_HOST", "127.0.0.1"), | ||
user=os.getenv("MYSQL_USER", "root"), | ||
passwd=os.getenv("MYSQL_PASSWD", ""), | ||
db=os.getenv("MYSQL_DB", "test"), | ||
charset=os.getenv("MYSQL_CHARSET", "utf8"), | ||
no_delay=True, | ||
sql_mode="REAL_AS_FLOAT", | ||
init_command="SET max_join_size=DEFAULT", | ||
cursorclass=SSDictCursor | ||
) | ||
|
||
@gen_test | ||
def test1(self): | ||
self.pool = ConnectionPool( | ||
max_connections=int(os.getenv("MYSQL_POOL", 5)), | ||
idle_seconds=7200, | ||
**self.PARAMS | ||
) | ||
|
||
@gen.coroutine | ||
def _execute_test2(self): | ||
self.init_params() | ||
sql = "select 1 as test" | ||
with (yield self.pool.Connection()) as connection: | ||
cursor = connection.cursor() | ||
yield cursor.execute(sql) | ||
result = yield cursor.fetchone() | ||
yield cursor.close() | ||
self.assertTrue('test' in result) | ||
self.assertEqual(result['test'], 1) | ||
self.assertEqual(result['test'], 1) | ||
|
||
@gen_test | ||
def test(self): | ||
yield self._execute_test1() | ||
yield self._execute_test2() |
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
Oops, something went wrong.