• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python tests.get_mysql_config函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tests.get_mysql_config函数的典型用法代码示例。如果您正苦于以下问题:Python get_mysql_config函数的具体用法?Python get_mysql_config怎么用?Python get_mysql_config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_mysql_config函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_dates

    def test_dates(self):
        """examples/dates.py"""
        try:
            import examples.dates as example
        except Exception as err:
            self.fail(err)
        output = example.main(tests.get_mysql_config())
        exp = ['  1 | 1977-06-14 | 1977-06-14 21:10:00 | 21:10:00 |',
               '  2 |       None |                None |  0:00:00 |',
               '  3 |       None |                None |  0:00:00 |']
        self.assertEqual(output, exp)

        example.DATA.append(('0000-00-00', None, '00:00:00'),)
        self.assertRaises(mysql.connector.errors.IntegrityError,
                          example.main, tests.get_mysql_config())
开发者ID:Tarhan,项目名称:mysql-connector-python,代码行数:15,代码来源:test_examples.py


示例2: test_connect

    def test_connect(self):
        """Interface exports the connect()-function"""
        self.assertTrue(inspect.isfunction(myconn.connect),
                        "Module does not export the connect()-function")
        cnx = myconn.connect(use_pure=True, **tests.get_mysql_config())
        self.assertTrue(isinstance(cnx, myconn.connection.MySQLConnection),
                        "connect() not returning by default pure "
                        "MySQLConnection object")

        if tests.MYSQL_CAPI:
            # By default use_pure=False
            cnx = myconn.connect(**tests.get_mysql_config())
            self.assertTrue(isinstance(cnx,
                                       myconn.connection_cext.CMySQLConnection),
                            "The connect()-method returns incorrect instance")
开发者ID:dveeden,项目名称:mysql-connector-python,代码行数:15,代码来源:test_pep249.py


示例3: test_get_connection

    def test_get_connection(self):
        dbconfig = tests.get_mysql_config()
        cnxpool = pooling.MySQLConnectionPool(pool_size=2, pool_name='test')

        self.assertRaises(errors.PoolError, cnxpool.get_connection)

        cnxpool = pooling.MySQLConnectionPool(pool_size=1, **dbconfig)

        # Get connection from pool
        pcnx = cnxpool.get_connection()
        self.assertTrue(isinstance(pcnx, pooling.PooledMySQLConnection))
        self.assertRaises(errors.PoolError, cnxpool.get_connection)
        self.assertEqual(pcnx._cnx._pool_config_version,
                         cnxpool._config_version)
        prev_config_version = pcnx._pool_config_version
        prev_thread_id = pcnx.connection_id
        pcnx.close()

        # Change configuration
        config_version = cnxpool._config_version
        cnxpool.set_config(autocommit=True)
        self.assertNotEqual(config_version, cnxpool._config_version)

        pcnx = cnxpool.get_connection()
        self.assertNotEqual(
            pcnx._cnx._pool_config_version, prev_config_version)
        self.assertNotEqual(prev_thread_id, pcnx.connection_id)
        self.assertEqual(1, pcnx.autocommit)
        pcnx.close()
开发者ID:hitigon,项目名称:mysql-connector-python,代码行数:29,代码来源:test_pooling.py


示例4: setUp

    def setUp(self):
        config = tests.get_mysql_config()
        config['raw'] = True
        config['buffered'] = True

        self.connection = connection.MySQLConnection(**config)
        self.cur = self.connection.cursor()
开发者ID:richfab,项目名称:LOG210-server,代码行数:7,代码来源:cursor.py


示例5: test_connect

 def test_connect(self):
     """Interface exports the connect()-function"""
     self.assertTrue(inspect.isfunction(myconn.connect),
                     "Module does not export the connect()-function")
     cnx = myconn.connect(**tests.get_mysql_config())
     self.assertTrue(isinstance(cnx, myconn.connection.MySQLConnection),
                     "The connect()-method returns incorrect instance")
开发者ID:allienson,项目名称:LP_trab_python,代码行数:7,代码来源:test_pep249.py


