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


Python WMInit.clearDatabase方法代码示例

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


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

示例1: testB_Database

# 需要导入模块: from WMCore.WMInit import WMInit [as 别名]
# 或者: from WMCore.WMInit.WMInit import clearDatabase [as 别名]
    def testB_Database(self):
        """
        _Database_

        Testing the database stuff.
        """

        init = WMInit()
        url     = os.environ.get("DATABASE")
        dialect = os.environ.get("DIALECT")
        sock    = os.environ.get("DBSOCK", None)

        init.setDatabaseConnection(url, dialect, sock)

        try:
            # Initial clear should work
            myThread = threading.currentThread()
            init.clearDatabase()

            # Clear one after another should work
            init.setSchema(modules = ['WMCore.WMBS'])
            init.clearDatabase()
            init.setSchema(modules = ['WMCore.WMBS'])
            init.clearDatabase()

            # Clear non-existant DB should work
            # Drop the database, and then make sure the database gets recreated
            a = myThread.dbi.engine.url.database
            dbName = myThread.dbi.processData("SELECT DATABASE() AS dbname")[0].fetchall()[0][0]
            myThread.dbi.processData("DROP DATABASE %s" % dbName)
            dbName = myThread.dbi.processData("SELECT DATABASE() AS dbname")[0].fetchall()[0][0]
            self.assertEqual(dbName, None)
            init.clearDatabase()
            dbName = myThread.dbi.processData("SELECT DATABASE() AS dbname")[0].fetchall()[0][0]
            self.assertEqual(dbName, a)


            init.setSchema(modules = ['WMCore.WMBS'])
            myThread.transaction.begin()
            myThread.transaction.processData("SELECT * FROM wmbs_job")
            init.clearDatabase()
            dbName = myThread.dbi.processData("SELECT DATABASE() AS dbname")[0].fetchall()[0][0]
            self.assertEqual(dbName, a)
            myThread.transaction.begin()
            init.setSchema(modules = ['WMCore.WMBS'])
            myThread.transaction.commit()
        except:
            init.clearDatabase()
            raise

        init.clearDatabase()        

        return        
开发者ID:stuartw,项目名称:WMCore,代码行数:55,代码来源:WMInit_t.py

示例2: TestInit

# 需要导入模块: from WMCore.WMInit import WMInit [as 别名]
# 或者: from WMCore.WMInit.WMInit import clearDatabase [as 别名]
class TestInit(object):
    """
    A set of initialization steps used in many tests.
    Test can call the methods from this class to
    initialize their default environment so to
    minimize code duplication.
    """

    def __init__(self, testClassName = "Unknown Class"):
        self.testClassName = testClassName
        self.testDir = None
        self.currModules = []
        global hasDatabase
        self.hasDatabase = hasDatabase
        if self.hasDatabase:
            self.init = WMInit()
        self.deleteTmp = True

    def __del__(self):
        if self.deleteTmp:
            self.delWorkDir()
        self.attemptToCloseDBConnections()


    def delWorkDir(self):
        if self.testDir != None:
            try:
                shutil.rmtree( self.testDir )
            except:
                # meh, if it fails, I guess something weird happened
                pass

    def setLogging(self, logLevel = logging.INFO):
        """
        Sets logging parameters
        """
        # remove old logging instances.
        return
        logger1 = logging.getLogger()
        logger2 = logging.getLogger(self.testClassName)
        for logger in [logger1, logger2]:
            for handler in logger.handlers:
                handler.close()
                logger.removeHandler(handler)

        self.init.setLogging(self.testClassName, self.testClassName,
                             logExists = False, logLevel = logLevel)

    def generateWorkDir(self, config = None, deleteOnDestruction = True, setTmpDir = False):
        self.testDir = tempfile.mkdtemp()
        if config:
            config.section_("General")
            config.General.workDir = self.testDir
        os.environ['TESTDIR'] = self.testDir
        if os.getenv('WMCORE_KEEP_DIRECTORIES', False):
            deleteOnDestruction = True
            logging.info("Generated testDir - %s" % self.testDir)
        if setTmpDir:
            os.environ['TMPDIR'] = self.testDir

        self.deleteTmp = deleteOnDestruction
        return self.testDir

    def getBackendFromDbURL(self, dburl):
        dialectPart = dburl.split(":")[0]
        if dialectPart == 'mysql':
            return 'MySQL'
        elif dialectPart == 'oracle':
            return 'Oracle'
        elif dialectPart == 'http':
            return 'CouchDB'
        else:
            raise RuntimeError("Unrecognized dialect %s" % dialectPart)

    def setDatabaseConnection(self, connectUrl=None, socket=None, destroyAllDatabase = False):
        """
        Set up the database connection by retrieving the environment
        parameters.

        The destroyAllDatabase option is for testing ONLY.  Never flip that switch
        on in any other instance where you don't know what you're doing.
        """
        if not self.hasDatabase:
            return
        config = self.getConfiguration(connectUrl=connectUrl, socket=socket)
        self.coreConfig = config
        self.init.setDatabaseConnection(config.CoreDatabase.connectUrl,
                                        config.CoreDatabase.dialect,
                                        config.CoreDatabase.socket)

        if trashDatabases or destroyAllDatabase:
            self.clearDatabase()

        # Have to check whether or not database is empty
        # If the database is not empty when we go to set the schema, abort!
        try:
            result = self.init.checkDatabaseContents()
        except OperationalError:
            logging.debug("Error checking DB contents, assume DB does not exist")
            return
#.........这里部分代码省略.........
开发者ID:alexanderrichards,项目名称:WMCore,代码行数:103,代码来源:TestInit.py


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