Exemple #1
0
def getColumnPosition(worksheet, dictionaryType):
    columnDescriptionLetter = ""
    columnActionLetter = ""
    columnExpectedResLetter = ""
    if dictionaryType == "action":
        columnDescriptionLetter = getColumnLetterFromString(worksheet, file_Tools_Actions_Column['stepDescr_header'])
        if columnDescriptionLetter == "":
            debugPrint("Column" + file_Tools_Actions_Column['stepDescr_header'] + "not found")
            exit()
        columnActionLetter = getColumnLetterFromString(worksheet, file_Tools_Actions_Column['action_header'])
        if columnActionLetter == "":
            debugPrint("Column" + file_Tools_Actions_Column['stepDescr_header'] + "not found")
            exit()
        columnExpectedResLetter = getColumnLetterFromString(worksheet, file_Tools_Actions_Column['expected_header'])
        if columnExpectedResLetter == "":
            debugPrint("Column" + file_Tools_Actions_Column['stepDescr_header'] + "not found")
            exit()
    elif dictionaryType == "verify":
        columnDescriptionLetter = getColumnLetterFromString(worksheet, file_Tools_Verify_Column['stepDescr_header'])
        if columnDescriptionLetter == "":
            debugPrint("Column" + file_Tools_Verify_Column['stepDescr_header'] + "not found")
            exit()
        columnExpectedResLetter = getColumnLetterFromString(worksheet, file_Tools_Verify_Column['expected_header'])
        if columnExpectedResLetter == "":
            debugPrint("Column" + file_Tools_Verify_Column['stepDescr_header'] + "not found")
            exit()
    else:
        debugPrint("dictionary type chosen not correct - shall be either 'action' or 'verify'")
    return columnDescriptionLetter, columnActionLetter, columnExpectedResLetter
Exemple #2
0
def importDictionaryV2(worksheetAction, functionDictionary, dictionaryType):
    fieldType_Col_Index = getColumnIndexFromString(
        worksheetAction, file_Tools_Verify_Column['fieldType_header'])
    valueLetter = getColumnLetterFromString(
        worksheetAction, file_Tools_Verify_Column['value_header'])
    enableLetter = getColumnLetterFromString(
        worksheetAction, file_Tools_Verify_Column['enable_header'])
    stepDescriptionLetter = getColumnLetterFromString(
        worksheetAction, file_Tools_Verify_Column['stepDescr_header'])
    preconditionLetter = getColumnLetterFromString(
        worksheetAction, file_Tools_Verify_Column['precondition_header'])
    expectedLetter = getColumnLetterFromString(
        worksheetAction, file_Tools_Verify_Column['expected_header'])
    timeStepLetter = getColumnLetterFromString(
        worksheetAction, file_Tools_Verify_Column['timeStep_header'])
    sampleTimeLetter = getColumnLetterFromString(
        worksheetAction, file_Tools_Verify_Column['sampleTime_header'])
    toleranceLetter = getColumnLetterFromString(
        worksheetAction, file_Tools_Verify_Column['tolerance_header'])

    functionName = ""
    for col in worksheetAction.iter_cols(min_col=fieldType_Col_Index,
                                         max_col=fieldType_Col_Index,
                                         min_row=2,
                                         values_only=True):
        for rowNum, rowValue in enumerate(col, start=2):
            if rowValue == "<function>":
                functionName = worksheetAction[valueLetter + str(rowNum)].value
                if functionName not in functionDictionary:
                    functionDictionary[functionName] = {
                        'startRow': rowNum,
                        'endRow': rowNum,
                        'parameters': [],
                        'data': []
                    }
            elif rowValue == "<step>":
                s = singleTestStep(
                    worksheetAction[enableLetter + str(rowNum)].value,
                    worksheetAction[stepDescriptionLetter + str(rowNum)].value,
                    worksheetAction[preconditionLetter + str(rowNum)].value,
                    worksheetAction[expectedLetter + str(rowNum)].value,
                    worksheetAction[timeStepLetter + str(rowNum)].value,
                    worksheetAction[sampleTimeLetter + str(rowNum)].value,
                    worksheetAction[toleranceLetter + str(rowNum)].value)
                if functionName != "":
                    functionDictionary[functionName]['endRow'] = rowNum
                    functionDictionary[functionName]['data'].append(s)
            elif rowValue == "<parameter>":
                if functionName != "":
                    parameterName = worksheetAction[valueLetter +
                                                    str(rowNum)].value
                    functionDictionary[functionName]['parameters'].append(
                        parameterName)
            else:
                print(rowNum)
                print(worksheetAction)
                return 1
                raise KeyError