示例6: test_add_connection

    def test_add_connection(self):
        cnxpool = pooling.MySQLConnectionPool(pool_name='test')
        self.assertRaises(errors.PoolError, cnxpool.add_connection)

        dbconfig = tests.get_mysql_config()
        cnxpool = pooling.MySQLConnectionPool(pool_size=2, pool_name='test')
        cnxpool.set_config(**dbconfig)

        cnxpool.add_connection()
        pcnx = pooling.PooledMySQLConnection(
            cnxpool,
            cnxpool._cnx_queue.get(block=False))
        self.assertTrue(isinstance(pcnx._cnx, MySQLConnection))
        self.assertEqual(cnxpool, pcnx._cnx_pool)
        self.assertEqual(cnxpool._config_version,
                         pcnx._cnx._pool_config_version)

        cnx = pcnx._cnx
        pcnx.close()
        # We should get the same connectoin back
        self.assertEqual(cnx, cnxpool._cnx_queue.get(block=False))
        cnxpool.add_connection(cnx)

        # reach max connections
        cnxpool.add_connection()
        self.assertRaises(errors.PoolError, cnxpool.add_connection)

        # fail connecting
        cnxpool._remove_connections()
        cnxpool._cnx_config['port'] = 9999999
        cnxpool._cnx_config['unix_socket'] = '/ham/spam/foobar.socket'
        self.assertRaises(errors.InterfaceError, cnxpool.add_connection)

        self.assertRaises(errors.PoolError, cnxpool.add_connection, cnx=str)
开发者ID:hitigon,项目名称:mysql-connector-python,代码行数:34,代码来源:test_pooling.py


示例7: test__handle_result

    def test__handle_result(self):
        """MySQLCursor object _handle_result()-method"""
        self.connection = connection.MySQLConnection(**tests.get_mysql_config())
        self.cur = self.connection.cursor()

        self.assertRaises(errors.InterfaceError, self.cur._handle_result, None)
        self.assertRaises(errors.InterfaceError, self.cur._handle_result,
                          'spam')
        self.assertRaises(errors.InterfaceError, self.cur._handle_result,
                          {'spam': 5})

        cases = [
            {'affected_rows': 99999,
                'insert_id': 10,
                'warning_count': 100,
                'server_status': 8,
             },
            {'eof': {'status_flag': 0, 'warning_count': 0},
                'columns': [('1', 8, None, None, None, None, 0, 129)]
             },
        ]
        self.cur._handle_result(cases[0])
        self.assertEqual(cases[0]['affected_rows'], self.cur.rowcount)
        self.assertFalse(self.cur._connection.unread_result)
        self.assertFalse(self.cur._have_unread_result())

        self.cur._handle_result(cases[1])
        self.assertEqual(cases[1]['columns'], self.cur.description)
        self.assertTrue(self.cur._connection.unread_result)
        self.assertTrue(self.cur._have_unread_result())
开发者ID:richfab,项目名称:LOG210-server,代码行数:30,代码来源:cursor.py


示例8: setUp

 def setUp(self):
     self.table_name = 'Bug21449996'
     cnx = mysql.connector.connect(**tests.get_mysql_config())
     cnx.cmd_query("DROP TABLE IF EXISTS %s" % self.table_name)
     cnx.cmd_query("CREATE TABLE {0} (c1 BLOB) DEFAULT CHARSET=latin1"
                   "".format(self.table_name))
     cnx.close()
开发者ID:mysql,项目名称:mysql-connector-python,代码行数:7,代码来源:test_bug21449996.py


示例9: test_fetchall

    def test_fetchall(self):
        """MySQLCursor object fetchall()-method"""
        self.check_method(self.cur, 'fetchall')

        self.assertRaises(errors.InterfaceError, self.cur.fetchall)

        self.connection = connection.MySQLConnection(**tests.get_mysql_config())
        tbl = 'myconnpy_fetch'
        self._test_execute_setup(self.connection, tbl)
        stmt_insert = (
            "INSERT INTO {table} (col1,col2) "
            "VALUES (%s,%s)".format(table=tbl))
        stmt_select = (
            "SELECT col1,col2 FROM {table} "
            "ORDER BY col1 ASC".format(table=tbl))

        self.cur = self.connection.cursor()
        self.cur.execute("SELECT * FROM {table}".format(table=tbl))
        self.assertEqual([], self.cur.fetchall(),
                         "fetchall() with empty result should return []")
        nrrows = 10
        data = [(i, str(i * 100)) for i in range(0, nrrows)]
        self.cur.executemany(stmt_insert, data)
        self.cur.execute(stmt_select)
        self.assertTrue(tests.cmp_result(data, self.cur.fetchall()),
                        "Fetching all rows failed.")
        self.assertEqual(None, self.cur.fetchone())
        self._test_execute_cleanup(self.connection, tbl)
        self.cur.close()
