當前位置: 首頁>>代碼示例>>Python>>正文


Python MSGDBConnector.closeDB方法代碼示例

本文整理匯總了Python中msg_db_connector.MSGDBConnector.closeDB方法的典型用法代碼示例。如果您正苦於以下問題:Python MSGDBConnector.closeDB方法的具體用法?Python MSGDBConnector.closeDB怎麽用?Python MSGDBConnector.closeDB使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在msg_db_connector.MSGDBConnector的用法示例。


在下文中一共展示了MSGDBConnector.closeDB方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestMSGDBConnect

# 需要導入模塊: from msg_db_connector import MSGDBConnector [as 別名]
# 或者: from msg_db_connector.MSGDBConnector import closeDB [as 別名]
class TestMSGDBConnect(unittest.TestCase):
    """
    These tests require a database connection to be available.
    """

    def setUp(self):
        self.connector = MSGDBConnector(True)
        self.conn = self.connector.connectDB()
        self.configer = MSGConfiger()

    def test_init(self):
        self.assertTrue(
            isinstance(self.connector, msg_db_connector.MSGDBConnector),
            "self.connection is an instance of MECODBConnector.")

    def test_db_connection(self):
        """
        DB can be connected to.
        """
        self.assertIsNotNone(self.conn, 'DB connection not available.')

        # Get the name of the database.
        self.assertEqual(
            self.configer.configOptionValue('Database', 'testing_db_name'),
            self.connector.dbName, 'Testing DB name is not correct.')

    def tearDown(self):
        self.connector.closeDB(self.conn)
開發者ID:Hawaii-Smart-Energy-Project,項目名稱:Maui-Smart-Grid,代碼行數:30,代碼來源:test____msg_db_connect.py

示例2: TestMECODupeChecker

# 需要導入模塊: from msg_db_connector import MSGDBConnector [as 別名]
# 或者: from msg_db_connector.MSGDBConnector import closeDB [as 別名]
class TestMECODupeChecker(unittest.TestCase):
    """
    Unit tests for duplicate checking.
    """

    def setUp(self):
        self.dupeChecker = MECODupeChecker()
        self.p = MECOXMLParser(True) # run in testing mode
        self.dbConnect = MSGDBConnector(True)
        self.dbUtil = MSGDBUtil()
        self.conn = self.dbConnect.connectDB()
        self.cur = self.conn.cursor()

    def testInit(self):
        self.assertEqual(self.dupeChecker.__class__.__name__, "MECODupeChecker",
                         "Dupe checker has been created.")

    def testFindIndividualDupe(self):
        """
        Find a duplicate record when only one exists.
        """
        self.dbUtil.eraseTestMeco()

        self.p.filename = "../../test-data/meco_v3-energy-test-data.xml"
        fileObject = open(self.p.filename, "rb")
        self.p.parseXML(fileObject, True)

        self.assertTrue(
            self.dupeChecker.readingBranchDupeExists(self.conn, '100000',
                                                     '2013-04-08 00:30:00',
                                                     '1', True),
            "Record should already exist")

    def testLoadOnTop(self):
        """
        If the same data set is loaded in succession,
        all values will be duplicated. Verify that this is true.

        This is no longer possible as
        duplicates are dropped before insertion.
        """

        pass

    def testLoadSingleMissingEntry(self):
        """
        A reading will be inserted into the database where the reading does
        not currently exist as determined by the
        MeterName-IntervalEndTime-Channel tuple.
        """

        pass

    def tearDown(self):
        self.dbConnect.closeDB(self.conn)
開發者ID:Hawaii-Smart-Energy-Project,項目名稱:Maui-Smart-Grid,代碼行數:57,代碼來源:test____meco_dupe_check.py

示例3: TestMECOXMLParser

