示例#1
0
def checkLoopsUsingIterator(loopList, index, elem):

    expectedIndex = tai.getStoredObject("checkLoopsUsingIterator", defaultValue=0)
    getUnittestObj().assertEqual(
        index, expectedIndex, "index parameter has unexpected value: %s, expected %s" % (str(index), str(expectedIndex))
    )
    getUnittestObj().assertEqual(
        elem,
        loopList[index],
        "iterated element has unexpected value: '%s', expected '%s'" % (str(elem), str(loopList[index])),
    )

    indexFromAPI = tai.getBlockIterationIndex()
    iterObjFromAPI = tai.getBlockIterationObject()
    getUnittestObj().assertEqual(
        indexFromAPI,
        expectedIndex,
        "tai.getBlockExecutionIndex() returned unexpected value: %s, expected %s"
        % (str(indexFromAPI), str(expectedIndex)),
    )
    getUnittestObj().assertEqual(
        iterObjFromAPI,
        elem,
        "tai.getBlockIterationObject() returned unexpected value: '%s', expected '%s'"
        % (str(iterObjFromAPI), str(elem)),
    )

    expectedIndex = expectedIndex + 1
    if expectedIndex == len(loopList):
        tai.removeStoredObject("checkLoopsUsingIterator")
    else:
        tai.storeObject("checkLoopsUsingIterator", expectedIndex)
示例#2
0
def checkLoopsUsingCounter(maxCounter, index):

    expectedIndex = tai.getStoredObject("checkLoopsUsingCounter", defaultValue=0)
    getUnittestObj().assertEqual(
        index, expectedIndex, "index parameter has unexpected value: %s, expected %s" % (str(index), str(expectedIndex))
    )

    indexFromAPI = tai.getBlockIterationIndex()
    getUnittestObj().assertEqual(
        indexFromAPI,
        expectedIndex,
        "tai.getBlockExecutionIndex() returned unexpected value: %s, expected %s"
        % (str(indexFromAPI), str(expectedIndex)),
    )

    expectedIndex = expectedIndex + 1
    if expectedIndex == maxCounter:
        tai.removeStoredObject("checkLoopsUsingCounter")
    else:
        tai.storeObject("checkLoopsUsingCounter", expectedIndex)
示例#3
0
def storageCheckNonExistingKey():
    """ check situations when existing key is asked or removed """
    rightNow = time.time()
    uniqueKey = "key_time_%f" % rightNow

    global currentTestCaseObject

    for lifeTime in tai.LIFETIME.getAllAsList():
        if lifeTime in [tai.LIFETIME.END_OF_FUNCTION, tai.LIFETIME.PERSISTENT]:
            continue  # no need to check for these
        actual = tai.getStoredObject(uniqueKey, lifeTime, rightNow)
        getUnittestObj().assertEqual(
            actual,
            rightNow,
            "key '%s' has unexpected value: '%s', expected '%s'" % (uniqueKey, str(actual), str(rightNow)),
        )

        tai.removeStoredObject(uniqueKey, lifeTime, False)

        # call tai.getStoredObject(uniqueKey, lifeTime, rightNow, True) and
        # expect KeyError exception:
        getUnittestObj().assertRaises(KeyError, tai.getStoredObject, uniqueKey, lifeTime, rightNow, True)
        getUnittestObj().assertRaises(KeyError, tai.removeStoredObject, uniqueKey, lifeTime, True)
示例#4
0
def storageRemove(key, lifeTime):
    """ remove object from the appropriate storage """
    tai.removeStoredObject(key, lifeTime)
示例#5
0
def deleteStoredObject(key, lifeTime):
    tai.removeStoredObject(key, lifeTime)