Beispiel #1
0
    def testDeleteOldRows(self):
        conn = MockConnection()

        dptDB = DOMProdTestDB(conn)

        fatId = 123
        monId = 456
        monDataId = 789

        cursor = MockCursor('delete')
        conn.addCursor(cursor)

        qry = 'select fat_mon_id from FATMonitor where fat_id=' + str(fatId)
        cursor.addExpectedExecute(qry, monId)

        qry = 'select fat_mondata_id from FATMonData where fat_mon_id=' + \
            str(monId)
        cursor.addExpectedExecute(qry, monDataId)

        qry = 'delete from FATMonHisto where fat_mondata_id=' + str(monDataId)
        cursor.addExpectedExecute(qry)

        qry = 'delete from FATMonData where fat_mon_id=' + str(monId)
        cursor.addExpectedExecute(qry)

        qry = 'delete from FATMonitor where fat_id=' + str(fatId)
        cursor.addExpectedExecute(qry)

        MonitorFile.deleteOldRows(dptDB, fatId)

        conn.verify()
Beispiel #2
0
    def testDeleteOldRows(self):
        conn = MockConnection()

        dptDB = DOMProdTestDB(conn)

        fatId = 1234

        cursor = MockCursor('delete')
        conn.addCursor(cursor)

        qry = 'delete from FATLCChain where fat_id=' + str(fatId)
        cursor.addExpectedExecute(qry)

        LCChainFile.deleteOldRows(dptDB, fatId)

        conn.verify()
Beispiel #3
0
    def testGetNextId(self):
        conn = MockConnection()

        dptDB = DOMProdTestDB(conn)

        tblName = "Table"
        colName = "Column"
        expId = 123

        cursor = MockCursor("NoNextId")
        conn.addCursor(cursor)

        qry = 'select max(' + colName + ') from ' + tblName
        cursor.addExpectedExecute(qry, (expId - 1, ))

        id = getNextId(dptDB, tblName, colName)
        self.assertEqual(id, expId, "Unexpected next ID")

        conn.verify()
Beispiel #4
0
    def testGetNextIdFirst(self):
        conn = MockConnection()

        dptDB = DOMProdTestDB(conn)

        tblName = "Table"
        colName = "Column"
        expId = 1

        cursor = MockCursor("NoNextId")
        conn.addCursor(cursor)

        qry = 'select max(' + colName + ') from ' + tblName
        cursor.addExpectedExecute(qry, None)

        id = getNextId(dptDB, tblName, colName)
        self.assertEqual(id, expId, "Expected empty query to return 1")

        conn.verify()
Beispiel #5
0
 def setUp(self):
     self.conn = MockConnection()
Beispiel #6
0
class testFATRun(unittest.TestCase):
    """Unit tests for FATRun class"""
    def setUp(self):
        self.conn = MockConnection()

    def tearDown(self):
        self.conn.verify()

    def testNoRuns(self):
        dptDB = DOMProdTestDB(self.conn)

        runName = 'A FAT RUN'

        cursor = MockCursor("Empty")
        self.conn.addCursor(cursor)

        qry = 'select fat_id,name,start_date,end_date,comment' + \
            ' from FAT order by fat_id'
        cursor.addExpectedExecute(qry, None)

        run = FATRun(dptDB)

        self.failIf(run.isName(runName),
                    'Run ' + runName + ' should not exist')
        self.assertEqual(None, run.getId(runName),
                         'Should not have ID for run ' + runName)

    def testOneRun(self):
        dptDB = DOMProdTestDB(self.conn)

        runName = 'A FAT RUN'
        expId = 123
        startDate = '2005-08-04'

        cursor = MockCursor("Empty")
        self.conn.addCursor(cursor)

        qry = 'select fat_id,name,start_date,end_date,comment' + \
            ' from FAT order by fat_id'
        cursor.addExpectedExecute(qry, (expId, runName, startDate, None, None))

        run = FATRun(dptDB)

        self.failUnless(run.isName(runName),
                        'Run ' + runName + ' should exist')
        self.assertEqual(expId, run.getId(runName),
                         'Unexpected ID for run ' + runName)

    def testTwoRuns(self):
        dptDB = DOMProdTestDB(self.conn)

        nameList = ['A FAT RUN', 'ANOTHER']
        idList = [123, 345]

        startDate = '2005-08-04'

        cursor = MockCursor("Empty")
        self.conn.addCursor(cursor)

        qry = 'select fat_id,name,start_date,end_date,comment' + \
            ' from FAT order by fat_id'
        cursor.addExpectedExecute(
            qry, (idList[0], nameList[0], startDate, None, None),
            (idList[1], nameList[1], startDate, '2005-08-05', 'A comment'))

        run = FATRun(dptDB)

        for i in range(len(nameList)):
            self.failUnless(run.isName(nameList[i]),
                            'Run ' + nameList[i] + ' should exist')
            self.assertEqual(idList[i], run.getId(nameList[i]),
                             'Unexpected ID for run ' + nameList[i])
