当前位置: 首页>>代码示例>>Python>>正文


Python pymysql.Warning方法代码示例

本文整理汇总了Python中pymysql.Warning方法的典型用法代码示例。如果您正苦于以下问题:Python pymysql.Warning方法的具体用法?Python pymysql.Warning怎么用?Python pymysql.Warning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymysql的用法示例。


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

示例1: test_load_warnings

# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import Warning [as 别名]
def test_load_warnings(self):
        """Test load local infile produces the appropriate warnings"""
        conn = self.connections[0]
        c = conn.cursor()
        c.execute("CREATE TABLE test_load_local (a INTEGER, b INTEGER)")
        filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                'data',
                                'load_local_warn_data.txt')
        try:
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter('always')
                c.execute(
                    ("LOAD DATA LOCAL INFILE '{0}' INTO TABLE " +
                     "test_load_local FIELDS TERMINATED BY ','").format(filename)
                )
                self.assertEqual(w[0].category, Warning)
                expected_message = "Incorrect integer value"
                if expected_message not in str(w[-1].message):
                    self.fail("%r not in %r" % (expected_message, w[-1].message))
        finally:
            c.execute("DROP TABLE test_load_local")
            c.close() 
开发者ID:MarcelloLins,项目名称:ServerlessCrawler-VancouverRealState,代码行数:24,代码来源:test_load_local.py

示例2: test_issue_491

# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import Warning [as 别名]
def test_issue_491(self):
        """ Test warning propagation """
        conn = pymysql.connect(charset="utf8", **self.databases[0])

        with warnings.catch_warnings():
            # Ignore all warnings other than pymysql generated ones
            warnings.simplefilter("ignore")
            warnings.simplefilter("error", category=pymysql.Warning)

            # verify for both buffered and unbuffered cursor types
            for cursor_class in (cursors.Cursor, cursors.SSCursor):
                c = conn.cursor(cursor_class)
                try:
                    c.execute("SELECT CAST('124b' AS SIGNED)")
                    c.fetchall()
                except pymysql.Warning as e:
                    # Warnings should have errorcode and string message, just like exceptions
                    self.assertEqual(len(e.args), 2)
                    self.assertEqual(e.args[0], 1292)
                    self.assertTrue(isinstance(e.args[1], text_type))
                else:
                    self.fail("Should raise Warning")
                finally:
                    c.close() 
开发者ID:MarcelloLins,项目名称:ServerlessCrawler-VancouverRealState,代码行数:26,代码来源:test_issues.py

示例3: test_load_warnings

# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import Warning [as 别名]
def test_load_warnings(self):
        """Test load local infile produces the appropriate warnings"""
        conn = self.connections[0]
        c = conn.cursor()
        c.execute("CREATE TABLE test_load_local (a INTEGER, b INTEGER)")
        filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                'data',
                                'load_local_warn_data.txt')
        try:
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter('always')
                c.execute(
                    ("LOAD DATA LOCAL INFILE '{0}' INTO TABLE " +
                     "test_load_local FIELDS TERMINATED BY ','").format(filename)
                )
                self.assertEqual(w[0].category, Warning)
                self.assertTrue("Incorrect integer value" in str(w[-1].message))
        finally:
            c.execute("DROP TABLE test_load_local") 
开发者ID:zhangzhengde0225,项目名称:VaspCZ,代码行数:21,代码来源:test_load_local.py

示例4: test_load_warnings

# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import Warning [as 别名]
def test_load_warnings(self):
        """Test load local infile produces the appropriate warnings"""
        conn = self.connect()
        c = conn.cursor()
        c.execute("CREATE TABLE test_load_local (a INTEGER, b INTEGER)")
        filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                'data',
                                'load_local_warn_data.txt')
        try:
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter('always')
                c.execute(
                    ("LOAD DATA LOCAL INFILE '{0}' INTO TABLE " +
                     "test_load_local FIELDS TERMINATED BY ','").format(filename)
                )
                self.assertEqual(w[0].category, Warning)
                expected_message = "Incorrect integer value"
                if expected_message not in str(w[-1].message):
                    self.fail("%r not in %r" % (expected_message, w[-1].message))
        finally:
            c.execute("DROP TABLE test_load_local")
            c.close() 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:24,代码来源:test_load_local.py

示例5: test_issue_363

# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import Warning [as 别名]
def test_issue_363(self):
        """ Test binary / geometry types. """
        conn = pymysql.connect(charset="utf8", **self.databases[0])
        self.safe_create_table(
            conn, "issue363",
            "CREATE TABLE issue363 ( "
            "id INTEGER PRIMARY KEY, geom LINESTRING NOT NULL, "
            "SPATIAL KEY geom (geom)) "
            "ENGINE=MyISAM default charset=utf8")

        cur = conn.cursor()
        query = ("INSERT INTO issue363 (id, geom) VALUES"
                 "(1998, GeomFromText('LINESTRING(1.1 1.1,2.2 2.2)'))")
        # From MySQL 5.7, ST_GeomFromText is added and GeomFromText is deprecated.
        if self.mysql_server_is(conn, (5, 7, 0)):
            with self.assertWarns(pymysql.err.Warning) as cm:
                cur.execute(query)
        else:
            cur.execute(query)

        # select WKT
        query = "SELECT AsText(geom) FROM issue363"
        if self.mysql_server_is(conn, (5, 7, 0)):
            with self.assertWarns(pymysql.err.Warning) as cm:
                cur.execute(query)
        else:
            cur.execute(query)
        row = cur.fetchone()
        self.assertEqual(row, ("LINESTRING(1.1 1.1,2.2 2.2)", ))

        # select WKB
        query = "SELECT AsBinary(geom) FROM issue363"
        if self.mysql_server_is(conn, (5, 7, 0)):
            with self.assertWarns(pymysql.err.Warning) as cm:
                cur.execute(query)
        else:
            cur.execute(query)
        row = cur.fetchone()
        self.assertEqual(row,
                         (b"\x01\x02\x00\x00\x00\x02\x00\x00\x00"
                          b"\x9a\x99\x99\x99\x99\x99\xf1?"
                          b"\x9a\x99\x99\x99\x99\x99\xf1?"
                          b"\x9a\x99\x99\x99\x99\x99\x01@"
                          b"\x9a\x99\x99\x99\x99\x99\x01@", ))

        # select internal binary
        cur.execute("SELECT geom FROM issue363")
        row = cur.fetchone()
        # don't assert the exact internal binary value, as it could
        # vary across implementations
        self.assertTrue(isinstance(row[0], bytes)) 
开发者ID:MarcelloLins,项目名称:ServerlessCrawler-VancouverRealState,代码行数:53,代码来源:test_issues.py

示例6: driver_path

# 需要导入模块: import pymysql [as 别名]
# 或者: from pymysql import Warning [as 别名]
def driver_path(provider, tmpdir, mysql_server):
    """Get a valid, uninitialized driver path for given provider"""
    import random
    import string

    from urllib.parse import urlparse

    def validate_con_info(con_info):
        return (con_info.scheme == 'mysql'
                and con_info.hostname
                and con_info.username
                and not con_info.path)

    def random_string(length):
        return ''.join(random.choices(string.ascii_uppercase, k=length))

    if provider == 'sqlite':
        dbfile = tmpdir.join('test.sqlite')
        yield str(dbfile)

    elif provider == 'mysql':
        if not mysql_server:
            return pytest.skip('mysql_server argument not given')

        if not mysql_server.startswith('mysql://'):
            mysql_server = f'mysql://{mysql_server}'

        con_info = urlparse(mysql_server)
        if not validate_con_info(con_info):
            raise ValueError('invalid value for mysql_server')

        dbpath = random_string(24)

        import pymysql
        try:
            with pymysql.connect(con_info.hostname, user=con_info.username,
                                 password=con_info.password) as con:
                pass
        except pymysql.OperationalError as exc:
            raise RuntimeError('error connecting to MySQL server') from exc

        try:
            yield f'{mysql_server}/{dbpath}'

        finally:  # cleanup
            with pymysql.connect(con_info.hostname, user=con_info.username,
                                 password=con_info.password) as con:
                try:
                    con.execute(f'DROP DATABASE IF EXISTS {dbpath}')
                except pymysql.Warning:
                    pass

    else:
        return NotImplementedError(f'unknown provider {provider}') 
开发者ID:DHI-GRAS,项目名称:terracotta,代码行数:56,代码来源:conftest.py


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