# 需要導入模塊: from msg_db_connector import MSGDBConnector [as 別名]
# 或者: from msg_db_connector.MSGDBConnector import closeDB [as 別名]
class TestMECOXMLParser(unittest.TestCase):
    """
    Unit tests for MECO XML Parser.
    """

    def setUp(self):
        self.p = MECOXMLParser(True) # run in testing mode
        self.dbConnect = MSGDBConnector(True)
        self.dbUtil = MSGDBUtil()
        self.conn = self.dbConnect.connectDB()
        self.cur = self.conn.cursor()

    def testMECOXMLParserCanBeInited(self):
        self.assertIsNotNone(self.p)

    def testEveryElementIsVisited(self):
        self.dbUtil.eraseTestMeco()

        self.p.filename = "../../test-data/meco_v3-energy-test-data.xml"
        fileObject = open(self.p.filename, "rb")
        expectedCount = 125
        self.p.parseXML(fileObject, True)
        print "element count = %s" % self.p.processForInsertElementCount
        self.assertEqual(self.p.processForInsertElementCount, expectedCount)

    def testAllTableNamesArePresent(self):
        self.dbUtil.eraseTestMeco()

        self.p.filename = "../../test-data/meco_v3-energy-test-data.xml"
        fileObject = open(self.p.filename, "rb")
        self.p.parseXML(fileObject, True)
        fail = False

        for key in self.p.tableNameCount.keys():
            print key + ": ",
            print self.p.tableNameCount[key]

            if self.p.tableNameCount[key] < 1:
                if key != 'ChannelStatus' and key != 'IntervalStatus' and key \
                        != 'EventData' and key != 'Event':
                    print "table = %s" % key
                    fail = True
        self.assertFalse(fail,
                         "At least one table of each type should have been "
                         "encountered.")

    def tearDown(self):
        self.dbConnect.closeDB(self.conn)
開發者ID:Hawaii-Smart-Energy-Project,項目名稱:Maui-Smart-Grid,代碼行數:50,代碼來源:test____meco_xml_parser.py

示例4: TestMECODBRead

# 需要導入模塊: from msg_db_connector import MSGDBConnector [as 別名]
# 或者: from msg_db_connector.MSGDBConnector import closeDB [as 別名]
class TestMECODBRead(unittest.TestCase):
    def setUp(self):
        self.reader = MECODBReader()
        self.connector = MSGDBConnector(True)
        self.conn = self.connector.connectDB()
        self.inserter = MECODBInserter()
        self.util = MSGDBUtil()
        self.lastSeqVal = None
        self.tableName = 'MeterData'
        self.colName = 'meter_data_id'
        self.deleter = MECODBDeleter()

    def testMECODBReadCanBeInited(self):
        self.assertIsNotNone(self.reader)

    def testSelectRecord(self):
        """
        Insert and retrieve a record to test the ability to select a record.
        """

        print "testSelectRecord:"
        print "self.conn = %s" % self.conn

        sampleDict = {'MeterName': '100001', 'UtilDeviceID': '100001',
                      'MacID': '00:00:00:00:00:00:00:00'}
        self.inserter.insertData(self.conn, self.tableName, sampleDict)
        self.lastSeqVal = self.util.getLastSequenceID(self.conn, self.tableName,
                                                      self.colName)

        print "lastSeqVal = %s" % self.lastSeqVal

        row = self.reader.selectRecord(self.conn, self.tableName, self.colName,
                                       self.lastSeqVal)
        self.assertEqual(row[self.colName], self.lastSeqVal)

    def tearDown(self):
        # Delete the record that was inserted.
        if self.lastSeqVal != None:
            self.deleter.deleteRecord(self.conn, self.tableName, self.colName,
                                      self.lastSeqVal)

        self.connector.closeDB(self.conn)
開發者ID:Hawaii-Smart-Energy-Project,項目名稱:Maui-Smart-Grid,代碼行數:44,代碼來源:test____meco_db_read.py

示例5: MSGDBUtilTester