Beispiel #7
0
class testFATData(unittest.TestCase):
    """Unit tests for FATData class"""
    def addMockLabIdQuery(self, id):
        hostName = socket.gethostname()

        cursor = MockCursor("GetLabId")
        self.conn.addCursor(cursor)

        qry = 'select lab_id from Laboratory where name="' + hostName + '"'
        cursor.addExpectedExecute(qry, (id, ))

    def setUp(self):
        self.conn = MockConnection()

    def tearDown(self):
        pass  #self.conn.verify()

    def testNotExists(self):
        dptDB = DOMProdTestDB(self.conn)

        expLabId = 12345
        self.addMockLabIdQuery(expLabId)

        runName = 'A FAT RUN'
        expId = None

        cursor = MockCursor("NotExists")
        self.conn.addCursor(cursor)

        qry = 'select fat_id from FAT where name="' + runName + \
            '" and lab_id=' + str(expLabId)
        cursor.addExpectedExecute(qry, None)

        self.failIf(FATData.exists(dptDB, runName),
                    'Run ' + runName + ' should not exist')

    def testExists(self):
        dptDB = DOMProdTestDB(self.conn)

        expLabId = 12345
        self.addMockLabIdQuery(expLabId)

        runName = 'A FAT RUN'
        expId = 12345

        cursor = MockCursor("NoResult")
        self.conn.addCursor(cursor)

        qry = 'select fat_id from FAT where name="' + runName + \
            '" and lab_id=' + str(expLabId)
        cursor.addExpectedExecute(qry, (expId, ))

        self.failUnless(FATData.exists(dptDB, runName),
                        'Run ' + runName + ' should exist')

    def testSaveFirst(self):
        dptDB = DOMProdTestDB(self.conn)

        expLabId = 12345
        self.addMockLabIdQuery(expLabId)

        runName = 'A FAT RUN'
        startDate = '2005-08-04'
        expId = 1

        cursor = MockCursor("FirstRun")
        self.conn.addCursor(cursor)

        qry = 'select max(fat_id) from FAT'
        cursor.addExpectedExecute(qry, None)

        cursor = MockCursor("SaveFirst")
        self.conn.addCursor(cursor)

        ins = 'insert into FAT(fat_id,lab_id,name,start_date,end_date' + \
            ',comment)values(' + str(expId) + ',' + str(expLabId) + ',"' + \
            runName + '","' + startDate + '",null,null)'
        cursor.addExpectedExecute(ins)

        data = FATData(runName, startDate, None, None)

        data.save(dptDB)

    def testSave(self):
        dptDB = DOMProdTestDB(self.conn)

        expLabId = 12345
        self.addMockLabIdQuery(expLabId)

        runName = 'A FAT RUN'
        startDate = '2005-08-04'
        expId = 1234

        cursor = MockCursor("GetNextId")
        self.conn.addCursor(cursor)

        qry = 'select max(fat_id) from FAT'
        cursor.addExpectedExecute(qry, (expId - 1, ))

        cursor = MockCursor("Save")
        self.conn.addCursor(cursor)

        ins = 'insert into FAT(fat_id,lab_id,name,start_date,end_date' + \
            ',comment)values(' + str(expId) + ',' + str(expLabId) + ',"' + \
            runName + '","' + startDate + '",null,null)'
        cursor.addExpectedExecute(ins)

        data = FATData(runName, startDate, None, None)

        data.save(dptDB)
