Best Python code snippet using tempest_python
iags.py
Source:iags.py  
1#! /usr/bin/env python2# -*- coding:utf8 -*-3#4# one_inclusion.py5#6# This file is part of pyplanes, a software distributed under the MIT license.7# For any question, please contact one of the authors cited below.8#9# Copyright (c) 202010# 	Olivier Dazel <olivier.dazel@univ-lemans.fr>11# 	Mathieu Gaborit <gaborit@kth.se>12# 	Peter Göransson <pege@kth.se>13#14# Permission is hereby granted, free of charge, to any person obtaining a copy15# of this software and associated documentation files (the "Software"), to deal16# in the Software without restriction, including without limitation the rights17# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell18# copies of the Software, and to permit persons to whom the Software is19# furnished to do so, subject to the following conditions:20#21# The above copyright notice and this permission notice shall be included in all22# copies or substantial portions of the Software.23#24from pyPLANES.gmsh.write_geo_file import Gmsh as Gmsh25from pyPLANES.gmsh.tools.write_geo_file import Gmsh as Gmsh26def find_points(string):27    _ind = string.find("+")28    x = string[:_ind]29    # print(x)30    string = string[_ind+1:]31    # print(string)32    ind_L = string.find("L")33    ind_C = string.find("C")34    ind_plus = string.find("+")35    # print(ind_L)36    # print(ind_C)37    # print(ind_plus)38    if (ind_L!=-1) or (ind_C!=-1) or (ind_plus!=-1):39        if ind_plus == -1: ind_plus = len(string)40        if ind_L == -1: ind_L = len(string)41        if ind_C == -1: ind_C = len(string)42        _ind = min([ind_L, ind_C, ind_plus]) 43        # print("_ind={}".format(_ind))44        y = string[:_ind]45        # print(y)46        string = string[_ind:]47        if string[0] == "+" : string = string[1:]48        # print(string)49    else:50        y = string51        string = ""52    # print(y)53    # print("x=" + x +"; y="+y)54    return (float(x),-float(y),string)55def import_line_loop(_p, G, lcar):56    G.list_lines = []57    x, y, _p = find_points(_p)58    p = G.new_point(x, y, lcar)59    while len(_p) >0:60        if _p[0] == "L":61            _p = _p[1:]62            x, y, _p = find_points(_p)63            if _p != "":64                G.new_point(x, y, lcar)65                G.new_line(G.list_points[-2], G.list_points[-1])66            else: 67                G.new_line(G.list_points[-1], p)68        elif _p[0] == "C":69            _p = _p[1:]70            # print(_p)71            x, y, _p = find_points(_p)72            G.new_point(x, y, lcar)73            x, y, _p = find_points(_p)74            G.new_point(x, y, lcar)75            x, y, _p = find_points(_p)76            if _p != "":77                G.new_point(x, y, lcar)78                G.new_bezier(G.list_points[-4], G.list_points[-3], G.list_points[-2], G.list_points[-1])79            else: 80                G.new_bezier(G.list_points[-3], G.list_points[-2], G.list_points[-1], p)81        else:82            raise NameError("First caracter is neither L nor C")83    ll = G.new_line_loop(G.list_lines)84    return ll85def import_surface(_p, G, _list, lcar):86    ll = import_line_loop(_p, G, lcar)87    _list.append(G.new_surface([ll.tag]))88    return ll 89def import_double_surface(_p_1, _p_2, G, _list_air, _list_porous, lcar):90    ll_interior = import_line_loop(_p_1, G, lcar)91    _list_air.append(G.new_surface([ll_interior.tag]))92    ll = import_line_loop(_p_2, G, lcar)93    _list_porous.append(G.new_surface([ll.tag, -ll_interior.tag]))94    return ll 95def iags( **kwargs):96    name_mesh = kwargs.get("name_mesh", "iags-2021")97    lcar = kwargs.get("lcar", 100)98    BC = kwargs.get("BC", ["Incident_PW", "Periodicity", "Rigid Wall", "Periodicity"])99    permeable_letters = kwargs.get("permeable_letters", False)100    # permeable_letters = True101    G = Gmsh(name_mesh)102    L = 840.103    d = 350.104    list_interfaces = []105    svg_file = open("Logo_Iags_Blanc_Od.svg", "r")106    paths = svg_file.readlines()107    paths =paths[0].split("ZM")108    paths_iterator = iter(paths)109    list_air = []110    list_tower = []111    list_letter = []112    list_rigid = []113    # Upper tower114    import_surface(next(paths_iterator), G, list_tower, lcar/10)115    # Lower tower116    import_surface(next(paths_iterator), G, list_tower, lcar/10)117    # Blason118    list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar/30))119    # Vertical Wall 120    list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar/30))121    # L 122    list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar))123    # e 124    list_interfaces.append(import_double_surface(next(paths_iterator), next(paths_iterator), G, list_letter, list_rigid, lcar))125    # M 126    list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar))    127    # a 128    list_interfaces.append(import_double_surface(next(paths_iterator), next(paths_iterator), G, list_letter, list_rigid, lcar))129    # ns Univ130    for ii in range(7): 131        list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar))  132    # e 133    list_interfaces.append(import_double_surface(next(paths_iterator), next(paths_iterator), G, list_letter, list_rigid, lcar))134    # rsit + accent135    for ii in range(6): 136        list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar))  137    # e 138    list_interfaces.append(import_double_surface(next(paths_iterator), next(paths_iterator), G, list_letter, list_rigid, lcar))139    # Institut 140    for ii in range(9): 141        list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar/10)) 142    # d 143    list_interfaces.append(import_double_surface(next(paths_iterator), next(paths_iterator), G, list_letter, list_rigid, lcar/10))144    # Apostrophe145    list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar))146    # A147    list_interfaces.append(import_double_surface(next(paths_iterator), next(paths_iterator), G, list_letter, list_rigid, lcar/10))148    # c149    list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar))150    # o151    list_interfaces.append(import_double_surface(next(paths_iterator), next(paths_iterator), G, list_letter, list_rigid, lcar))152    # usti153    for ii in range(5): 154        list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar/10)) 155    # q156    list_interfaces.append(import_double_surface(next(paths_iterator), next(paths_iterator), G, list_letter, list_rigid, lcar))157    # u158    list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar))159    # e 160    list_interfaces.append(import_double_surface(next(paths_iterator), next(paths_iterator), G, list_letter, list_rigid, lcar))161    # Gr162    for ii in range(2):163        list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar/10)) 164    # ad165    for ii in range(2):166        list_interfaces.append(import_double_surface(next(paths_iterator), next(paths_iterator), G, list_letter, list_rigid, lcar))167    # u 168    list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar/10))169    # a 170    list_interfaces.append(import_double_surface(next(paths_iterator), next(paths_iterator), G, list_letter, list_rigid, lcar))171    # t 172    list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar/10))173    # e174    list_interfaces.append(import_double_surface(next(paths_iterator), next(paths_iterator), G, list_letter, list_rigid, lcar))175    # Sch 176    for ii in range(3):177        list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar/10))178    # oo 179    for ii in range(2):180        list_interfaces.append(import_double_surface(next(paths_iterator), next(paths_iterator), G, list_letter, list_rigid, lcar))     181    # l182    list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar/10))183    # 2184    list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar/10))185    # 0186    list_interfaces.append(import_double_surface(next(paths_iterator), next(paths_iterator), G, list_letter, list_rigid, lcar))  187    # 21188    for ii in range(2):189        list_interfaces.append(import_surface(next(paths_iterator), G, list_rigid,lcar/10))190    list_interfaces = [-ll.tag for ll in list_interfaces]191    p_0 = G.new_point(0, 0, lcar/10)192    p_1 = G.new_point(L, 0,lcar/10)193    p_2 = G.new_point(L, -d, lcar/10)194    p_3 = G.new_point(0, -d, lcar/10)195    lines = [None]*4196    lines[0] = G.new_line(p_0, p_1)197    lines[1] = G.new_line(p_1, p_2)198    lines[2] = G.new_line(p_2, p_3)199    lines[3] = G.new_line(p_3, p_0)200    boundary_domain = G.new_line_loop(lines)201    cavite = G.new_surface([boundary_domain.tag] + list_interfaces)202    list_air.append(cavite)203    G.new_physical(lines, "method=FEM")204    G.new_physical(lines, "typ=1D")205    for bc in set(BC):206        # Determine the lines 207        list_lines = [lines[i] for i, _bc in enumerate(BC) if _bc == bc]208        G.new_physical(list_lines, "condition="+ bc)209    if permeable_letters:210        G.new_physical(list_air + list_letter + list_tower, "method=FEM")211        G.new_physical(list_air + list_letter + list_tower, "typ=2D")212        G.new_physical(list_air, "mat=Air")213        G.new_physical(list_tower, "mat=tower")214        G.new_physical(list_letter, "mat=letter")215    else:216        G.new_physical(list_air + list_letter + list_tower, "typ=2D")217        G.new_physical(list_air + list_tower + list_letter, "method=FEM")218        G.new_physical(list_air+ list_tower + list_letter, "mat=Air")219    option = "-2 -v 0 "...generate_manual_outputs.py
Source:generate_manual_outputs.py  
1# -*- coding: utf-8 -*-2"""Generate markdown file of Output information to be inserted into the manual"""3import sys4import os5sys.path.append(os.path.abspath(os.path.join(__file__, "../../..")))6from collections import OrderedDict7from mycodo.config import INSTALL_DIRECTORY8from mycodo.scripts.generate_doc_output import generate_controller_doc9from mycodo.utils.outputs import parse_output_information10save_path = os.path.join(INSTALL_DIRECTORY, "docs/Supported-Outputs.md")11outputs_info = OrderedDict()12mycodo_info = OrderedDict()13def repeat_to_length(s, wanted):14    return (s * (wanted//len(s) + 1))[:wanted]15if __name__ == "__main__":16    for output_id, output_data in parse_output_information(exclude_custom=True).items():17        name_str = ""18        if 'output_name' in output_data and output_data['output_name']:19            name_str += "{}".format(output_data['output_name'])20        if 'output_manufacturer' in output_data and output_data['output_manufacturer']:21            name_str += ": {}".format(output_data['output_manufacturer'])22        if 'measurements_name' in output_data and output_data['measurements_name']:23            name_str += ": {}".format(output_data['measurements_name'])24        if 'output_library' in output_data and output_data['output_library']:25            name_str += ": {}".format(output_data['output_library'])26        if ('output_manufacturer' in output_data and27                output_data['output_manufacturer'] in ['Linux', 'Mycodo', 'Raspberry Pi', 'System']):28            if name_str in mycodo_info and 'dependencies_module' in mycodo_info[name_str]:29                # Multiple sets of dependencies, append library30                mycodo_info[name_str]['dependencies_module'].append(output_data['dependencies_module'])31            else:32                # Only one set of dependencies33                mycodo_info[name_str] = output_data34                if 'dependencies_module' in output_data:35                    mycodo_info[name_str]['dependencies_module'] = [output_data['dependencies_module']]  # turn into list36        else:37            if name_str in outputs_info and 'dependencies_module' in outputs_info[name_str]:38                # Multiple sets of dependencies, append library39                outputs_info[name_str]['dependencies_module'].append(output_data['dependencies_module'])40            else:41                # Only one set of dependencies42                outputs_info[name_str] = output_data43                if 'dependencies_module' in output_data:44                    outputs_info[name_str]['dependencies_module'] = [output_data['dependencies_module']]  # turn into list45    mycodo_info = dict(OrderedDict(sorted(mycodo_info.items(), key = lambda t: t[0])))46    outputs_info = dict(OrderedDict(sorted(outputs_info.items(), key = lambda t: t[0])))47    list_outputs = [48        (mycodo_info, "Built-In Outputs (System)"),49        (outputs_info, "Built-In Outputs (Devices)")50    ]51    with open(save_path, 'w') as out_file:52        out_file.write("Supported Outputs are listed below.\n\n")53        for each_list in list_outputs:54            out_file.write("## {}\n\n".format(each_list[1]))55            for each_id, each_data in each_list[0].items():56                if 'output_name' in each_data and each_data['output_name']:57                    out_file.write("### {}\n\n".format(each_data['output_name']))58                else:59                    out_file.write("### {}\n\n".format(each_id))60                if 'output_manufacturer' in each_data and each_data['output_manufacturer']:61                    out_file.write("- Manufacturer: {}\n".format(each_data['output_manufacturer']))62                if 'measurements_name' in each_data and each_data['measurements_name']:63                    out_file.write("- Measurements: {}\n".format(each_data['measurements_name']))64                if 'interfaces' in each_data and each_data['interfaces']:65                    list_interfaces = []66                    for each_type in each_data['interfaces']:67                        if each_type == 'I2C':68                            list_interfaces.append("I<sup>2</sup>C")69                        elif each_type == 'MYCODO':70                            list_interfaces.append("Mycodo")71                        elif each_type == '1WIRE':72                            list_interfaces.append("1-Wire")73                        elif each_type == 'HTTP':74                            list_interfaces.append("HTTP")75                        elif each_type == 'FTDI':76                            list_interfaces.append("FTDI")77                        elif each_type == 'UART':78                            list_interfaces.append("UART")79                        elif each_type == 'GPIO':80                            list_interfaces.append("GPIO")81                        elif each_type == 'PYTHON':82                            list_interfaces.append("Python")83                        elif each_type == 'SHELL':84                            list_interfaces.append("Shell")85                        else:86                            list_interfaces.append(each_type)87                    out_file.write("- Interfaces: {}\n".format(", ".join(list_interfaces)))88                if 'output_types' in each_data and each_data['output_types']:89                    list_output_types = []90                    for each_type in each_data['output_types']:91                        if each_type == 'on_off':92                            list_output_types.append("On/Off")93                        elif each_type == 'volume':94                            list_output_types.append("Volume")95                        elif each_type == 'pwm':96                            list_output_types.append("PWM")97                        elif each_type == 'value':98                            list_output_types.append("Value")99                    out_file.write("- Output Types: {}\n".format(", ".join(list_output_types)))100                if 'output_library' in each_data and each_data['output_library']:101                    out_file.write("- Libraries: {}\n".format(each_data['output_library']))...generate_manual_inputs.py
Source:generate_manual_inputs.py  
1# -*- coding: utf-8 -*-2"""Generate markdown file of Input information to be inserted into the manual"""3import os4import sys5sys.path.append(os.path.abspath(os.path.join(__file__, "../../..")))6from collections import OrderedDict7from mycodo.config import INSTALL_DIRECTORY8from mycodo.scripts.generate_doc_output import generate_controller_doc9from mycodo.utils.inputs import parse_input_information10save_path = os.path.join(INSTALL_DIRECTORY, "docs/Supported-Inputs.md")11inputs_info = OrderedDict()12mycodo_info = OrderedDict()13def repeat_to_length(s, wanted):14    return (s * (wanted//len(s) + 1))[:wanted]15if __name__ == "__main__":16    for input_id, input_data in parse_input_information(exclude_custom=True).items():17        name_str = ""18        if 'input_manufacturer' in input_data and input_data['input_manufacturer']:19            name_str += "{}".format(input_data['input_manufacturer'])20        if 'input_name' in input_data and input_data['input_name']:21            name_str += ": {}".format(input_data['input_name'])22        if 'measurements_name' in input_data and input_data['measurements_name']:23            name_str += ": {}".format(input_data['measurements_name'])24        if 'input_library' in input_data and input_data['input_library']:25            name_str += ": {}".format(input_data['input_library'])26        if ('input_manufacturer' in input_data and27                input_data['input_manufacturer'] in ['Linux', 'Mycodo', 'Raspberry Pi', 'System']):28            if name_str in mycodo_info and 'dependencies_module' in mycodo_info[name_str]:29                # Multiple sets of dependencies, append library30                mycodo_info[name_str]['dependencies_module'].append(input_data['dependencies_module'])31            else:32                # Only one set of dependencies33                mycodo_info[name_str] = input_data34                if 'dependencies_module' in input_data:35                    mycodo_info[name_str]['dependencies_module'] = [input_data['dependencies_module']]  # turn into list36        else:37            if name_str in inputs_info and 'dependencies_module' in inputs_info[name_str]:38                # Multiple sets of dependencies, append library39                inputs_info[name_str]['dependencies_module'].append(input_data['dependencies_module'])40            else:41                # Only one set of dependencies42                inputs_info[name_str] = input_data43                if 'dependencies_module' in input_data:44                    inputs_info[name_str]['dependencies_module'] = [input_data['dependencies_module']]  # turn into list45    mycodo_info = dict(OrderedDict(sorted(mycodo_info.items(), key = lambda t: t[0])))46    inputs_info = dict(OrderedDict(sorted(inputs_info.items(), key = lambda t: t[0])))47    list_inputs = [48        (mycodo_info, "Built-In Inputs (System)"),49        (inputs_info, "Built-In Inputs (Devices)")50    ]51    with open(save_path, 'w') as out_file:52        out_file.write("Supported Inputs are listed below.\n\n")53        for each_list in list_inputs:54            out_file.write("## {}\n\n".format(each_list[1]))55            for each_id, each_data in each_list[0].items():56                name_str = ""57                if 'input_manufacturer' in each_data and each_data['input_manufacturer']:58                    name_str += "{}".format(each_data['input_manufacturer'])59                if 'input_name' in each_data and each_data['input_name']:60                    name_str += ": {}".format(each_data['input_name'])61                out_file.write("### {}\n\n".format(name_str))62                if 'input_manufacturer' in each_data and each_data['input_manufacturer']:63                    out_file.write("- Manufacturer: {}\n".format(each_data['input_manufacturer']))64                if 'measurements_name' in each_data and each_data['measurements_name']:65                    out_file.write("- Measurements: {}\n".format(each_data['measurements_name']))66                if 'interfaces' in each_data and each_data['interfaces']:67                    list_interfaces = []68                    for each_type in each_data['interfaces']:69                        if each_type == 'I2C':70                            list_interfaces.append("I<sup>2</sup>C")71                        elif each_type == 'MYCODO':72                            list_interfaces.append("Mycodo")73                        elif each_type == '1WIRE':74                            list_interfaces.append("1-Wire")75                        elif each_type == 'HTTP':76                            list_interfaces.append("HTTP")77                        elif each_type == 'FTDI':78                            list_interfaces.append("FTDI")79                        elif each_type == 'UART':80                            list_interfaces.append("UART")81                        elif each_type == 'GPIO':82                            list_interfaces.append("GPIO")83                        elif each_type == 'PYTHON':84                            list_interfaces.append("Python")85                        elif each_type == 'SHELL':86                            list_interfaces.append("Shell")87                        else:88                            list_interfaces.append(each_type)89                    out_file.write("- Interfaces: {}\n".format(", ".join(list_interfaces)))90                if 'input_library' in each_data and each_data['input_library']:91                    out_file.write("- Libraries: {}\n".format(each_data['input_library']))...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!!
