Пример #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 storageCheck(key, lifeTime, expected, clean=False):
    """ check that object is found from the appropriate storage """
    actual = tai.getStoredObject(key, lifeTime)
    global currentTestCaseObject
    getUnittestObj().assertEqual(
        actual, expected, "key '%s' has unexpected value: '%s', expected '%s'" % (key, str(actual), str(expected))
    )
Пример #3
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)
Пример #4
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)