Beispiel #8
0
class testDOMProdTestDB(unittest.TestCase):
    """Unit tests for DOMProdTestDB module"""
    def setUp(self):
        self.conn = MockConnection()

    def tearDown(self):
        self.conn.verify()

    def testGetDOMIdNone(self):
        dptDB = DOMProdTestDB(self.conn)

        domTag = 'TEDY1234'
        expId = None

        cursor = MockCursor("NoResult")
        self.conn.addCursor(cursor)

        qry = 'select prod_id from Product where tag_serial="' + domTag + '"'
        cursor.addExpectedExecute(qry, None)

        id = dptDB.getDOMId(domTag)
        self.assertEqual(id, expId, "Expected empty query to return None")

    def testGetDOMIdDirect(self):
        dptDB = DOMProdTestDB(self.conn)

        domTag = 'TEDY1234'
        expId = 12345

        cursor = MockCursor("Direct")
        self.conn.addCursor(cursor)

        qry = 'select prod_id from Product where tag_serial="' + domTag + '"'
        cursor.addExpectedExecute(qry, (expId, ))

        id = dptDB.getDOMId(domTag)
        self.assertEqual(id, expId,
                         "Expected ID#" + str(expId) + ", got ID#" + str(id))

    def testGetDOMIdIndirect(self):
        dptDB = DOMProdTestDB(self.conn)

        mbSerial = 'fedcba543210'
        expId = 12345

        cursor = MockCursor("Indirect")
        self.conn.addCursor(cursor)

        qry = 'select d.prod_id' + \
            ' from Product mb,AssemblyProduct ap,Assembly a,Product d' + \
            ' where mb.hardware_serial="' + mbSerial + '"' + \
            ' and mb.prod_id=ap.prod_id and ap.assem_id=a.assem_id' + \
            ' and a.prod_id=d.prod_id'
        cursor.addExpectedExecute(qry, (expId, ))

        id = dptDB.getDOMId(mbSerial)
        self.assertEqual(id, expId,
                         "Expected ID#" + str(expId) + ", got ID#" + str(id))

    def testGetLabIdByNameNone(self):
        dptDB = DOMProdTestDB(self.conn)

        hostName = 'foo.bar.com'
        expId = None

        cursor = MockCursor("LabNameNone")

        qry = 'select lab_id from Laboratory where name="' + hostName + '"'
        cursor.addExpectedExecute(qry, None)

        id = dptDB.getLabIdByName(cursor, hostName)
        self.assertEqual(
            id, expId, "Expected getLabIdByName to return " + str(expId) +
            ", not " + str(id))

        cursor.verify()

    def testGetLabIdByName(self):
        dptDB = DOMProdTestDB(self.conn)

        hostName = 'foo.bar.com'
        expId = 12345

        cursor = MockCursor("LabName")

        qry = 'select lab_id from Laboratory where name="' + hostName + '"'
        cursor.addExpectedExecute(qry, (expId, ))

        id = dptDB.getLabIdByName(cursor, hostName)
        self.assertEqual(
            id, expId, "Expected getLabIdByName to return " + str(expId) +
            ", not " + str(id))

        cursor.verify()

    def testGetLabIdByMachNone(self):
        dptDB = DOMProdTestDB(self.conn)

        hostName = 'foo.bar.com'
        expId = None

        cursor = MockCursor("LabMachNone")

        tmpName = hostName
        while True:
            qry = 'select lab_id from LabMachine where machine="' + tmpName + \
                '"'
            cursor.addExpectedExecute(qry, None)

            dot = tmpName.find('.')
            if dot < 0:
                break

            tmpName = tmpName[dot + 1:]

        id = dptDB.getLabIdByMachine(cursor, hostName)
        self.assertEqual(
            id, expId, "Expected getLabIdByName to return " + str(expId) +
            ", not " + str(id))

        cursor.verify()

    def testGetLabIdByMach(self):
        dptDB = DOMProdTestDB(self.conn)

        pieces = ['foo', 'bar', 'com']

        hostName = '.'.join(pieces)
        expId = 12345

        for i in range(len(pieces)):
            cursor = MockCursor("LabMach#" + str(i))

            n = 0
            tmpName = hostName
            while True:
                qry = 'select lab_id from LabMachine where machine="' + \
                    tmpName + '"'
                if n < i:
                    cursor.addExpectedExecute(qry, None)
                else:
                    cursor.addExpectedExecute(qry, (expId, ))
                    break

                n = n + 1

                dot = tmpName.find('.')
                if dot < 0:
                    break

                tmpName = tmpName[dot + 1:]

            id = dptDB.getLabIdByMachine(cursor, hostName)
            self.assertEqual(
                id, expId, "Expected getLabIdByName to return " + str(expId) +
                ", not " + str(id))

            cursor.verify()

    def testGetLabIdNone(self):
        dptDB = DOMProdTestDB(self.conn)

        hostName = 'foo.bar.com'
        expId = None

        cursor = MockCursor("SubNameNone")
        self.conn.addCursor(cursor)

        qry = 'select lab_id from Laboratory where name="' + hostName + '"'
        cursor.addExpectedExecute(qry, None)

        cursor = MockCursor("SubMachNone")
        self.conn.addCursor(cursor)

        tmpName = hostName
        while True:
            qry = 'select lab_id from LabMachine where machine="' + tmpName + \
                '"'
            cursor.addExpectedExecute(qry, None)

            dot = tmpName.find('.')
            if dot < 0:
                break

            tmpName = tmpName[dot + 1:]

        try:
            id = dptDB.getLabId(hostName)
            self.fail("Expected getLabId(" + hostName + ") to fail")
        except IOError as msg:
            pass  # expect this to fail

    def testGetLabIdRtnMach(self):
        dptDB = DOMProdTestDB(self.conn)

        pieces = ['foo', 'bar', 'com']

        hostName = '.'.join(pieces)
        expId = 12345

        for i in range(len(pieces)):
            cursor = MockCursor("SubNameNone#2x" + str(i))
            self.conn.addCursor(cursor)

            qry = 'select lab_id from Laboratory where name="' + hostName + '"'
            cursor.addExpectedExecute(qry, None)

            cursor = MockCursor("SubMachRtn#" + str(i))
            self.conn.addCursor(cursor)

            n = 0
            tmpName = hostName
            while True:
                qry = 'select lab_id from LabMachine where machine="' + \
                    tmpName + '"'
                if n < i:
                    cursor.addExpectedExecute(qry, None)
                else:
                    cursor.addExpectedExecute(qry, (expId, ))
                    break

                n = n + 1

                dot = tmpName.find('.')
                if dot < 0:
                    break

                tmpName = tmpName[dot + 1:]

            id = dptDB.getLabId(hostName)
            self.assertEqual(
                id, expId, "Expected getLabId to return " + str(expId) +
                ", not " + str(id))

    def testGetLabIdRtnName(self):
        dptDB = DOMProdTestDB(self.conn)

        hostName = 'foo.bar.com'
        expId = 12345

        cursor = MockCursor("SubName")
        self.conn.addCursor(cursor)

        qry = 'select lab_id from Laboratory where name="' + hostName + '"'
        cursor.addExpectedExecute(qry, (expId, ))

        id = dptDB.getLabId(hostName)
        self.assertEqual(
            id, expId,
            "Expected getLabId to return " + str(expId) + ", not " + str(id))

    def testGetMainBoardIdNone(self):
        dptDB = DOMProdTestDB(self.conn)

        mbSerial = 'fedcba543210'
        expId = None

        cursor = MockCursor("NoResult")
        self.conn.addCursor(cursor)

        qry = 'select prod_id from Product where hardware_serial="' + \
            mbSerial + '"'
        cursor.addExpectedExecute(qry, None)

        id = dptDB.getMainBoardId(mbSerial)
        self.assertEqual(id, expId, "Expected empty query to return None")

    def testGetMainBoardIdDirect(self):
        dptDB = DOMProdTestDB(self.conn)

        mbSerial = 'fedcba543210'
        expId = 12345

        cursor = MockCursor("Direct")
        self.conn.addCursor(cursor)

        qry = 'select prod_id from Product' + \
            ' where hardware_serial="' + mbSerial + '"'
        cursor.addExpectedExecute(qry, (expId, ))

        id = dptDB.getMainBoardId(mbSerial)
        self.assertEqual(id, expId,
                         "Expected ID#" + str(expId) + ", got ID#" + str(id))

    def testGetMainBoardIdIndirect(self):
        dptDB = DOMProdTestDB(self.conn)

        domTag = 'TEDY1234'
        expId = 12345

        cursor = MockCursor("Indirect")
        self.conn.addCursor(cursor)

        qry = 'select mb.prod_id' + \
            ' from Product mb,AssemblyProduct ap,Assembly a,Product d' + \
            ' where d.tag_serial="' + domTag + '" and d.prod_id=a.prod_id' + \
            ' and a.assem_id=ap.assem_id and ap.prod_id=mb.prod_id'
        cursor.addExpectedExecute(qry, (expId, ))

        id = dptDB.getMainBoardId(domTag)
        self.assertEqual(id, expId,
                         "Expected ID#" + str(expId) + ", got ID#" + str(id))

    def testGetProductMB(self):
        dptDB = DOMProdTestDB(self.conn)

        mbSerial = 'fedcba543210'
        expId = 12345

        cursor = MockCursor("Direct")
        self.conn.addCursor(cursor)

        qry = 'select prod_id from Product' + \
            ' where hardware_serial="' + mbSerial + '"'
        cursor.addExpectedExecute(qry, (expId, ))

        id = dptDB.getProductId(mbSerial)
        self.assertEqual(id, expId,
                         "Expected ID#" + str(expId) + ", got ID#" + str(id))

    def testGetProductDOM(self):
        dptDB = DOMProdTestDB(self.conn)

        domTag = 'TEDY1234'
        expId = 12345

        cursor = MockCursor("Indirect")
        self.conn.addCursor(cursor)

        qry = 'select prod_id from Product' + \
            ' where tag_serial="' + domTag + '"'
        cursor.addExpectedExecute(qry, (expId, ))

        id = dptDB.getProductId(domTag)
        self.assertEqual(id, expId,
                         "Expected ID#" + str(expId) + ", got ID#" + str(id))
