Best Python code snippet using lisa_python
test_jq.py
Source:test_jq.py
...11 yield12 xa.set_backend(backend="memory", path="pytest-")13# é²æ¢peb csv æ°åä½é¿åå¤åå14@pytest.fixture15def reset_table():16 l = ["./peb-SH000807.csv", "./sw-801180.csv", "./teb-SH000300.csv"]17 for f in l:18 shutil.copyfile(f, f + ".backup")19 yield20 for f in l:21 shutil.move(f + ".backup", f)22def test_jq_provider():23 assert xa.show_providers() == ["jq"]24def test_peb_history(csv_cache, reset_table):25 h = xa.PEBHistory("SH000807", end="20200302")26 h.summary()27 h.v() # matplotlib is required for this28 assert round(h.df.iloc[0]["pe"], 2) == 19.6729def test_swpeb_history(csv_cache, reset_table):...
populate_tables.py
Source:populate_tables.py
1import sqlite3, uuid2def reset_table(c, table):3 c.execute('DELETE FROM %s' % table)4def add_race(c, race):5 c.execute('INSERT INTO race(name) VALUES (\'%s\')' % race)6def add_profession(c, profession):7 c.execute('INSERT INTO profession(name) VALUES (\'%s\')' % profession)8def add_biome(c, biome):9 c.execute('INSERT INTO biome(name) VALUES(\'%s\')' % biome)10def add_settlement(c, biome):11 c.execute('INSERT INTO settlement(name) VALUES(\'%s\')' % settlement)12conn = sqlite3.connect('laketown.db')13c = conn.cursor()14reset_table(c, 'race')15reset_table(c, 'profession')16reset_table(c, 'biome')17reset_table(c, 'settlement')18races = ['orc', 'elf', 'human', 'goblin', 'giant', 'troll', 'minotaur', 'dragon', 'beast', 'wyrm', 'dwarf', 'halfling', 'centaur', 'vampire', 'dryad']19for race in races:20 add_race(c, race)21professions = ['warrior', 'mage', 'rogue', 'archer', 'paladin', 'priest', 'necromancer', 'dragon_rider', 'dragon_hunter', 'summoner', 'trader', 'hunter', 'guard', 'worker']22for profession in professions:23 add_profession(c, profession)24biomes = ['desert', 'forest', 'plains', 'marsh', 'tundra', 'mountains', 'plains', 'glacier', 'jungle', 'volcano', 'ocean', 'coast']25for biome in biomes:26 add_biome(c, biome)27settlements = ['village', 'trading_post', 'castle', 'mine', 'hideout', 'camp', 'logging_camp', 'hunting_camp', 'temple', 'city', 'town']28for settlement in settlements:29 add_settlement(c, settlement)30conn.commit()31conn.close()
KMP.py
Source:KMP.py
1def KMP_preprocess(pattern):2 m = len(pattern)3 reset_table = [0]*(m+1)4 reset_table[0] = -15 i = 06 j = -17 while i<m:8 while j>-1 and pattern[i] != pattern[j]: j = reset_table[j]9 i += 110 j += 111 reset_table[i] = j12 return reset_table13def KMP(pattern,target,table):14 res = []15 m = len(pattern)16 n = len(target)17 i = 018 j = 019 while i<n:20 while j>-1 and target[i] != pattern[j]: j = table[j]21 i += 122 j += 123 if j==m:24 res.append(i-m)25 j = table[j]26 return res27def main():28 p = "ABABA"29 t = "ACABAABABDABABABABBABABA"30 table = KMP_preprocess(p)31 print("Reset table for {}:".format(p))32 print(table)33 res = KMP(p,t,table)34 print("{} is matched in {} at: ".format(p,t))35 print(res)36if __name__ == '__main__':...
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!!