github.com/dolthub/go-mysql-server@v0.18.0/_integration/python-sqlalchemy/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 pandas as pd
    29  import sqlalchemy
    30  
    31  
    32  class TestMySQL(unittest.TestCase):
    33  
    34      def test_connect(self):
    35          engine = sqlalchemy.create_engine('mysql+mysqldb://root:@127.0.0.1:3306/mydb')
    36          with engine.connect() as conn:
    37              expected = {
    38                  "name":  {0: 'John Doe', 1: 'John Doe', 2: 'Jane Doe', 3: 'Evil Bob'},
    39                  "email": {0: 'john@doe.com', 1: 'johnalt@doe.com', 2: 'jane@doe.com', 3: 'evilbob@gmail.com'},
    40                  "phone_numbers": {0: ['555-555-555'], 1: [], 2: [], 3: ['555-666-555', '666-666-666']},
    41              }
    42              repo_df = pd.read_sql_table("mytable", con=conn)
    43              d = repo_df.to_dict()
    44              del d["created_at"]
    45              self.assertEqual(expected, d)
    46  
    47  
    48  if __name__ == '__main__':
    49      unittest.main()