Beispiel #9
0
class testMonData(unittest.TestCase):
    """Unit tests for MonData class"""
    def setUp(self):
        self.conn = MockConnection()

    def tearDown(self):
        self.conn.verify()

    def testInit(self):
        dptDB = DOMProdTestDB(self.conn)

        mbSerial = '123fed456cba'
        maxTemp = 12.34
        minTemp = 1.234
        avgTemp = 6.78
        maxHV = 234
        minHV = 123
        avgHV = 178
        maxPT = 34.56
        minPT = 3.456
        avgPT = 18.76
        maxRate = 456
        minRate = 321
        avgRate = 388.888
        width = 56.7
        const = 678.9
        numSpikes = 7
        r2 = 8.90
        histo = [0, 0, 1, 5, 10, 7, 4, 1, 1, 1, 0, 0]

        mon = MonData(mbSerial, maxTemp, minTemp, avgTemp, maxHV, minHV, avgHV,
                      maxPT, minPT, avgPT, maxRate, minRate, avgRate, width,
                      const, numSpikes, r2, histo)

        prodId = 777
        monId = 666
        dataId = 600

        cursor = MockCursor("GetProdId")
        self.conn.addCursor(cursor)

        qry = 'select d.prod_id from Product mb,AssemblyProduct ap' + \
              ',Assembly a,Product d' + \
              ' where mb.hardware_serial="' + mbSerial + \
              '" and mb.prod_id=ap.prod_id' + \
              ' and ap.assem_id=a.assem_id and a.prod_id=d.prod_id'
        cursor.addExpectedExecute(qry, (prodId, ))

        cursor = MockCursor("InsMonData")
        self.conn.addCursor(cursor)

        qry = ('insert into FATMonData(fat_mondata_id,fat_mon_id' +
                   ',prod_id,temp_max,temp_min,temp_avg' +
                   ',hv_max,hv_min,hv_avg,pt_max,pt_min,pt_avg' +
                   ',rate_max,rate_min,rate_avg' +
                   ',width,constant,num_spikes,r2)' +
                   'values(%d,%d' +
                   ',%d,%f,%f,%f' +
                   ',%d,%d,%d,%f,%f,%f' +
                   ',%d,%d,%f' +
                   ',%f,%f,%d,%f)') % \
                   (dataId, monId, prodId, maxTemp, minTemp, avgTemp,
                    maxHV, minHV, avgHV, maxPT, minPT, avgPT,
                    maxRate, minRate, avgRate, width, const, numSpikes, r2)
        cursor.addExpectedExecute(qry)

        for bin in range(len(histo)):
            qry = 'insert into FATMonHisto(fat_mondata_id,bin,value)' + \
                  'values(%d,%d,%d)' % (dataId, bin, histo[bin])
            cursor.addExpectedExecute(qry)

        mon.insert(dptDB, monId, dataId)
