Best Python code snippet using localstack_python
test_customize_form.py
Source:test_customize_form.py
...29 def get_customize_form(self, doctype=None):30 d = frappe.get_doc("Customize Form")31 if doctype:32 d.doc_type = doctype33 d.run_method("fetch_to_customize")34 return d35 def test_fetch_to_customize(self):36 d = self.get_customize_form()37 self.assertEquals(d.doc_type, None)38 self.assertEquals(len(d.get("fields")), 0)39 d = self.get_customize_form("Event")40 self.assertEquals(d.doc_type, "Event")41 self.assertEquals(len(d.get("fields")), 28)42 d = self.get_customize_form("User")43 self.assertEquals(d.doc_type, "User")44 self.assertEquals(len(d.get("fields")), len(frappe.get_doc("DocType", d.doc_type).fields) + 1)45 self.assertEquals(d.get("fields")[-1].fieldname, "test_custom_field")46 self.assertEquals(d.get("fields", {"fieldname": "location"})[0].in_list_view, 1)47 return d48 def test_save_customization_idx(self):49 d = self.get_customize_form("User")50 original_sequence = [df.fieldname for df in d.get("fields")]51 # move field to last52 location_field = d.get("fields", {"fieldname": "location"})[0]53 d.get("fields").remove(location_field)54 d.append("fields", location_field)55 d.run_method("save_customization")56 frappe.clear_cache(doctype=d.doc_type)57 property_setter_name, _idx = frappe.db.get_value("Property Setter",58 {"doc_type": d.doc_type, "property": "_idx"}, ("name", "value"))59 self.assertTrue(_idx)60 _idx = json.loads(_idx)61 for i, df in enumerate(frappe.get_meta(d.doc_type).get("fields")):62 self.assertEquals(_idx[i], df.fieldname)63 frappe.delete_doc("Property Setter", property_setter_name)64 frappe.clear_cache(doctype=d.doc_type)65 for i, df in enumerate(frappe.get_meta(d.doc_type).get("fields")):66 self.assertEquals(original_sequence[i], df.fieldname)67 def test_save_customization_property(self):68 d = self.get_customize_form("User")69 self.assertEquals(frappe.db.get_value("Property Setter",70 {"doc_type": "User", "property": "allow_copy"}, "value"), None)71 d.allow_copy = 172 d.run_method("save_customization")73 self.assertEquals(frappe.db.get_value("Property Setter",74 {"doc_type": "User", "property": "allow_copy"}, "value"), '1')75 d.allow_copy = 076 d.run_method("save_customization")77 self.assertEquals(frappe.db.get_value("Property Setter",78 {"doc_type": "User", "property": "allow_copy"}, "value"), None)79 def test_save_customization_field_property(self):80 d = self.get_customize_form("User")81 self.assertEquals(frappe.db.get_value("Property Setter",82 {"doc_type": "User", "property": "reqd", "field_name": "location"}, "value"), None)83 location_field = d.get("fields", {"fieldname": "location"})[0]84 location_field.reqd = 185 d.run_method("save_customization")86 self.assertEquals(frappe.db.get_value("Property Setter",87 {"doc_type": "User", "property": "reqd", "field_name": "location"}, "value"), '1')88 location_field = d.get("fields", {"fieldname": "location"})[0]89 location_field.reqd = 090 d.run_method("save_customization")91 self.assertEquals(frappe.db.get_value("Property Setter",92 {"doc_type": "User", "property": "reqd", "field_name": "location"}, "value"), None)93 def test_save_customization_custom_field_property(self):94 d = self.get_customize_form("User")95 self.assertEquals(frappe.db.get_value("Custom Field", "User-test_custom_field", "reqd"), 0)96 custom_field = d.get("fields", {"fieldname": "test_custom_field"})[0]97 custom_field.reqd = 198 d.run_method("save_customization")99 self.assertEquals(frappe.db.get_value("Custom Field", "User-test_custom_field", "reqd"), 1)100 custom_field = d.get("fields", {"is_custom_field": True})[0]101 custom_field.reqd = 0102 d.run_method("save_customization")103 self.assertEquals(frappe.db.get_value("Custom Field", "User-test_custom_field", "reqd"), 0)104 def test_save_customization_new_field(self):105 d = self.get_customize_form("User")106 d.append("fields", {107 "label": "Test Add Custom Field Via Customize Form",108 "fieldtype": "Data",109 "__islocal": 1110 })111 d.run_method("save_customization")112 self.assertEquals(frappe.db.get_value("Custom Field",113 "User-test_add_custom_field_via_customize_form", "fieldtype"), "Data")114 frappe.delete_doc("Custom Field", "User-test_add_custom_field_via_customize_form")115 self.assertEquals(frappe.db.get_value("Custom Field",116 "User-test_add_custom_field_via_customize_form"), None)117 def test_save_customization_remove_field(self):118 d = self.get_customize_form("User")119 custom_field = d.get("fields", {"fieldname": "test_custom_field"})[0]120 d.get("fields").remove(custom_field)121 d.run_method("save_customization")122 self.assertEquals(frappe.db.get_value("Custom Field", custom_field.name), None)123 frappe.local.test_objects["Custom Field"] = []124 make_test_records_for_doctype("Custom Field")125 def test_reset_to_defaults(self):126 d = frappe.get_doc("Customize Form")127 d.doc_type = "User"128 d.run_method('reset_to_defaults')129 self.assertEquals(d.get("fields", {"fieldname": "location"})[0].in_list_view, 0)130 frappe.local.test_objects["Property Setter"] = []131 make_test_records_for_doctype("Property Setter")132 def test_set_allow_on_submit(self):133 d = self.get_customize_form("User")134 d.get("fields", {"fieldname": "first_name"})[0].allow_on_submit = 1135 d.get("fields", {"fieldname": "test_custom_field"})[0].allow_on_submit = 1136 d.run_method("save_customization")137 d = self.get_customize_form("User")138 # don't allow for standard fields139 self.assertEquals(d.get("fields", {"fieldname": "first_name"})[0].allow_on_submit or 0, 0)140 # allow for custom field141 self.assertEquals(d.get("fields", {"fieldname": "test_custom_field"})[0].allow_on_submit, 1)142 def test_title_field_pattern(self):143 d = self.get_customize_form("Web Form")144 df = d.get("fields", {"fieldname": "title"})[0]145 # invalid fieldname146 df.options = """{doc_type} - {introduction_test}"""147 self.assertRaises(InvalidFieldNameError, d.run_method, "save_customization")148 # space in formatter149 df.options = """{doc_type} - {introduction text}"""150 self.assertRaises(InvalidFieldNameError, d.run_method, "save_customization")151 # valid fieldname152 df.options = """{doc_type} - {introduction_text}"""153 d.run_method("save_customization")154 # valid fieldname with escaped curlies155 df.options = """{{ {doc_type} }} - {introduction_text}"""156 d.run_method("save_customization")157 # undo158 df.options = None...
main.py
Source:main.py
...8 'insertion':insertion.insertion_sort,9 'selection':selection.selection_sort,10 'merge': merge.merge_sort11}12def run_method(method:str, array:list)->float:13 print(method,end=' ')14 start = time()15 16 if method == 'quick':17 methods[method](array,0,len(array)-1)18 else: 19 methods[method](array)20 21 end = time() - start22 print(end)23 24 return end25number_pool = range(1000000)26v1 = sample(number_pool,1000)27v2 = sample(number_pool,10000)28v3 = sample(number_pool,100000)29v1_up = sorted(v1.copy())30v2_up = sorted(v2.copy())31v3_up = sorted(v3.copy())32v1_down = sorted(v1.copy(),reverse=True)33v2_down = sorted(v2.copy(),reverse=True)34v3_down = sorted(v3.copy(),reverse=True)35times = {}36times['random'] = {}37times['ascending'] = {}38times['descending'] = {}39# Random array40# For 1.000 elements41print('Running 1.000')42times['random']['bubble'] = [run_method('bubble',v1.copy())]43times['random']['quick'] = [run_method('quick',v1.copy())]44times['random']['insertion'] = [run_method('insertion',v1.copy())]45times['random']['selection'] = [run_method('selection',v1.copy())]46times['random']['merge'] = [run_method('merge',v1.copy())]47# For 10.000 elements48print('Running 10.000')49times['random']['bubble'].append(run_method('bubble',v2.copy()))50times['random']['quick'].append(run_method('quick',v2.copy()))51times['random']['insertion'].append(run_method('insertion',v2.copy()))52times['random']['selection'].append(run_method('selection',v2.copy()))53times['random']['merge'].append(run_method('merge',v2.copy()))54# For 100.000 elements55print('Running 100.000')56times['random']['bubble'].append(run_method('bubble',v3.copy()))57times['random']['quick'].append(run_method('quick',v3.copy()))58times['random']['insertion'].append(run_method('insertion',v3.copy()))59times['random']['selection'].append(run_method('selection',v3.copy()))60times['random']['merge'].append(run_method('merge',v3.copy()))61# Array sorted in ascending order62# For 1.000 elements63print('Running 1.000')64times['ascending']['bubble'] = [run_method('bubble',v1_up.copy())]65times['ascending']['quick'] = [run_method('quick',v1_up.copy())]66times['ascending']['insertion'] = [run_method('insertion',v1_up.copy())]67times['ascending']['selection'] = [run_method('selection',v1_up.copy())]68times['ascending']['merge'] = [run_method('merge',v1_up.copy())]69# For 10.000 elements70print('Running 10.000')71times['ascending']['bubble'].append(run_method('bubble',v2_up.copy()))72times['ascending']['quick'].append(run_method('quick',v2_up.copy()))73times['ascending']['insertion'].append(run_method('insertion',v2_up.copy()))74times['ascending']['selection'].append(run_method('selection',v2_up.copy()))75times['ascending']['merge'].append(run_method('merge',v2_up.copy()))76# For 100.000 elements77print('Running 100.000')78times['ascending']['bubble'].append(run_method('bubble',v3_up.copy()))79times['ascending']['quick'].append(run_method('quick',v3_up.copy()))80times['ascending']['insertion'].append(run_method('insertion',v3_up.copy()))81times['ascending']['selection'].append(run_method('selection',v3_up.copy()))82times['ascending']['merge'].append(run_method('merge',v3_up.copy()))83# Array sorted in descending order84# For 1.000 elements85print('Running 1.000')86times['descending']['bubble'] = [run_method('bubble',v1_down.copy())]87times['descending']['quick'] = [run_method('quick',v1_down.copy())]88times['descending']['insertion'] = [run_method('insertion',v1_down.copy())]89times['descending']['selection'] = [run_method('selection',v1_down.copy())]90times['descending']['merge'] = [run_method('merge',v1_down.copy())]91# For 10.000 elements92print('Running 10.000')93times['descending']['bubble'].append(run_method('bubble',v2_down.copy()))94times['descending']['quick'].append(run_method('quick',v2_down.copy()))95times['descending']['insertion'].append(run_method('insertion',v2_down.copy()))96times['descending']['selection'].append(run_method('selection',v2_down.copy()))97times['descending']['merge'].append(run_method('merge',v2_down.copy()))98# For 100.000 elements99print('Running 100.000')100times['descending']['bubble'].append(run_method('bubble',v3_down.copy()))101times['descending']['quick'].append(run_method('quick',v3_down.copy()))102times['descending']['insertion'].append(run_method('insertion',v3_down.copy()))103times['descending']['selection'].append(run_method('selection',v3_down.copy()))104times['descending']['merge'].append(run_method('merge',v3_down.copy()))105times['arrays'] = {106 'v1':v1,107 'v2':v2,108 'v3':v3109}110with open("times.json","w") as file:...
encrypt_test.py
Source:encrypt_test.py
1from __future__ import absolute_import, division, print_function, \2 with_statement3import sys4import os5sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../'))6from shadowsocks.crypto import rc4_md57from shadowsocks.crypto import openssl8from shadowsocks.crypto import sodium9from shadowsocks.crypto import table10def run(func):11 try:12 func()13 except:14 pass15def run_n(func, name):16 try:17 func(name)18 except:19 pass20def main():21 print("\n""rc4_md5")22 rc4_md5.test()23 print("\n""aes-256-cfb")24 openssl.test_aes_256_cfb()25 print("\n""aes-128-cfb")26 openssl.test_aes_128_cfb()27 print("\n""bf-cfb")28 run(openssl.test_bf_cfb)29 print("\n""camellia-128-cfb")30 run_n(openssl.run_method, "camellia-128-cfb")31 print("\n""cast5-cfb")32 run_n(openssl.run_method, "cast5-cfb")33 print("\n""idea-cfb")34 run_n(openssl.run_method, "idea-cfb")35 print("\n""seed-cfb")36 run_n(openssl.run_method, "seed-cfb")37 print("\n""salsa20")38 run(sodium.test_salsa20)39 print("\n""chacha20")40 run(sodium.test_chacha20)41if __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!!