Best Python code snippet using lisa_python
DNA.py
Source:DNA.py  
...52        for i in range(self.num):53            prog = self.program_list[i]54            for row in ccc.execute("SELECT * FROM NODES WHERE ID = " + str(self.genes[i])):55                #print(row)56                if row[2] >= prog.get_ram() and row[3] >= prog.get_cpu() and row[4] == prog.get_cpu_type():57                    #print("prog.get_ram() ,cpu ,prog.get_cpu_type()")58                    # print(prog.get_ram())59                    # print(prog.get_cpu())60                    # print(prog.get_cpu_type())61                    #print("okay")62                    prog.set_node()63                    self.fitness += 164                    fit += 165                    ccc.execute("UPDATE NODES SET RAM = "+str(row[2]-prog.get_ram())+", CPU = "+str(row[3]-prog.get_cpu())+" WHERE ID = "+str(self.genes[i]))66                    # for r in ccc.execute("SELECT * FROM NODES WHERE ID = " + str(self.genes[i])):67                    #     print(r)68        #print(fit)69        # with open('calc_fitness_in_hill.txt', 'a') as out:70        #     out.write(str(self.fitness)+" pow((self.fitness/self.num), 4) :  "+str(pow((self.fitness/self.num), 4))+ '\n\n' + "#################" + '\n\n')71        self.local_hillclimbing(ccc)72        ccc.close()73        self.final_fitness = pow((self.fitness/self.num), 4)74        #return pow((self.fitness/self.num), 4)75    def local_hillclimbing(self, conn):76        random_num = random.randint(0, math.floor(self.num))77        #print("hereeeeeeeeeee")78        for i in range(random_num, self.num):79            prog = self.program_list[i]80            if prog.get_node() == False:81                count = 082                for row in conn.execute("SELECT * FROM NODES WHERE RAM > " + str(prog.get_ram()) + " AND cpu > " + str(prog.get_cpu()) + " AND CPU_TYPE = " + str(prog.get_cpu_type())):83                    if count == 1:84                        break85                    else:86                        self.genes[i] = row[0]87                        self.program_list[i].set_node()88                        self.fitness += 189                        conn.execute("UPDATE NODES SET RAM = " + str(row[2] - prog.get_ram()) + ", CPU = " + str(row[3] - prog.get_cpu()) + " WHERE ID = " + str(row[0]))90                        count = 191                if count == 0:...test_cpucfg.py
Source:test_cpucfg.py  
...3from bare68k.consts import *4from bare68k.errors import *5def test_cpu_default():6    c = CPUConfig()7    assert c.get_cpu_type() == M68K_CPU_TYPE_680008    assert c.get_cpu_type_str() == "68000"9def test_set_cpu():10    c = CPUConfig()11    c.set_cpu_type(68010)12    assert c.get_cpu_type() == M68K_CPU_TYPE_6801013    assert c.get_addr_bus_width() == 2414    c.set_cpu_type(20)15    assert c.get_cpu_type() == M68K_CPU_TYPE_6802016    assert c.get_addr_bus_width() == 3217    c.set_cpu_type("10")18    assert c.get_cpu_type() == M68K_CPU_TYPE_6801019    assert c.get_addr_bus_width() == 2420    c.set_cpu_type("68020")21    assert c.get_cpu_type() == M68K_CPU_TYPE_6802022    assert c.get_addr_bus_width() == 3223    c.set_cpu_type("EC20")24    assert c.get_cpu_type() == M68K_CPU_TYPE_68EC02025    assert c.get_addr_bus_width() == 3226    with pytest.raises(ConfigError):...computer_data.py
Source:computer_data.py  
2import os3import psutil4import subprocess5import re6def get_cpu_type():7    command = "cat /proc/cpuinfo"8    return subprocess.check_output(command,shell=True).strip()9with open('diag.txt','w') as WF:10    WF.write('Processor:{}\n'.format(platform.processor()))11    cpu_name=get_cpu_type()12    WF.write('Cpu:{}\n'.format(cpu_name))13    WF.write('Cores:{}\n'.format(os.cpu_count()))14    WF.write('Threads:{}\n'.format(psutil.cpu_count()))...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!!
