class TestConfigManager(unittest.TestCase): def setUp(self): self.src = TestSource('test', x=5) self.mgr = ConfigManager('prod', self.src) def test_get_version(self): vobj = self.mgr['2.0'] assert isinstance(vobj, ConfigVersion) assert vobj.version == 4 vobj2 = self.mgr.get_version(pydt.datetime(2012, 2, 1)) assert vobj.tag == '2.0' assert vobj is vobj2 vobj = self.mgr.get_version(2) assert vobj.tag is None assert vobj.version == 2 def test_get_config(self): name = 'us_largecap' date = pydt.datetime(2012, 1, 31) vdate = pydt.datetime(2012, 1, 29) item = self.mgr.get_config(name, 'quantmodel', date) # 2012-1-31 assert isinstance(item, ConfigItem) assert item.universe == 'SPX' assert item.key == 4 item_v0 = self.mgr.get_config(name, 'quantmodel', date, '1.0') assert isinstance(item_v0, ConfigItem) assert item_v0.key == 0 item_v8 = self.mgr.get_config(name, 'quantmodel', date, 8) assert isinstance(item_v8, ConfigItem) assert item_v8.key == 8 item_v4 = self.mgr.get_config(name, 'quantmodel', date, vdate) assert isinstance(item_v4, ConfigItem) assert item_v4.key == 4
def _init_database(): """ 初始化 SQLAlchemy for MySQL """ config = ConfigManager.get_config() # 初始化数据库连接 engine_1 = engine_from_config(config.DB_1_CONFIG, prefix='') # 创建DBSession类型 session_1_factory = sessionmaker(bind=engine_1, autoflush=False) # 托管到 scoped_session session_read_class = scoped_session(session_1_factory) return session_read_class
def get_conn_basicos(): conf = ConfigManager.get_config('db', "BASICOS") conn = pymysql.connect(host=conf['host'], user=conf['user'], passwd=conf['password'], db=conf['database'], charset='utf8') return conn
def get_conn_basicos(): conf = ConfigManager.get_config('db', "BASICOS") conn = pymysql.connect(host=conf['host'], user=conf['user'], passwd=conf['password'], db=conf['database'], charset='utf8') return conn def query(s, array=None): try: dbConn = get_conn_basicos() cursor = dbConn.cursor() cursor.execute(s, array) res = [] for x in cursor.fetchall(): res.append([xx for xx in x]) dbConn.commit() cursor.close() return res except Exception as e: return [[e]] medicine_conn = DbConn(ConfigManager.get_config("db", "MEDICINE")) comparator_conn = DbConn(ConfigManager.get_config("db", "COMPARATOR")) # basicos_conn = DbConn(ConfigManager.get_config('db', "BASICOS")) if __name__ == '__main__': print(query('select 7;'))