github.com/dolthub/go-mysql-server@v0.18.0/_integration/python-pymysql/test.py (about) 1 # Copyright 2020-2021 Dolthub, Inc. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # 15 # Licensed under the Apache License, Version 2.0 (the "License"); 16 # you may not use this file except in compliance with the License. 17 # You may obtain a copy of the License at 18 # 19 # http://www.apache.org/licenses/LICENSE-2.0 20 # 21 # Unless required by applicable law or agreed to in writing, software 22 # distributed under the License is distributed on an "AS IS" BASIS, 23 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 # See the License for the specific language governing permissions and 25 # limitations under the License. 26 27 import unittest 28 import pymysql.cursors 29 30 class TestMySQL(unittest.TestCase): 31 32 def test_connect(self): 33 connection = pymysql.connect(host='127.0.0.1', 34 user='root', 35 password='', 36 db='', 37 cursorclass=pymysql.cursors.DictCursor) 38 39 try: 40 with connection.cursor() as cursor: 41 sql = "SELECT name, email FROM mytable ORDER BY name, email" 42 cursor.execute(sql) 43 rows = cursor.fetchall() 44 45 expected = [ 46 {"name": "Evil Bob", "email": "evilbob@gmail.com"}, 47 {"name": "Jane Doe", "email": "jane@doe.com"}, 48 {"name": "John Doe", "email": "john@doe.com"}, 49 {"name": "John Doe", "email": "johnalt@doe.com"} 50 ] 51 52 self.assertEqual(expected, rows) 53 finally: 54 connection.close() 55 56 57 if __name__ == '__main__': 58 unittest.main()