1717
1818import numpy as np
1919import runtime .testing as testing
20- from odps import ODPS , tunnel
20+ from odps import tunnel
2121from runtime .db import (MYSQL_FIELD_TYPE_DICT , buffered_db_writer , connect ,
2222 connect_with_data_source , db_generator ,
2323 get_table_schema , limit_select , parseHiveDSN ,
@@ -53,7 +53,7 @@ def execute(driver, conn, statement):
5353 try :
5454 rows = cursor .fetchall ()
5555 field_columns = list (map (list , zip (* rows ))) if len (rows ) > 0 else None
56- except :
56+ except : # noqa: E722
5757 field_columns = None
5858
5959 return field_names , field_columns
@@ -62,7 +62,9 @@ def execute(driver, conn, statement):
6262class TestDB (TestCase ):
6363
6464 create_statement = "create table test_db (features text, label int)"
65- hive_create_statement = 'create table test_db (features string, label int) ROW FORMAT DELIMITED FIELDS TERMINATED BY "\001 "'
65+ hive_create_statement = 'create table test_db (features string, ' \
66+ 'label int) ROW FORMAT DELIMITED FIELDS ' \
67+ 'TERMINATED BY "\001 "'
6668 select_statement = "select * from test_db"
6769 drop_statement = "drop table if exists test_db"
6870
@@ -114,7 +116,8 @@ def _do_test_hive_specified_db(self,
114116 hdfs_namenode_addr = "" ,
115117 hive_location = "" ):
116118 create_db = '''create database if not exists test_db'''
117- create_tbl = '''create table test_db.tbl (features string, label int) ROW FORMAT DELIMITED FIELDS TERMINATED BY "\001 "'''
119+ create_tbl = '''create table test_db.tbl (features string, label int)
120+ ROW FORMAT DELIMITED FIELDS TERMINATED BY "\001 "'''
118121 drop_tbl = '''drop table if exists test_db.tbl'''
119122 select_tbl = '''select * from test_db.tbl'''
120123 table_schema = ["label" , "features" ]
@@ -173,9 +176,11 @@ def _do_test(self, driver, conn, hdfs_namenode_addr="", hive_location=""):
173176
174177
175178class TestGenerator (TestCase ):
176- create_statement = "create table test_table_float_fea (features float, label int)"
179+ create_statement = "create table test_table_float_fea " \
180+ "(features float, label int)"
177181 drop_statement = "drop table if exists test_table_float_fea"
178- insert_statement = "insert into test_table_float_fea (features,label) values(1.0, 0), (2.0, 1)"
182+ insert_statement = "insert into test_table_float_fea (features,label)" \
183+ " values(1.0, 0), (2.0, 1)"
179184
180185 @unittest .skipUnless (testing .get_driver () == "mysql" ,
181186 "skip non mysql tests" )
@@ -241,29 +246,26 @@ def test_parse_hive_dsn(self):
241246 ("usr" , "pswd" , "hiveserver" , "1000" , "mydb" , "PLAIN" , {
242247 "mapreduce_job_quenename" : "mr"
243248 }),
244- parseHiveDSN (
245- "usr:pswd@hiveserver:1000/mydb?auth=PLAIN&session.mapreduce_job_quenename=mr"
246- ))
249+ parseHiveDSN ("usr:pswd@hiveserver:1000/mydb?auth=PLAIN&"
250+ "session.mapreduce_job_quenename=mr" ))
247251 self .assertEqual (
248252 ("usr" , "pswd" , "hiveserver" , "1000" , "my_db" , "PLAIN" , {
249253 "mapreduce_job_quenename" : "mr"
250254 }),
251- parseHiveDSN (
252- "usr:pswd@hiveserver:1000/my_db?auth=PLAIN&session.mapreduce_job_quenename=mr"
253- ))
255+ parseHiveDSN ("usr:pswd@hiveserver:1000/my_db?auth=PLAIN&"
256+ "session.mapreduce_job_quenename=mr" ))
254257 self .assertEqual (
255258 ("root" , "root" , "127.0.0.1" , None , "mnist" , "PLAIN" , {}),
256259 parseHiveDSN ("root:root@127.0.0.1/mnist?auth=PLAIN" ))
257260 self .assertEqual (("root" , "root" , "127.0.0.1" , None , None , "" , {}),
258261 parseHiveDSN ("root:root@127.0.0.1" ))
259262
260263 def test_parse_maxcompute_dsn (self ):
261- self .assertEqual (
262- ("access_id" , "access_key" , "http://maxcompute-service.com/api" ,
263- "test_ci" ),
264- parseMaxComputeDSN (
265- "access_id:access_key@maxcompute-service.com/api?curr_project=test_ci&scheme=http"
266- ))
264+ self .assertEqual (("access_id" , "access_key" ,
265+ "http://maxcompute-service.com/api" , "test_ci" ),
266+ parseMaxComputeDSN (
267+ "access_id:access_key@maxcompute-service.com/api?"
268+ "curr_project=test_ci&scheme=http" ))
267269
268270 def test_kv_feature_column (self ):
269271 feature_spec = {
@@ -300,8 +302,8 @@ def test_get_table_schema(self):
300302
301303 schema = selected_columns_and_types (
302304 conn ,
303- "SELECT sepal_length, petal_width * 2.3 new_petal_width, class FROM iris.train "
304- )
305+ "SELECT sepal_length, petal_width * 2.3 new_petal_width, "
306+ "class FROM iris.train" )
305307 expect = [
306308 ("sepal_length" , "FLOAT" ),
307309 ("new_petal_width" , "DOUBLE" ),
@@ -321,8 +323,8 @@ def test_get_table_schema(self):
321323
322324 schema = selected_columns_and_types (
323325 conn ,
324- "SELECT sepal_length, petal_width * 2.3 AS new_petal_width, class FROM iris.train "
325- )
326+ "SELECT sepal_length, petal_width * 2.3 AS new_petal_width, "
327+ "class FROM iris.train" )
326328 expect = [
327329 ("sepal_length" , "FLOAT" ),
328330 ("new_petal_width" , "FLOAT" ),
@@ -344,8 +346,8 @@ def test_get_table_schema(self):
344346
345347 schema = selected_columns_and_types (
346348 conn ,
347- "SELECT sepal_length, petal_width * 2.3 new_petal_width, class FROM %s "
348- % table )
349+ "SELECT sepal_length, petal_width * 2.3 new_petal_width, "
350+ "class FROM %s" % table )
349351 expect = [
350352 ("sepal_length" , "DOUBLE" ),
351353 ("new_petal_width" , "DOUBLE" ),
@@ -367,7 +369,8 @@ def test_field_type(self):
367369
368370 table_name = "iris.test_mysql_field_type_table"
369371 drop_table_sql = "DROP TABLE IF EXISTS %s" % table_name
370- create_table_sql = "CREATE TABLE IF NOT EXISTS " + table_name + "(a %s)"
372+ create_table_sql = "CREATE TABLE IF NOT EXISTS " + \
373+ table_name + "(a %s)"
371374 select_sql = "SELECT * FROM %s" % table_name
372375
373376 for int_type , str_type in MYSQL_FIELD_TYPE_DICT .items ():
0 commit comments