Best Python code snippet using yandex-tank
options.py
Source:options.py
...12from syr.lock import locked13log = LogFile()14def goodcrypto_server_url():15 ''' Get the url for the goodcrypto server. '''16 goodcrypto_server_url = get_options().goodcrypto_server_url17 if goodcrypto_server_url and len(goodcrypto_server_url.strip()) > 0:18 goodcrypto_server_url = goodcrypto_server_url.strip()19 if not goodcrypto_server_url.startswith('http'):20 if ':8443' in goodcrypto_server_url:21 goodcrypto_server_url = 'https://{}'.format(goodcrypto_server_url)22 else:23 goodcrypto_server_url = 'http://{}'.format(goodcrypto_server_url)24 if not goodcrypto_server_url.endswith('/'):25 goodcrypto_server_url += '/'26 return goodcrypto_server_url27def set_goodcrypto_server_url(new_goodcrypto_server_url):28 ''' Set the url for the goodcrypto server. '''29 record = get_options()30 record.goodcrypto_server_url = new_goodcrypto_server_url31 save_options(record)32def mail_server_address():33 ''' Get the IP address or domain for the MTA. '''34 mail_server_address = get_options().mail_server_address35 if not mail_server_address:36 mail_server_address = ''37 return mail_server_address38def set_mail_server_address(new_mail_server_address):39 ''' Set the IP address or domain for the MTA. '''40 record = get_options()41 record.mail_server_address = new_mail_server_address42 save_options(record)43def goodcrypto_listen_port():44 '''45 Get the port where the goodcrypto mail server listens for messages FROM the MTA.46 The MTA sends messages TO this port on the goodcrypto mail server.47 '''48 goodcrypto_listen_port = get_options().goodcrypto_listen_port49 if goodcrypto_listen_port is None:50 from goodcrypto.mail.models import Options51 goodcrypto_listen_port = Options.DEFAULT_GOODCRYPTO_LISTEN_PORT52 return goodcrypto_listen_port53def set_goodcrypto_listen_port(new_goodcrypto_listen_port):54 ''' Set the port where the goodcrypto mail server listens for messages FROM the MTA. '''55 record = get_options()56 record.goodcrypto_listen_port = new_goodcrypto_listen_port57 save_options(record)58def mta_listen_port():59 '''60 Get the port where the MTA listens for messages FROM the the goodcrypto mail server.61 The goodcrypto mail server sends "crypted" messages TO this port on the MTA.62 '''63 mta_listen_port = get_options().mta_listen_port64 if mta_listen_port is None:65 from goodcrypto.mail.models import Options66 mta_listen_port = Options.DEFAULT_MTA_LISTEN_PORT67 return mta_listen_port68def set_mta_listen_port(new_mta_listen_port):69 ''' Set the port where the MTA listens for messages FROM the the goodcrypto mail server. '''70 record = get_options()71 record.mta_listen_port = new_mta_listen_port72 save_options(record)73def auto_exchange_keys():74 ''' Get whether to auto exchange keys. '''75 return get_options().auto_exchange76def set_auto_exchange_keys(auto):77 ''' Set the user's preference to exchange keys automatically. '''78 record = get_options()79 record.auto_exchange = auto80 save_options(record)81def create_private_keys():82 ''' Get whether to automatically create private keys. '''83 return get_options().create_private_keys84def set_create_private_keys(auto):85 ''' Set the user's preference to create private keys automatically. '''86 record = get_options()87 record.create_private_keys = auto88 save_options(record)89def clear_sign_email():90 ''' Get whether to clear sign outbound encrypted mail. '''91 return get_options().clear_sign92def set_clear_sign_email(sign):93 ''' Set the user's preference to clear sign encrypted outbound mail. '''94 record = get_options()95 record.clear_sign = sign96 save_options(record)97def clear_sign_policy():98 ''' Get the policy to clear sign a message. '''99 return get_options().clear_sign_policy100def set_clear_sign_policy(policy):101 ''' Set the user's preference to clear sign encrypted outbound mail. '''102 record = get_options()103 record.clear_sign_policy = policy104 save_options(record)105def filter_html():106 ''' Get whether to filter html from inbound email messages. '''107 return get_options().filter_html108def set_filter_html(preference):109 ''' Set the user's preference to filter html in inbound email messages. '''110 record = get_options()111 record.filter_html = preference112 save_options(record)113def encrypt_metadata():114 ''' Get whether to encrypt metadata. '''115 return get_options().encrypt_metadata116def set_encrypt_metadata(encrypt):117 ''' Set the user's preference to encrypt metadata. '''118 record = get_options()119 record.encrypt_metadata = encrypt120 save_options(record)121def bundle_and_pad():122 ''' Get whether to bundle and pad messages. '''123 return get_options().bundle_and_pad124def set_bundle_and_pad(bundle):125 ''' Set the user's preference to bundle and pad messages. '''126 record = get_options()127 record.bundle_and_pad = bundle128 save_options(record)129def bundle_frequency():130 ''' Get how frequently to send bundled messages. '''131 return get_options().bundle_frequency132def set_bundle_frequency(frequency):133 ''' Set the user's preference to send bundled messages. '''134 record = get_options()135 record.bundle_frequency = frequency136 save_options(record)137def bundled_message_max_size():138 ''' Get the max size for bundled messages. '''139 return bundle_message_kb() * 1024140def bundle_message_kb():141 ''' Get the kb for bundled messages. '''142 bundle_message_kb = get_options().bundle_message_kb143 if bundle_message_kb is None:144 bundle_message_kb = 0145 return bundle_message_kb146def set_bundle_message_kb(kb):147 ''' Set the kb for bundled messages. '''148 record = get_options()149 record.bundle_message_kb = kb150 save_options(record)151def login_to_view_fingerprints():152 ''' Get whether to require logging in before viewing fingerprints. '''153 try:154 return get_options().login_to_view_fingerprints155 except:156 return False157def set_login_to_view_fingerprints(require):158 ''' Set the user's preference to require logging in before viewing fingerprints. '''159 record = get_options()160 try:161 record.login_to_view_fingerprints = require162 save_options(record)163 except:164 pass165def login_to_export_keys():166 ''' Get whether to require logging in before exporting keys. '''167 try:168 return get_options().login_to_export_keys169 except:170 return False171def set_login_to_export_keys(require):172 ''' Set the user's preference to require logging in before exporting keys. '''173 record = get_options()174 try:175 record.login_to_export_keys = require176 save_options(record)177 except:178 pass179def require_outbound_encryption():180 ''' Get whether to require all outbound mail is encrypted. '''181 try:182 return get_options().require_outbound_encryption183 except:184 return False185def set_require_outbound_encryption(require):186 ''' Set whether to require all outbound mail is encrypted. '''187 record = get_options()188 try:189 record.require_outbound_encryption = require190 save_options(record)191 except:192 pass193def require_key_verified():194 ''' Get whether to require key verified before using a new key. '''195 try:196 return get_options().require_key_verified197 except:198 return False199def set_require_key_verified(require):200 ''' Set the user's preference to require key verified before using a new key. '''201 record = get_options()202 try:203 record.require_key_verified = require204 save_options(record)205 except:206 pass207def add_dkim_sig():208 ''' Get whether to add the domain's DKIM signature to outbound messages. '''209 try:210 return get_options().add_dkim_sig211 except:212 return False213def set_add_dkim_sig(add):214 ''' Set the user's preference to add the domain's DKIM signature to outbound messages. '''215 record = get_options()216 try:217 record.add_dkim_sig = add218 save_options(record)219 except:220 pass221def verify_dkim_sig():222 ''' Get whether to verify DKIM signatures on inbound messages. '''223 try:224 return get_options().verify_dkim_sig225 except:226 return False227def set_verify_dkim_sig(verify):228 ''' Set the user's preference to verify DKIM signatures on inbound messages. '''229 record = get_options()230 try:231 record.verify_dkim_sig = verify232 save_options(record)233 except:234 pass235def dkim_delivery_policy():236 ''' Get the delivery policy if DKIM verification fails. '''237 try:238 return get_options().dkim_delivery_policy239 except:240 return DEFAULT_DKIM_POLICY241def set_dkim_delivery_policy(policy):242 ''' Set the domain's DKIM signature. '''243 record = get_options()244 try:245 record.dkim_delivery_policy = policy246 save_options(record)247 except:248 pass249def dkim_public_key():250 ''' Get the domain's DKIM signature. '''251 try:252 return get_options().dkim_public_key253 except:254 return False255def set_dkim_public_key(key):256 ''' Set the domain's DKIM signature. '''257 record = get_options()258 try:259 record.dkim_public_key = key260 save_options(record)261 except:262 pass263def use_keyservers():264 ''' Get whether to use keyservers to find keys for contacts. '''265 try:266 return get_options().use_keyservers267 except:268 return False269def set_use_keyservers(use):270 ''' Set whether to use keyservers to find keys for contacts. '''271 record = get_options()272 try:273 record.use_keyservers = use274 save_options(record)275 except:276 pass277def add_long_tags():278 ''' Get whether to add long tags to messages or not. '''279 try:280 return get_options().add_long_tags281 except:282 return True283def set_add_long_tags(add):284 ''' Set whether to add long tags to messages or not. '''285 record = get_options()286 try:287 record.add_long_tags = add288 save_options(record)289 except:290 pass291def debug_logs_enabled():292 ''' Get whether to enable debug logs. '''293 return get_options().debugging_enabled294def set_debug_logs_enabled(enable):295 ''' Set the user's preference to enable debug logs.'''296 record = get_options()297 record.debugging_enabled = enable298 save_options(record)299def bundle_hourly():300 ''' Return the code for bundling and padding messages hourly. '''301 return HOURS_CODE302def bundle_daily():303 ''' Return the code for bundling and padding messages daily. '''304 return DAYS_CODE305def bundle_weekly():306 ''' Return the code for bundling and padding messages weekly. '''307 return WEEKS_CODE308def get_options():309 '''310 Get the mail options.311 >>> get_options() is not None312 True313 '''314 from goodcrypto.mail.models import Options315 try:316 record = get_singleton(Options)317 except Options.DoesNotExist:318 with locked():319 record = Options.objects.create(320 goodcrypto_listen_port=Options.DEFAULT_GOODCRYPTO_LISTEN_PORT,321 mta_listen_port=Options.DEFAULT_MTA_LISTEN_PORT)322 record.save()323 return record324def save_options(record):325 '''326 Save the mail options.327 >>> save_options(get_options())328 '''329 from goodcrypto.mail.models import Options330 save_singleton(Options, record)331def log_message(message):332 '''333 Log a message to the local log.334 >>> import os.path335 >>> from syr.log import BASE_LOG_DIR336 >>> from syr.user import whoami337 >>> log_message('test')338 >>> os.path.exists(os.path.join(BASE_LOG_DIR, whoami(), 'goodcrypto.mail.options.log'))339 True340 '''341 global log...
torus_puzzle.py
Source:torus_puzzle.py
...80 if state[i] == 0:81 j -= 182 return j 83#this method returns an array of the new combo84def get_options(one, two, optionX):85 option = optionX86 temp = option[one]87 option[one] = option[two]88 option[two] = temp 89 return option90#this method is to print all possible successors 91def print_succ(state):92 state1 = copy.deepcopy(state)93 state2 = copy.deepcopy(state)94 state3 = copy.deepcopy(state)95 state4 = copy.deepcopy(state)96 options = [state1, state2, state3, state4]97 goal = [1,2,3,4,5,6,7,8,0]98 empty = 099 for i in state: #this finds the index of the blank 0100 if state[i] == 0:101 empty = i102 #prints all 4 combos for each empty position103 if empty == 0: 104 options[0] = get_options(1,empty, options[0]) #0 is the blank, 1 is to switch with105 options[1] = get_options(2,empty, options[1]) 106 options[2] = get_options(3,empty, options[2])107 options[3] = get_options(6,empty, options[3])108 109 if empty == 1: 110 options[0] = get_options(0,empty, options[0])111 options[1] = get_options(2,empty, options[1]) 112 options[2] = get_options(4,empty, options[2])113 options[3] = get_options(7,empty, options[3])114 if empty == 2:115 options[0] = get_options(0,empty, options[0])116 options[1] = get_options(1,empty, options[1])117 options[2] = get_options(5,empty, options[2])118 options[3] = get_options(8,empty, options[3])119 if empty == 3: 120 options[0] = get_options(0,empty, options[0])121 options[1] = get_options(4,empty, options[1])122 options[2] = get_options(5,empty, options[2])123 options[3] = get_options(6,empty, options[3])124 if empty == 4: 125 options[0] = get_options(1,empty, options[0])126 options[1] = get_options(3,empty, options[1])127 options[2] = get_options(5,empty, options[2])128 options[3] = get_options(7,empty, options[3])129 if empty == 5:130 options[0] = get_options(2,empty, options[0])131 options[1] = get_options(3,empty, options[1])132 options[2] = get_options(4,empty, options[2])133 options[3] = get_options(8,empty, options[3])134 if empty == 6: 135 options[0] = get_options(0,empty, options[0])136 options[1] = get_options(3,empty, options[1])137 options[2] = get_options(7,empty, options[2])138 options[3] = get_options(8,empty, options[3])139 if empty == 7: 140 options[0] = get_options(1,empty, options[0])141 options[1] = get_options(4,empty, options[1])142 options[2] = get_options(6,empty, options[2])143 options[3] = get_options(8,empty, options[3])144 if empty == 8: 145 options[0]= get_options(2,empty, options[0])146 options[1] = get_options(5,empty, options[1])147 options[2] = get_options(6,empty, options[2])148 options[3]= get_options(7,empty, options[3])149 options = sorted(options) # sorts the combos150 151 h = []152 j = 0153 k = 0 154 # this loop gets all of the h values, and adds them to h. 155 for i in range(len(options)): 156 for k in range(len(options[i])): 157 if options[i][k] != goal[k]:158 j += 1159 if options[i][k] == 0:160 j-=1 # because we dont count the blank 0161 h.append(j)162 j = 0163 # this method prints the values 164 for i in range(len(options)): 165 print( str(options[i]) + " h=" + str(h[i]))166 return options167# this method is exactly like print succ, but doesn't print succ. 168def dont_print_succ(state):169 state1 = copy.deepcopy(state) 170 state2 = copy.deepcopy(state)171 state3 = copy.deepcopy(state)172 state4 = copy.deepcopy(state)173 options = [state1, state2, state3, state4]174 goal = [1,2,3,4,5,6,7,8,0]175 empty = 0176 for i in state: #this finds the index of the blank 0177 if state[i] == 0:178 empty = i179 if empty == 0: 180 options[0] = get_options(1,empty, options[0]) #0 is the blank, 1 is to switch with181 options[1] = get_options(2,empty, options[1]) 182 options[2] = get_options(3,empty, options[2])183 options[3] = get_options(6,empty, options[3])184 185 if empty == 1: 186 options[0] = get_options(0,empty, options[0])187 options[1] = get_options(2,empty, options[1]) 188 options[2] = get_options(4,empty, options[2])189 options[3] = get_options(7,empty, options[3])190 if empty == 2:191 options[0] = get_options(0,empty, options[0])192 options[1] = get_options(1,empty, options[1])193 options[2] = get_options(5,empty, options[2])194 options[3] = get_options(8,empty, options[3])195 if empty == 3: 196 options[0] = get_options(0,empty, options[0])197 options[1] = get_options(4,empty, options[1])198 options[2] = get_options(5,empty, options[2])199 options[3] = get_options(6,empty, options[3])200 if empty == 4: 201 options[0] = get_options(1,empty, options[0])202 options[1] = get_options(3,empty, options[1])203 options[2] = get_options(5,empty, options[2])204 options[3] = get_options(7,empty, options[3])205 if empty == 5:206 options[0] = get_options(2,empty, options[0])207 options[1] = get_options(3,empty, options[1])208 options[2] = get_options(4,empty, options[2])209 options[3] = get_options(8,empty, options[3])210 if empty == 6: 211 options[0] = get_options(0,empty, options[0])212 options[1] = get_options(3,empty, options[1])213 options[2] = get_options(7,empty, options[2])214 options[3] = get_options(8,empty, options[3])215 if empty == 7: 216 options[0] = get_options(1,empty, options[0])217 options[1] = get_options(4,empty, options[1])218 options[2] = get_options(6,empty, options[2])219 options[3] = get_options(8,empty, options[3])220 if empty == 8: 221 options[0]= get_options(2,empty, options[0])222 options[1] = get_options(5,empty, options[1])223 options[2] = get_options(6,empty, options[2])224 options[3]= get_options(7,empty, options[3])225 options = sorted(options)226 227 h = []228 j = 0229 k = 0230 for i in range(len(options)): 231 for k in range(len(options[i])): 232 if options[i][k] != goal[k]:233 j += 1234 if options[i][k] == 0:235 j-=1 # because we dont count the blank 0236 h.append(j)237 j = 0238 return options...
test_options.py
Source:test_options.py
1import pytest2import cure3def test_default_options():4 assert cure.get_options() == cure.DEFAULT_OPTIONS5 assert cure.get_options() == [cure.KEYWORD_TRAILING_UNDERSCORES]6 assert cure.get_options(cure.DEFAULT_OPTIONS) == cure.DEFAULT_OPTIONS7def test_options():8 assert cure.get_options(1) == [cure.KEYWORD_TRAILING_UNDERSCORES]9 assert cure.get_options(1, 0, 0, 1) == [cure.KEYWORD_TRAILING_UNDERSCORES]10 assert cure.get_options(KEYWORD_TRAILING_UNDERSCORES=True) == [cure.KEYWORD_TRAILING_UNDERSCORES]11 assert cure.get_options(keyword_trailing_underscores=True) == [cure.KEYWORD_TRAILING_UNDERSCORES]12 assert cure.get_options(["KEYWORD_TRAILING_UNDERSCORES"]) == [cure.KEYWORD_TRAILING_UNDERSCORES]13 assert cure.get_options(["keyword_trailing_underscores"]) == [cure.KEYWORD_TRAILING_UNDERSCORES]14 assert cure.get_options([1]) == [cure.KEYWORD_TRAILING_UNDERSCORES]15 assert cure.get_options([cure.KEYWORD_TRAILING_UNDERSCORES]) == [cure.KEYWORD_TRAILING_UNDERSCORES]16 assert cure.get_options((cure.KEYWORD_TRAILING_UNDERSCORES)) == [cure.KEYWORD_TRAILING_UNDERSCORES]17 assert cure.get_options(cure.KEYWORD_TRAILING_UNDERSCORES) == [cure.KEYWORD_TRAILING_UNDERSCORES]18 assert cure.get_options(cure.KEYWORD_TRAILING_UNDERSCORES, cure.KEYWORD_TRAILING_UNDERSCORES) == [19 cure.KEYWORD_TRAILING_UNDERSCORES20 ]21 assert cure.get_options("KEYWORD_TRAILING_UNDERSCORES", cure.KEYWORD_TRAILING_UNDERSCORES) == [22 cure.KEYWORD_TRAILING_UNDERSCORES23 ]24 assert cure.get_options(cure.KEYWORD_SNAKE_CASE_RECURSIVE, cure.KEYWORD_TRAILING_UNDERSCORES) == [25 cure.KEYWORD_TRAILING_UNDERSCORES,26 cure.KEYWORD_SNAKE_CASE_RECURSIVE,27 ]28 assert cure.get_options(29 cure.KEYWORD_SNAKE_CASE_RECURSIVE30 | cure.KEYWORD_TRAILING_UNDERSCORES31 | cure.KEYWORD_TRAILING_UNDERSCORES32 | cure.KEYWORD_CAMEL_CASE33 ) == [cure.KEYWORD_TRAILING_UNDERSCORES, cure.KEYWORD_SNAKE_CASE_RECURSIVE, cure.KEYWORD_CAMEL_CASE]34 with pytest.raises(TypeError):35 cure.get_options(0)36 with pytest.raises(TypeError):37 cure.get_options(KEYWORD_TRAILING_UNDERSCORES=False)38 with pytest.raises(TypeError):39 cure.get_options(1, 65536)40 with pytest.raises(TypeError):41 cure.get_options(65536)42 with pytest.raises(TypeError):43 cure.get_options([65536])44 with pytest.raises(TypeError):45 cure.get_options([131072])46 with pytest.raises(TypeError):47 cure.get_options(["unknown_option"])48 with pytest.raises(TypeError):49 cure.get_options(unknown_option=True)50 with pytest.raises(TypeError):...
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!!