开发者ID:richfab,项目名称:LOG210-server,代码行数:29,代码来源:cursor.py


示例10: test___init__

    def test___init__(self):
        dbconfig = tests.get_mysql_config()
        self.assertRaises(errors.PoolError, pooling.MySQLConnectionPool)

        self.assertRaises(AttributeError, pooling.MySQLConnectionPool,
                          pool_name='test',
                          pool_size=-1)
        self.assertRaises(AttributeError, pooling.MySQLConnectionPool,
                          pool_name='test',
                          pool_size=0)
        self.assertRaises(AttributeError, pooling.MySQLConnectionPool,
                          pool_name='test',
                          pool_size=(pooling.CNX_POOL_MAXSIZE + 1))

        cnxpool = pooling.MySQLConnectionPool(pool_name='test')
        self.assertEqual(5, cnxpool._pool_size)
        self.assertEqual('test', cnxpool._pool_name)
        self.assertEqual({}, cnxpool._cnx_config)
        self.assertTrue(isinstance(cnxpool._cnx_queue, Queue))
        self.assertTrue(isinstance(cnxpool._config_version, uuid.UUID))

        cnxpool = pooling.MySQLConnectionPool(pool_size=10, pool_name='test')
        self.assertEqual(10, cnxpool._pool_size)

        cnxpool = pooling.MySQLConnectionPool(pool_size=10, **dbconfig)
        self.assertEqual(dbconfig, cnxpool._cnx_config,
                         "Connection configuration not saved correctly")
        self.assertEqual(10, cnxpool._cnx_queue.qsize())
        self.assertTrue(isinstance(cnxpool._config_version, uuid.UUID))
开发者ID:hitigon,项目名称:mysql-connector-python,代码行数:29,代码来源:test_pooling.py


示例11: test__process_params

    def test__process_params(self):
        """MySQLCursor object _process_params()-method"""
        self.check_method(self.cur, '_process_params')

        self.assertRaises(
            errors.ProgrammingError, self.cur._process_params, 'foo')
        self.assertRaises(errors.ProgrammingError, self.cur._process_params, ())

        st_now = time.localtime()
        data = (
            None,
            int(128),
            int(1281288),
            float(3.14),
            Decimal('3.14'),
            r'back\slash',
            'newline\n',
            'return\r',
            "'single'",
            '"double"',
            'windows\032',
            "Strings are sexy",
            '\u82b1',
            datetime.datetime(2008, 5, 7, 20, 0o1, 23),
            datetime.date(2008, 5, 7),
            datetime.time(20, 0o3, 23),
            st_now,
            datetime.timedelta(hours=40, minutes=30, seconds=12),
        )
        exp = (
            b'NULL',
            b'128',
            b'1281288',
            b'3.14',
            b"'3.14'",
            b"'back\\\\slash'",
            b"'newline\\n'",
            b"'return\\r'",
            b"'\\'single\\''",
            b'\'\\"double\\"\'',
            b"'windows\\\x1a'",
            b"'Strings are sexy'",
            b"'\xe8\x8a\xb1'",
            b"'2008-05-07 20:01:23'",
            b"'2008-05-07'",
            b"'20:03:23'",
            b"'" + time.strftime('%Y-%m-%d %H:%M:%S', st_now).encode('ascii')
            + b"'",
            b"'40:30:12'",
        )

        self.cnx = connection.MySQLConnection(**tests.get_mysql_config())
        self.cur = self.cnx.cursor()
        self.assertEqual((), self.cur._process_params(()),
                         "_process_params() should return a tuple")
        res = self.cur._process_params(data)
        for (i, exped) in enumerate(exp):
            self.assertEqual(exped, res[i])
        self.cur.close()
开发者ID:hitigon,项目名称:mysql-connector-python,代码行数:59,代码来源:cursor.py


示例12: test_use_unicode

    def test_use_unicode(self):
        """lp:499410 Disabling unicode does not work"""
        config = tests.get_mysql_config()
        config['use_unicode'] = False
        cnx = connection.MySQLConnection(**config)

        self.assertEqual(False, cnx._use_unicode)
        cnx.close()
开发者ID:hitigon,项目名称:mysql-connector-python,代码行数:8,代码来源:bugs.py


