Best Python code snippet using lisa_python
ExpressionsProcessing.py
Source:ExpressionsProcessing.py  
1import ExpressionSplitter2def get_main_literals_values(literals):3    values_p_literal = 2**len(literals)  # Total values per literal4    final_evaluation = []  # Array to return5    partial_evaluation = []  # Array to complete final_evaluation6    dictionary = {}7    sequence = values_p_literal  # Sequence between true and false,8    for i in range(0, len(literals), 1):  # For i in every literal9        sequence /= 2  # Sequence is reduced10        found_booleans = 0  # Found booleans11        step = 0  # Step starting in zero12        partial_evaluation.clear()  # Clears array to use again later13        while found_booleans < values_p_literal:  # While found booleans is less than 2^n spaces...14            if step < sequence:  # If step is less than the sequence...15                partial_evaluation.append(bool(1))  # Appends true16                found_booleans += 1  # One boolean was found17                step += 1  # Step increases18            elif step >= sequence:  # Else If step is greater or equal than the sequence...19                partial_evaluation.append(bool(0))  # Appends false20                found_booleans += 1  # One boolean was found21                step += 1  # Step increases22            if step >= sequence*2:  # If step is less than the double of the sequence...23                step = 0  # Step resets24        support_variable = partial_evaluation.copy()  # Partial evaluation is stored in a variable25        final_evaluation.append(support_variable)  # Appends support variable to the final array26        dictionary[literals[i]] = support_variable27    return dictionary28def get_denied_literals_values(normal_dictionary, denied_literals):29    support_variable = []  # Support var30    for i in denied_literals:  # For every denied literal31        substring = i[1]32        support = normal_dictionary.get(str(substring))  # Support variables33        support_variable.clear()34        for j in support:  # For every element in support35            if j:  # If true then...36                support_variable.append(not j)  # Append false37            else:  # If false then...38                support_variable.append(not j)  # Append true39        support = support_variable.copy()  # Partial evaluation is stored in a variable40        normal_dictionary[i] = support41    return normal_dictionary42def split_subexpressions(dictionary, final_exp, literals, denied_literals, exp):  # Splits all of the43    # expression into smaller expressions.44    t1, t2, is_div = ExpressionSplitter.parentheses_indexes_search(exp)45    start = (len(denied_literals) + len(literals))46    temp_array = []47    step = 048    if is_div is False:  # When the operation is divided in two by a â operator.49        for i in range(start, len(final_exp), 1):50            temp_array.clear()51            print(final_exp[i])52            j = 053            if step >= 1:54                temp_array.append(final_exp[i - 1])55                j += len(final_exp[i - 1])56            while j < len(final_exp[i]):57                if (111 < ord(final_exp[i][j]) <= 122) and (ord(final_exp[i][j]) != 118):58                    if final_exp[i][j - 1] == '~':59                        temp_array.append(final_exp[i][j - 1:j + 1])60                    else:61                        temp_array.append(final_exp[i][j])62                elif (final_exp[i][j] == 'v' or final_exp[i][j] == '^' or final_exp[i][j] == 'â' or63                      final_exp[i][j] == 'â'):64                    temp_array.append(final_exp[i][j])65                j += 166            step += 167            count = i68            result = evaluate(dictionary, temp_array, final_exp, count)69            dictionary[final_exp[i]] = result70        return dictionary71    else:  # When the operation is not divided72        for i in range(start, len(final_exp), 1):73            bigger = 074            blocked = False75            temp_array.clear()76            j = 077            if i == (len(final_exp)-1):78                blocked = True79                substring_1, substring_2 = "", ""80                to_append = ""81                for k in range(0, len(final_exp[i]), 1):82                    if (final_exp[i][k] == 'v' or final_exp[i][k] == '^' or final_exp[i][k] == 'â' or83                            final_exp[i][k] == 'â') and (final_exp[i][k-1] == ')'):84                        substring_1 = final_exp[i][0:k]85                        symbol = final_exp[i][k]86                    if (final_exp[i][k] == 'v' or final_exp[i][k] == '^' or final_exp[i][k] == 'â' or87                            final_exp[i][k] == 'â') and (final_exp[i][k+1] == '('):88                        substring_2 = final_exp[i][k+1:len(final_exp[i])]89                    elif (final_exp[i][k] == 'v' or final_exp[i][k] == '^' or final_exp[i][k] == 'â' or90                            final_exp[i][k] == 'â') and (final_exp[i][k+1] == '~'):91                        substring_2 = final_exp[i][k+1:len(final_exp[i])]92                temp_array.append(substring_1)93                temp_array.append(symbol)94                temp_array.append(substring_2)95            elif step >= 1:96                if final_exp[i].find(final_exp[i - 1]) != -1:97                    temp_array.append(final_exp[i - 1])98                    j += len(final_exp[i - 1])99            while j < len(final_exp[i]) and blocked is False:100                if ((111 < ord(final_exp[i][j]) <= 122) and (ord(final_exp[i][j]) != 118)) \101                        or ord(final_exp[i][j]) == '(':102                    if final_exp[i][j - 1] == '~':103                        temp_array.append(final_exp[i][j - 1:j + 1])104                    else:105                        temp_array.append(final_exp[i][j])106                elif (final_exp[i][j] == 'v' or final_exp[i][j] == '^' or final_exp[i][j] == 'â' or107                      final_exp[i][j] == 'â'):108                    temp_array.append(final_exp[i][j])109                j += 1110            step += 1111            print("TA:", temp_array)112            count = i113            result = evaluate(dictionary, temp_array, final_exp, count)114            dictionary[final_exp[i]] = result115        return dictionary116def evaluate(dictionary, array, exp, count):  # Evaluates every expression from the dictionary117    exp1, exp2 = dictionary.get(array[0]), dictionary.get(array[2])  # Assign two dictionaries for local use118    string = str(array[0])119    print("String:", string)120    print("Exp:", exp[count][0:2])121    index = 0122    result = False123    array_support = []124    array_2 = []125    visited = False126    for i in range(len(exp1)):127        if array[1] == 'v':  # OR logical expression128            if (exp1[index] or exp2[index]) is True:129                array_2.append(True)130            else:131                array_2.append(False)132        if array[1] == '^':  # AND logical expression133            if (exp1[index] and exp2[index]) is True:134                array_2.append(True)135            else:136                array_2.append(False)137        if array[1] == 'â':  # Therefore evaluation138            if (exp1[index] is True) and (exp2[index] is False):139                array_2.append(False)140            else:141                array_2.append(True)142        if array[1] == 'â':  # If only evaluation143            if ((exp1[index] is True) and (exp2[index] is True)) or \144                    ((exp1[index] is False) and (exp2[index] is False)):145                array_2.append(True)146            else:147                array_2.append(False)148        print("Exp cnt", exp[count])149        if exp[count][0:1] == '~':  # NOT evaluation, taking the previous character to the expression150            visited = True151            if array_2[index] is True:152                result = False153            else:154                result = True155            array_support.append(result)156        index += 1157    if visited is True:158        array_2 = array_support...argparser.py
Source:argparser.py  
...23        help="Set the log level output by the console to DEBUG level. By default, the "24        "console displays logs with INFO and higher levels. The log file will contain "25        "the DEBUG level and is not affected by this setting.",26    )27def support_variable(parser: ArgumentParser) -> None:28    parser.add_argument(29        "--variable",30        "-v",31        dest="variables",32        action="append",33        help="Variables are defined in runbooks, LISA doesn't pre-define any variable, "34        "Specify one or more variables in the format of `name:value`, which will "35        "overwrite the value in the YAML file. It can support secret values in the "36        "format of `s:name:value`. Learn more from documents.",37    )38def support_log_path(parser: ArgumentParser) -> None:39    parser.add_argument(40        "--log_path",41        "-l",42        type=Path,43        dest="log_path",44        help="Uses to replace the default log root path.",45    )46def support_working_path(parser: ArgumentParser) -> None:47    parser.add_argument(48        "--working_path",49        "-w",50        type=Path,51        dest="working_path",52        help="Uses to replace the default log working path.",53    )54def support_id(parser: ArgumentParser) -> None:55    parser.add_argument(56        "--id",57        "-i",58        type=Path,59        dest="run_id",60        help="The ID is used to avoid conflicts on names or folders. If the log or "61        "name has a chance to conflict in a global storage, use an unique ID to avoid "62        "it.",63    )64def parse_args() -> Namespace:65    """This wraps Python's 'ArgumentParser' to setup our CLI."""66    parser = ArgumentParser(prog="lisa")67    support_debug(parser)68    support_runbook(parser, required=False)69    support_variable(parser)70    support_log_path(parser)71    support_working_path(parser)72    support_id(parser)73    # Default to ârunâ when no subcommand is given.74    parser.set_defaults(func=commands.run)75    subparsers = parser.add_subparsers(dest="cmd", required=False)76    # Entry point for ârunâ.77    run_parser = subparsers.add_parser("run")78    run_parser.set_defaults(func=commands.run)79    # Entry point for âlist-startâ.80    list_parser = subparsers.add_parser(constants.LIST)81    list_parser.set_defaults(func=commands.list_start)82    list_parser.add_argument(83        "--type",84        "-t",85        dest="type",86        choices=["case"],87        help="specify the information type",88    )89    list_parser.add_argument(90        "--all",91        "-a",92        dest="list_all",93        action="store_true",94        help="ignore test case selection, and display all test cases",95    )96    # Entry point for âcheckâ.97    check_parser = subparsers.add_parser("check")98    check_parser.set_defaults(func=commands.check)99    for sub_parser in subparsers.choices.values():100        support_runbook(sub_parser)101        support_variable(sub_parser)102        support_debug(sub_parser)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