# 需要導入模塊: from msg_db_connector import MSGDBConnector [as 別名]
# 或者: from msg_db_connector.MSGDBConnector import closeDB [as 別名]
class MSGDBUtilTester(unittest.TestCase):
    """
    Unit tests for MECO DB Utils.
    """

    def setUp(self):
        self.i = MECODBInserter()

        # Connect to the testing database.
        self.connector = MSGDBConnector(testing = True)

        self.conn = self.connector.connectDB()
        self.lastSeqVal = None

        # Does this work having the dictCur be in another class?
        self.dictCur = self.connector.dictCur

        self.cursor = self.conn.cursor()
        self.deleter = MECODBDeleter()
        self.tableName = 'MeterData'
        self.columnName = 'meter_data_id'
        self.configer = MSGConfiger()
        self.logger = MSGLogger(__name__, 'debug')
        self.dbUtil = MSGDBUtil()

    def testMECODBUtilCanBeInited(self):
        self.assertIsNotNone(self.dbUtil)

    def testLastSequenceNumberIsCorrect(self):
        """
        Test if last sequence ID value is generated correctly. Do this by
        inserting and deleting a DB record.
        """

        # Insert some values.
        sampleDict = {'MeterName': '100001', 'UtilDeviceID': '100001',
                      'MacID': '00:00:00:00:00:00:00:00'}
        self.i.insertData(self.conn, self.tableName, sampleDict)

        self.lastSeqVal = self.dbUtil.getLastSequenceID(self.conn,
                                                        self.tableName,
                                                        self.columnName)
        print "lastSeqVal = %s" % self.lastSeqVal

        sql = """SELECT * FROM "%s" WHERE %s = %s""" % (
        self.tableName, self.columnName, self.lastSeqVal)
        dictCur = self.connector.dictCur
        self.dbUtil.executeSQL(dictCur, sql)
        row = dictCur.fetchone()
        meterDataID = row[self.columnName]
        self.assertEqual(self.lastSeqVal, meterDataID)

    def testGetDBName(self):
        dbName = self.dbUtil.getDBName(self.cursor)[0]
        self.logger.log("DB name is %s" % dbName, 'info')
        self.assertEqual(dbName, "test_meco",
                         "Testing DB name should be set correctly.")


    def testEraseTestingDatabase(self):
        """
        Test that calls to eraseTestMeco() work correctly.
        """

        dbName = self.dbUtil.getDBName(self.cursor)[0]
        self.logger.log("DB name is %s" % dbName, 'info')
        self.assertEqual(dbName, "test_meco",
                         "Testing DB name should be set correctly.")
        self.dbUtil.eraseTestMeco()

        # Check all of the tables for the presence of records.
        for table in self.configer.insertTables:
            sql = """select count(*) from "%s";""" % table
            self.dbUtil.executeSQL(self.dictCur, sql)
            row = self.dictCur.fetchone()
            self.assertEqual(row[0], 0,
                             "No records should be present in the %s table."
                             % table)

    def testColumns(self):
        """
        Test the ability to retrieve the column names from a database.
        """

        print self.dbUtil.columns(self.cursor, 'Event')


    def tearDown(self):
        """
        Delete the record that was inserted.
        """
        if self.lastSeqVal != None:
            self.deleter.deleteRecord(self.conn, self.tableName,
                                      self.columnName, self.lastSeqVal)

        self.connector.closeDB(self.conn)
開發者ID:daveyshindig,項目名稱:Maui-Smart-Grid,代碼行數:98,代碼來源:test____msg_db_util.py

示例6: TestMECODBInserter

# 需要導入模塊: from msg_db_connector import MSGDBConnector [as 別名]
# 或者: from msg_db_connector.MSGDBConnector import closeDB [as 別名]
class TestMECODBInserter(unittest.TestCase):
    """
    Unit tests for the MECO XML Parser.
    """

    def setUp(self):
        self.i = MECODBInserter()
        self.util = MSGDBUtil()
        self.connector = MSGDBConnector(True)
        self.deleter = MECODBDeleter()
        self.reader = MECODBReader()
        self.lastSeqVal = None
        self.conn = self.connector.connectDB()
        self.sampleTableName = 'MeterData'
        self.sampleDict = {'MeterName': '100001', 'UtilDeviceID': '100001',
                           'MacID': '00:00:00:00:00:00:00:00'}
        self.keyName = 'meter_data_id'

    def testMECODBInserterCanBeInited(self):
        localInserter = MECODBInserter()
        self.assertIsInstance(self.i, type(localInserter))


    def testInsertionToMeterDataTable(self):
        """
        Data can be written to the Meter Data table.
        """

        # Insert some values.
        self.i.insertData(self.conn, self.sampleTableName, self.sampleDict)

        # Retrieve the last fetched value.
        self.lastSeqVal = self.util.getLastSequenceID(self.conn,
                                                      self.sampleTableName,
                                                      self.keyName)

        print "lastSeqVal = %s" % self.lastSeqVal

        row = self.reader.selectRecord(self.conn, self.sampleTableName,
                                       self.keyName, self.lastSeqVal)
        self.assertEqual(row[self.keyName], self.lastSeqVal)


    def test_fkey_value_is_correct(self):
        """
        Verify that the fkey value used during insertion is correct.
        """


    def testInsertionsSums(self):
        """
        """

        pass

    def tearDown(self):
        # Delete the record that was inserted.
        if self.lastSeqVal != None:
            self.deleter.deleteRecord(self.conn, self.sampleTableName,
                                      self.keyName, self.lastSeqVal)

        self.connector.closeDB(self.conn)
開發者ID:Hawaii-Smart-Energy-Project,項目名稱:Maui-Smart-Grid,代碼行數:64,代碼來源:test____meco_db_inserter.py


注:本文中的msg_db_connector.MSGDBConnector.closeDB方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。