def checkActionFile(worksheetAction, worksheetActionFileName):
    try:
        getColumnIndexFromString(worksheetAction,
                                 file_Tools_Verify_Column['fieldType_header'])
        getColumnLetterFromString(worksheetAction,
                                  file_Tools_Verify_Column['fieldType_header'])
        getColumnLetterFromString(worksheetAction,
                                  file_Tools_Verify_Column['value_header'])
        getColumnLetterFromString(worksheetAction,
                                  file_Tools_Verify_Column['stepDescr_header'])
        getColumnLetterFromString(
            worksheetAction, file_Tools_Verify_Column['precondition_header'])
        getColumnLetterFromString(worksheetAction,
                                  file_Tools_Verify_Column['expected_header'])
        getColumnLetterFromString(worksheetAction,
                                  file_Tools_Verify_Column['timeStep_header'])
        getColumnLetterFromString(
            worksheetAction, file_Tools_Verify_Column['sampleTime_header'])
        getColumnLetterFromString(worksheetAction,
                                  file_Tools_Verify_Column['tolerance_header'])
    except ValueError:
        debugPrint("In file ", worksheetActionFileName)
        exit()
def checkBuildFile(worksheetBuild, worksheetBuildFileName):
    try:
        getColumnLetterFromString(worksheetBuild,
                                  file_TC_BUILD_Column['enable_header'])
        getColumnLetterFromString(worksheetBuild,
                                  file_TC_BUILD_Column['testN_header'])
        getColumnLetterFromString(worksheetBuild,
                                  file_TC_BUILD_Column['testID_header'])
        getColumnLetterFromString(worksheetBuild,
                                  file_TC_BUILD_Column['testType_header'])
        getColumnLetterFromString(worksheetBuild,
                                  file_TC_BUILD_Column['stepID_header'])
        getColumnLetterFromString(worksheetBuild,
                                  file_TC_BUILD_Column['stepDescr_header'])
        getColumnLetterFromString(worksheetBuild,
                                  file_TC_BUILD_Column['precondition_header'])
        getColumnLetterFromString(worksheetBuild,
                                  file_TC_BUILD_Column['action_header'])
        getColumnLetterFromString(worksheetBuild,
                                  file_TC_BUILD_Column['expected_header'])
        getColumnLetterFromString(worksheetBuild,
                                  file_TC_BUILD_Column['timeStep_header'])
        getColumnLetterFromString(worksheetBuild,
                                  file_TC_BUILD_Column['sampleTime_header'])
        getColumnLetterFromString(worksheetBuild,
                                  file_TC_BUILD_Column['tolerance_header'])

    except ValueError:
        debugPrint("In file ", worksheetBuildFileName)
        exit()
