def test_mysql(self): driver = testing.get_driver() user, password, host, port, database, _ = parseMySQLDSN( testing.get_mysql_dsn()) conn = connect(driver, database, user=user, password=password, host=host, port=port) self._do_test(driver, conn) conn.close() conn = testing.get_singleton_db_connection() self._do_test(driver, conn)
def test_generator(self): driver = testing.get_driver() user, password, host, port, database, _ = parseMySQLDSN( testing.get_mysql_dsn()) conn = connect(driver, database, user=user, password=password, host=host, port=int(port)) # prepare test data execute(driver, conn, self.drop_statement) execute(driver, conn, self.create_statement) execute(driver, conn, self.insert_statement) column_name_to_type = { "features": { "feature_name": "features", "delimiter": "", "dtype": "float32", "is_sparse": False, "shape": [] } } label_meta = {"feature_name": "label", "shape": [], "delimiter": ""} gen = db_generator(conn, "SELECT * FROM test_table_float_fea", label_meta) idx = 0 for row, label in gen(): features = read_features_from_row(row, ["features"], ["features"], column_name_to_type) d = (features, label) if idx == 0: self.assertEqual(d, (((1.0, ), ), 0)) elif idx == 1: self.assertEqual(d, (((2.0, ), ), 1)) idx += 1 self.assertEqual(idx, 2)
def test_parse_mysql_dsn(self): # [username[:password]@][protocol[(address)]]/dbname[?param1=value1&...¶mN=valueN] self.assertEqual(("usr", "pswd", "localhost", "8000", "mydb", { "param1": "value1" }), parseMySQLDSN("usr:pswd@tcp(localhost:8000)/mydb?param1=value1"))
def __init__(self, *args, **kwargs): super(TestSQLData, self).__init__(*args, **kwargs) dsn = testing.get_mysql_dsn() user, passwd, host, port, _, _ = parseMySQLDSN(dsn) self.db = sql_data.connect(user, passwd, host, int(port)) self.assertIsNotNone(self.db)