def mock_circlecore_context(): with tempfile.TemporaryDirectory('cc_') as tmp_dir: assert os.path.exists(tmp_dir) assert not os.path.exists(os.path.join(tmp_dir, 'metadata.sqlite3')) metadata_db_engine = sqlalchemy.create_engine( 'sqlite:///' + os.path.join(tmp_dir, 'metadata.sqlite3'), poolclass=NullPool) MetaDataSession.configure(bind=metadata_db_engine) # empty MetaDataBase.metadata.create_all(metadata_db_engine) # make my CcInfo with MetaDataSession.begin(): my_cc_info = CcInfo(display_name='My CircleCore', myself=True, work='') my_cc_info.uuid = generate_uuid(model=CcInfo) MetaDataSession.add(my_cc_info) yield metadata_db_engine, tmp_dir MetaDataBase.metadata.drop_all(metadata_db_engine) MetaDataSession.remove()
def open_metadata_db(self): """metadataデータベースの設定をする.""" self.metadata_db_engine = sqlalchemy.create_engine( 'sqlite:///' + os.path.abspath(self.metadata_file_path)) MetaDataSession.configure(bind=self.metadata_db_engine)