示例13: setUp

 def setUp(self):
     config = tests.get_mysql_config()
     self.cnx = connection.MySQLConnection(**config)
     self.cur = self.cnx.cursor()
     self.table = "⽃⽄⽅⽆⽇⽈⽉⽊"
     self.cur.execute("DROP TABLE IF EXISTS {0}".format(self.table))
     self.cur.execute("CREATE TABLE {0} (c1 VARCHAR(100)) "
                      "CHARACTER SET 'utf8'".format(self.table))
开发者ID:rcsousa,项目名称:heroku-buildpack-python,代码行数:8,代码来源:bugs.py


示例14: setUp

 def setUp(self):
     dbconfig = tests.get_mysql_config()
     self.conn = mysql.connector.connect(**dbconfig)
     self.cnx = DatabaseWrapper(settings.DATABASES['default'])
     self.cur = self.cnx.cursor()
     self.tbl = "BugOra20106629"
     self.cur.execute("DROP TABLE IF EXISTS {0}".format(self.tbl), ())
     self.cur.execute("CREATE TABLE {0}(col1 TEXT, col2 BLOB)".format(self.tbl), ())
开发者ID:loicbaron,项目名称:nutrition,代码行数:8,代码来源:test_django.py


示例15: test_ssl_cipher_in_option_file

    def test_ssl_cipher_in_option_file(self):
        config = tests.get_mysql_config()
        config['ssl_ca'] = TEST_SSL['ca']
        config['use_pure'] = False

        cnx = mysql.connector.connect(**config)
        cnx.cmd_query("SHOW STATUS LIKE 'Ssl_cipher'")
        self.assertNotEqual(cnx.get_row()[1], '')  # Ssl_cipher must have a value
开发者ID:loicbaron,项目名称:nutrition,代码行数:8,代码来源:test_bug21879914.py


示例16: test__process_params_dict

    def test__process_params_dict(self):
        """MySQLCursor object _process_params_dict()-method"""
        self.check_method(self.cur, '_process_params')

        self.assertRaises(
            errors.ProgrammingError, self.cur._process_params, 'foo')
        self.assertRaises(errors.ProgrammingError, self.cur._process_params, ())

        st_now = time.localtime()
        data = {
            'a': None,
            'b': int(128),
            'c': int(1281288),
            'd': float(3.14),
            'e': Decimal('3.14'),
            'f': 'back\slash',  # pylint: disable=W1401
            'g': 'newline\n',
            'h': 'return\r',
            'i': "'single'",
            'j': '"double"',
            'k': 'windows\032',
            'l': str("Strings are sexy"),
            'm': '\u82b1',
            'n': datetime.datetime(2008, 5, 7, 20, 0o1, 23),
            'o': datetime.date(2008, 5, 7),
            'p': datetime.time(20, 0o3, 23),
            'q': st_now,
            'r': datetime.timedelta(hours=40, minutes=30, seconds=12),
        }
        exp = {
            b'%(a)s': b'NULL',
            b'%(b)s': b'128',
            b'%(c)s': b'1281288',
            b'%(d)s': b'3.14',
            b'%(e)s': b"'3.14'",
            b'%(f)s': b"'back\\\\slash'",
            b'%(g)s': b"'newline\\n'",
            b'%(h)s': b"'return\\r'",
            b'%(i)s': b"'\\'single\\''",
            b'%(j)s': b'\'\\"double\\"\'',
            b'%(k)s': b"'windows\\\x1a'",
            b'%(l)s': b"'Strings are sexy'",
            b'%(m)s': b"'\xe8\x8a\xb1'",
            b'%(n)s': b"'2008-05-07 20:01:23'",
            b'%(o)s': b"'2008-05-07'",
            b'%(p)s': b"'20:03:23'",
            b'%(q)s': b"'" +
            time.strftime('%Y-%m-%d %H:%M:%S', st_now).encode('ascii')
            + b"'",
            b'%(r)s': b"'40:30:12'",
        }

        self.cnx = connection.MySQLConnection(**tests.get_mysql_config())
        self.cur = self.cnx.cursor()
        self.assertEqual({}, self.cur._process_params_dict({}),
                         "_process_params_dict() should return a dict")
        self.assertEqual(exp, self.cur._process_params_dict(data))
        self.cur.close()
开发者ID:hitigon,项目名称:mysql-connector-python,代码行数:58,代码来源:cursor.py