Beispiel #10
0
class testMonitor(unittest.TestCase):
    """Unit tests for Monitor class"""
    def setUp(self):
        self.conn = MockConnection()

    def tearDown(self):
        self.conn.verify()

    def fakeData(self, baseId):
        mbSerial = '%06x%06x' % (baseId, baseId + 16)
        maxTemp = baseId + 12.34
        minTemp = baseId + 1.234
        avgTemp = baseId + 6.78
        maxHV = baseId + 234
        minHV = baseId + 123
        avgHV = baseId + 178
        maxPT = baseId + 34.56
        minPT = baseId + 3.456
        avgPT = baseId + 18.76
        maxRate = baseId + 456
        minRate = baseId + 321
        avgRate = baseId + 388.888
        width = baseId + 56.7
        const = baseId + 678.9
        numSpikes = baseId + 7
        r2 = baseId + 8.90
        histo = [0, baseId / 10, baseId, baseId / 2, baseId / 5, 0]

        return MonData(mbSerial, maxTemp, minTemp, avgTemp, maxHV, minHV,
                       avgHV, maxPT, minPT, avgPT, maxRate, minRate, avgRate,
                       width, const, numSpikes, r2, histo)

    def testBasic(self):
        dptDB = DOMProdTestDB(self.conn)

        mon = Monitor(12.34)

        mon.setBinSize(11)
        try:
            mon.setBinSize(12)
            fail('Should not be able to set binSize to different size')
        except ValueError:
            pass  # expect this to fail

    def testInsertNoData(self):
        dptDB = DOMProdTestDB(self.conn)

        temp = 12.34
        binSize = 17

        mon = Monitor(temp)

        mon.setBinSize(binSize)

        monId = 123
        fatId = 456

        cursor = MockCursor("GetMonId")
        self.conn.addCursor(cursor)

        qry = 'select max(fat_mon_id) from FATMonitor'
        cursor.addExpectedExecute(qry, (monId - 1, ))

        cursor = MockCursor("InsMon")
        self.conn.addCursor(cursor)

        qry = 'insert into FATMonitor(fat_mon_id,fat_id,temp,binsize)' + \
              'values(' + str(monId) + ',' + str(fatId) + ',"' + \
              str(temp) + '",' + str(binSize) + ')'
        cursor.addExpectedExecute(qry, None)

        mon.insert(dptDB, fatId)

    def testInsert(self):
        dptDB = DOMProdTestDB(self.conn)

        temp = 12.34
        binSize = 17

        mon = Monitor(temp)

        mon.setBinSize(binSize)

        data = [
            self.fakeData(111111),
            self.fakeData(24680),
            self.fakeData(3691224)
        ]
        for d in data:
            mon.append(d)

        monId = 123
        fatId = 456
        nextDataId = 789

        cursor = MockCursor("GetMonId")
        self.conn.addCursor(cursor)

        qry = 'select max(fat_mon_id) from FATMonitor'
        cursor.addExpectedExecute(qry, (monId - 1, ))

        cursor = MockCursor("InsMon")
        self.conn.addCursor(cursor)

        qry = 'insert into FATMonitor(fat_mon_id,fat_id,temp,binsize)' + \
              'values(' + str(monId) + ',' + str(fatId) + ',"' + \
              str(temp) + '",' + str(binSize) + ')'
        cursor.addExpectedExecute(qry, None)

        cursor = MockCursor("GetDataId")
        self.conn.addCursor(cursor)

        qry = 'select max(fat_mondata_id) from FATMonData'
        cursor.addExpectedExecute(qry, (nextDataId - 1, ))

        nextProdId = 333

        for i in range(len(data)):
            d = data[i]

            cursor = MockCursor("GetProdId#" + str(i))
            self.conn.addCursor(cursor)

            qry = 'select d.prod_id from Product mb,AssemblyProduct ap' + \
                  ',Assembly a,Product d' + \
              ' where mb.hardware_serial="' + d.mbId + \
              '" and mb.prod_id=ap.prod_id' + \
              ' and ap.assem_id=a.assem_id and a.prod_id=d.prod_id'
            cursor.addExpectedExecute(qry, (nextProdId, ))

            cursor = MockCursor("InsMonData#" + str(i))
            self.conn.addCursor(cursor)

            qry = ('insert into FATMonData(fat_mondata_id,fat_mon_id' +
                   ',prod_id,temp_max,temp_min,temp_avg' +
                   ',hv_max,hv_min,hv_avg,pt_max,pt_min,pt_avg' +
                   ',rate_max,rate_min,rate_avg' +
                   ',width,constant,num_spikes,r2)' +
                   'values(%d,%d' +
                   ',%d,%f,%f,%f' +
                   ',%d,%d,%d,%f,%f,%f' +
                   ',%d,%d,%f' +
                   ',%f,%f,%d,%f)') % \
                   (nextDataId, monId, nextProdId,
                    d.maxTemp, d.minTemp, d.avgTemp,
                    d.maxHV, d.minHV, d.avgHV,
                    d.maxPT, d.minPT, d.avgPT,
                    d.maxRate, d.minRate, d.avgRate,
                    d.width, d.const, d.numSpikes, d.r2)
            cursor.addExpectedExecute(qry)

            for bin in range(len(d.histo)):
                qry = 'insert into FATMonHisto(fat_mondata_id,bin,value)' + \
                      'values(%d,%d,%d)' % (nextDataId, bin, d.histo[bin])
                cursor.addExpectedExecute(qry)

            nextDataId = nextDataId + 1
            nextProdId = nextProdId + 1

        mon.insert(dptDB, fatId)
Beispiel #11
0
class testTestResult(unittest.TestCase):
    """Unit tests for TestResult class"""

    def notChar(self, dir, descr):
        if dir == 0:
            ch = '!'
        else:
            ch = ' '
        return ch + descr

    def setUp(self):
        self.conn = MockConnection()

    def tearDown(self):
        self.conn.verify()

    def testIncomplete(self):
        dptDB = DOMProdTestDB(self.conn)

        fatId = 123

        for lo in range(1):
            if lo == 0:
                loDOM = None
            else:
                loDOM = 'UX3P0123'

            for hi in range(1):
                if lo == 1 and hi == 1:
                    continue

                if hi == 0:
                    hiDOM = None
                else:
                    hiDOM = 'AE3H0001'

                result = TestResult(loDOM, hiDOM)

                for set in range(1):
                    if set == 1:
                        result.setDownNeg(lo == 0)
                        result.setDownPos(hi == 1)
                        result.setUpNeg(lo == 0)
                        result.setUpPos(hi == 1)

                    self.failIf(result.isFilled(), 'Result[' + str(loDOM) +
                                '/' + str(hiDOM) +
                                '] should not claim to be filled')
                    self.failIf(result.isSuccess(), 'Result[' + str(loDOM) +
                                '/' + str(hiDOM) +
                                '] should not be a success')

                    try:
                        result.insert(dptDB, fatId)
                        fail('Result [' + str(loDOM) + '/' + str(hiDOM) +
                             '] insert should not succeed')
                    except ValueError:
                        pass # expect this to fail

    def testInsert(self):
        dptDB = DOMProdTestDB(self.conn)

        fatId = 123

        loDOM = 'UX3P0123'
        loId = 543

        hiDOM = 'AE3H0001'
        hiId = 678

        result = TestResult(loDOM, hiDOM)

        for dn in range(1):
            for dp in range(1):
                for un in range(1):
                    for up in range(1):
                        result.setDownNeg(dn == 1)
                        result.setDownPos(dp == 1)
                        result.setUpNeg(un == 1)
                        result.setUpPos(up == 1)

                        self.failUnless(result.isFilled(),
                                        'Result[' + str(loDOM) + '/' +
                                        str(hiDOM) + '] should be filled')
                        if (dn + dp + un + up) == 4:
                            self.failUnless(result.isSuccess(), 'Result[' +
                                            str(loDOM) + '/' + str(hiDOM) +
                                            '] should be a success')
                        else:
                            self.failIf(result.isSuccess(), 'Result[' +
                                        str(loDOM) + '/' + str(hiDOM) +
                                        '] should not be a success')

                        name = self.notChar(dn, 'D-') + \
                            self.notChar(dp, 'D+') + \
                            self.notChar(un, 'U-') + \
                            self.notChar(up, 'U+')

                        cursor = MockCursor(name + " LoDOM")
                        self.conn.addCursor(cursor)

                        qry = 'select prod_id from Product' + \
                            ' where tag_serial="' + loDOM + '"'
                        cursor.addExpectedExecute(qry, (loId, ))

                        cursor = MockCursor(name + " LoDOM")
                        self.conn.addCursor(cursor)

                        qry = 'select prod_id from Product' + \
                            ' where tag_serial="' + hiDOM + '"'
                        cursor.addExpectedExecute(qry, (hiId, ))

                        cursor = MockCursor(name + " Insert")
                        self.conn.addCursor(cursor)

                        qry = 'insert into FATLCChain(fat_id,hi_prod_id' + \
                            ',lo_prod_id,down_neg,down_pos,up_neg,up_pos)' + \
                            'values(' + str(fatId) + ',' + str(loId) + ',' + \
                            str(hiId) +  ',' + str(dn) + ',' + \
                            str(dp) + ',' + str(un) + ',' + str(up) + ')'
                        cursor.addExpectedExecute(qry)

                        result.insert(dptDB, fatId)