def substituteFunctions(swStart, wsEnd, substitutionDictionary):
    # findExpressions(worksheetStart=swStart, substitutionDictionary=substitutionDictionary)

    columnEnableIndex = getColumnIndexFromString(
        swStart, file_TC_BUILD_Column['enable_header'])
    columnTestNIndex = getColumnIndexFromString(
        swStart, file_TC_BUILD_Column['testN_header'])
    columnTestIDIndex = getColumnIndexFromString(
        swStart, file_TC_BUILD_Column['testID_header'])
    columnDescriptionIndex = getColumnIndexFromString(
        swStart, file_TC_BUILD_Column['stepDescr_header'])
    columnPreconditionIndex = getColumnIndexFromString(
        swStart, file_TC_BUILD_Column['precondition_header'])
    columnActionIndex = getColumnIndexFromString(
        swStart, file_TC_BUILD_Column['action_header'])
    columnExpectedResIndex = getColumnIndexFromString(
        swStart, file_TC_BUILD_Column['expected_header'])
    columnTimeStepIndex = getColumnIndexFromString(
        swStart, file_TC_BUILD_Column['timeStep_header'])
    columnSampleTimeIndex = getColumnIndexFromString(
        swStart, file_TC_BUILD_Column['sampleTime_header'])
    columnToleranceIndex = getColumnIndexFromString(
        swStart, file_TC_BUILD_Column['tolerance_header'])

    columnEnableLetter = getColumnLetterFromString(
        swStart, file_TC_BUILD_Column['enable_header'])
    columnTestNLetter = getColumnLetterFromString(
        swStart, file_TC_BUILD_Column['testN_header'])
    columnDescriptionLetter = getColumnLetterFromString(
        swStart, file_TC_BUILD_Column['stepDescr_header'])
    columnPreconditionLetter = getColumnLetterFromString(
        swStart, file_TC_BUILD_Column['precondition_header'])
    columnActionLetter = getColumnLetterFromString(
        swStart, file_TC_BUILD_Column['action_header'])
    columnExpectedResLetter = getColumnLetterFromString(
        swStart, file_TC_BUILD_Column['expected_header'])
    columnTimeStepLetter = getColumnLetterFromString(
        swStart, file_TC_BUILD_Column['timeStep_header'])
    columnSampleTimeLetter = getColumnLetterFromString(
        swStart, file_TC_BUILD_Column['sampleTime_header'])
    columnToleranceLetter = getColumnLetterFromString(
        swStart, file_TC_BUILD_Column['tolerance_header'])

    # startColIndex = column_index_from_string(startCol)
    # endColIndex = column_index_from_string(endCol)
    c = 0
    translation = swStart.max_row + 15
    rowNumEnd = translation
    rowsAdded = 0
    for rowNumStart, row in enumerate(swStart.iter_rows(), start=1):
        # print(c)
        # c += 1
        foundStringToSubstitute = False
        for colNum, cell in enumerate(row, start=1):
            if isinstance(cell.value, str):
                # print(wsheetEnd.cell(row=rowNumEnd, column=colNum + startColIndex).value)
                if len(cell.value) > 2:
                    if "()" in cell.value:
                        functionParsed = parseFunction(cell.value)
                        functionName = functionParsed['functionName']
                        parametersList = functionParsed['parametersList']
                        substitutedFunction = createFunction(
                            functionParsed, substitutionDictionary)
                        if functionName in substitutionDictionary:
                            foundStringToSubstitute = True
                            # enableCell = worksheetStart.cell(row=rowNumStart, column=columnEnableIndex)
                            testNCell = swStart.cell(row=rowNumStart,
                                                     column=columnTestNIndex)
                            # testIDCell = worksheetStart.cell(row=rowNumStart, column=columnTestIDIndex)
                            # parametersList
                            # for dataNum, t in enumerate(substitutionDictionary[functionName]['data']):
                            for dataNum, t in enumerate(substitutedFunction):
                                # riporto il valore di "step" in
                                newRowPos = rowNumStart + translation + rowsAdded + dataNum

                                # riporto il valore di "enable "
                                wsEnd.cell(row=newRowPos,
                                           column=columnEnableIndex,
                                           value=t.enable)
                                if cell.has_style:
                                    wsEnd[
                                        columnEnableLetter +
                                        str(newRowPos)].alignment = Alignment(
                                            horizontal='center')

                                # print(enableCell.value)
                                # riporto il valore in testN
                                wsEnd.cell(row=newRowPos,
                                           column=columnTestNIndex,
                                           value=testNCell.value)
                                wsEnd[columnTestNLetter +
                                      str(newRowPos)].alignment = copy(
                                          testNCell.alignment
                                      )  # Alignment(horizontal='center')
                                ## riporto il valore in testID
                                # worksheetEnd.cell(row=newRowPos, column=columnTestIDIndex, value=testIDCell.value)

                                # riporto il valore della descrizione nella colonna della step description
                                wsEnd.cell(row=newRowPos,
                                           column=columnDescriptionIndex,
                                           value=t.descr)
                                if cell.has_style:
                                    wsEnd[columnDescriptionLetter +
                                          str(newRowPos)].fill = copy(
                                              cell.fill)
                                    wsEnd[columnDescriptionLetter +
                                          str(newRowPos)].border = copy(
                                              cell.border)
                                    wsEnd[columnDescriptionLetter +
                                          str(newRowPos)].font = copy(
                                              cell.font)
                                # riporto il valore dell'azione/risultato atteso" nella colonna corrente
                                wsEnd.cell(row=newRowPos,
                                           column=colNum,
                                           value=t.act)
                                if cell.has_style:
                                    wsEnd[columnPreconditionLetter +
                                          str(newRowPos)].fill = copy(
                                              cell.fill)
                                    wsEnd[columnPreconditionLetter +
                                          str(newRowPos)].border = copy(
                                              cell.border)
                                    wsEnd[columnPreconditionLetter +
                                          str(newRowPos)].font = copy(
                                              cell.font)
                                    wsEnd[columnActionLetter +
                                          str(newRowPos)].fill = copy(
                                              cell.fill)
                                    wsEnd[columnActionLetter +
                                          str(newRowPos)].border = copy(
                                              cell.border)
                                    wsEnd[columnActionLetter +
                                          str(newRowPos)].font = copy(
                                              cell.font)
                                # riporto il valore di "expected res" nella colonna degli expected results
                                wsEnd.cell(row=newRowPos,
                                           column=columnExpectedResIndex,
                                           value=t.exp)
                                if cell.has_style:
                                    wsEnd[columnExpectedResLetter +
                                          str(newRowPos)].fill = copy(
                                              cell.fill)
                                    wsEnd[columnExpectedResLetter +
                                          str(newRowPos)].border = copy(
                                              cell.border)
                                    wsEnd[columnExpectedResLetter +
                                          str(newRowPos)].font = copy(
                                              cell.font)

                                # riporto il valore di "time step"
                                wsEnd.cell(row=newRowPos,
                                           column=columnTimeStepIndex,
                                           value=t.timeStep)
                                if cell.has_style:
                                    wsEnd[columnTimeStepLetter +
                                          str(newRowPos)].fill = copy(
                                              cell.fill)
                                    wsEnd[columnTimeStepLetter +
                                          str(newRowPos)].border = copy(
                                              cell.border)
                                    wsEnd[columnTimeStepLetter +
                                          str(newRowPos)].font = copy(
                                              cell.font)
                                    wsEnd[
                                        columnTimeStepLetter +
                                        str(newRowPos)].alignment = Alignment(
                                            horizontal='center')

                                # riporto il valore di "sample time"
                                wsEnd.cell(row=newRowPos,
                                           column=columnSampleTimeIndex,
                                           value=t.sampleTime)
                                if cell.has_style:
                                    wsEnd[columnSampleTimeLetter +
                                          str(newRowPos)].fill = copy(
                                              cell.fill)
                                    wsEnd[columnSampleTimeLetter +
                                          str(newRowPos)].border = copy(
                                              cell.border)
                                    wsEnd[columnSampleTimeLetter +
                                          str(newRowPos)].font = copy(
                                              cell.font)
                                    wsEnd[
                                        columnSampleTimeLetter +
                                        str(newRowPos)].alignment = Alignment(
                                            horizontal='center')

                                # riporto il valore di tolerance nella colonna degli expected results
                                wsEnd.cell(row=newRowPos,
                                           column=columnToleranceIndex,
                                           value=t.tolerance)
                                if cell.has_style:
                                    wsEnd[columnToleranceLetter +
                                          str(newRowPos)].fill = copy(
                                              cell.fill)
                                    wsEnd[columnToleranceLetter +
                                          str(newRowPos)].border = copy(
                                              cell.border)
                                    wsEnd[columnToleranceLetter +
                                          str(newRowPos)].font = copy(
                                              cell.font)
                                    wsEnd[
                                        columnToleranceLetter +
                                        str(newRowPos)].alignment = Alignment(
                                            horizontal='center')

                            rowsAdded += len(substitutedFunction) - 1
        if not foundStringToSubstitute:
            wsEnd.move_range("A" + str(rowNumStart) + ":AA" + str(rowNumStart),
                             rows=translation + rowsAdded,
                             cols=0)

    wsEnd.delete_rows(1, amount=translation)