示例17: test_column_names

 def test_column_names(self):
     self.cnx = connection.MySQLConnection(**tests.get_mysql_config())
     self.cur = self.cnx.cursor()
     stmt = "SELECT NOW() as now, 'The time' as label, 123 FROM dual"
     exp = (u'now', u'label', u'123')
     self.cur.execute(stmt)
     self.cur.fetchone()
     self.assertEqual(exp, self.cur.column_names)
     self.cur.close()
开发者ID:richfab,项目名称:LOG210-server,代码行数:9,代码来源:cursor.py


示例18: test__set_connection

    def test__set_connection(self):
        """MySQLCursor object _set_connection()-method"""
        self.check_method(self.cur, '_set_connection')

        self.assertRaises(errors.InterfaceError,
                          self.cur._set_connection, 'foo')
        self.connection = connection.MySQLConnection(**tests.get_mysql_config())
        self.cur._set_connection(self.connection)
        self.cur.close()
开发者ID:richfab,项目名称:LOG210-server,代码行数:9,代码来源:cursor.py


示例19: test_open_connection__ipv4

    def test_open_connection__ipv4(self):
        """Open a connection using TCP"""
        try:
            self.cnx.open_connection()
        except errors.Error as err:
            self.fail(str(err))

        config = tests.get_mysql_config()
        self._host = config['host']
        self._port = config['port']

        cases = [
            # Address, Expected Family, Should Raise, Force IPv6
            (tests.get_mysql_config()['host'], socket.AF_INET, False, False),
            ]

        for case in cases:
            self._test_open_connection(*case)
开发者ID:gdub,项目名称:mysql-connector-python,代码行数:18,代码来源:test_network.py


示例20: test_executemany

    def test_executemany(self):
        """MySQLCursor object executemany()-method"""
        self.check_method(self.cur, 'executemany')

        self.assertEqual(None, self.cur.executemany(None, []))

        config = tests.get_mysql_config()
        config['get_warnings'] = True
        self.cnx = connection.MySQLConnection(**config)
        self.cur = self.cnx.cursor()
        self.assertRaises(errors.ProgrammingError, self.cur.executemany,
                          'foo', None)
        self.assertRaises(errors.ProgrammingError, self.cur.executemany,
                          'foo', 'foo')
        self.assertEqual(None, self.cur.executemany('foo', []))
        self.assertRaises(errors.ProgrammingError, self.cur.executemany,
                          'foo', ['foo'])
        self.assertRaises(errors.ProgrammingError, self.cur.executemany,
                          'SELECT %s', [('foo',), 'foo'])
        self.assertRaises(errors.InterfaceError,
                          self.cur.executemany,
                          "INSERT INTO t1 1 %s", [(1,), (2,)])

        self.cur.executemany("SELECT SHA1(%s)", [('foo',), ('bar',)])
        self.assertEqual(None, self.cur.fetchone())
        self.cur.close()

        tbl = 'myconnpy_cursor'
        self._test_execute_setup(self.cnx, tbl)
        stmt_insert = "INSERT INTO {0} (col1,col2) VALUES (%s,%s)".format(tbl)
        stmt_select = "SELECT col1,col2 FROM {0} ORDER BY col1".format(tbl)

        self.cur = self.cnx.cursor()

        res = self.cur.executemany(stmt_insert, [(1, 100), (2, 200), (3, 300)])
        self.assertEqual(3, self.cur.rowcount)

        res = self.cur.executemany("SELECT %s", [('f',), ('o',), ('o',)])
        self.assertEqual(3, self.cur.rowcount)

        data = [{'id': 2}, {'id': 3}]
        stmt = "SELECT * FROM {0} WHERE col1 <= %(id)s".format(tbl)
        self.cur.executemany(stmt, data)
        self.assertEqual(5, self.cur.rowcount)

        self.cur.execute(stmt_select)
        self.assertEqual([(1, '100'), (2, '200'), (3, '300')],
                         self.cur.fetchall(), "Multi insert test failed")

        data = [{'id': 2}, {'id': 3}]
        stmt = "DELETE FROM {0} WHERE col1 = %(id)s".format(tbl)
        self.cur.executemany(stmt, data)
        self.assertEqual(2, self.cur.rowcount)

        self._test_execute_cleanup(self.cnx, tbl)
        self.cur.close()
开发者ID:hitigon,项目名称:mysql-connector-python,代码行数:56,代码来源:cursor.py



注:本文中的tests.get_mysql_config函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tests.get_testdata函数代码示例发布时间:2022-05-27
下一篇:
Python tests.get_data_path函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap