How to use _write_to_file method in avocado

Best Python code snippet using avocado_python

Setup.py

Source:Setup.py Github

copy

Full Screen

...171# self.driver.save_screenshot("Step {1} - Tab1_Passender_Tariff {0} - {2}.png".format(test_name,172# self.step,173# step_description))174#175# def _write_to_file(self, _filename: str, object_key: str, append: bool=False, _type: str='variable'):176# from onSeleniumBased.modules.Printing import write_to_file, append_to_file, p_e177# from onSeleniumBased.modules.User import BodyMassIndex, Address, IBAN, CivilServant, HealthQuestions, \178# Occupation, DailySicknessAllowance, AgeContributionRelief, PreviousInsurance179# if object_key not in vars(self.user):180# return181#182# v = vars(self.user)[object_key]183#184# _print_string = None185# if type(v) in [BodyMassIndex,186# Address,187# IBAN,188# CivilServant,189# HealthQuestions,190# Occupation,191# AgeContributionRelief,192# DailySicknessAllowance,193# PreviousInsurance]:194# _print_string = object_key + ':\n' + v.printable195# else:196# _print_string = object_key + '\t=\t' + str(v)197#198# if append:199# append_to_file(_filename=_filename, _print_string=_print_string)200# else:201# write_to_file(_filename=_filename, _print_string=_print_string)202#203# def store_user_data_in_file(self, f: str or None):204# from onSeleniumBased.modules.Printing import append_to_file205#206# if f is None or f == "":207# f = "ENVIRONMENT_" + self.environment + "_USER_" + self.user.forename + "_" + self.user.lastname + ".txt"208# self._write_to_file(_filename=f, append=False, object_key='forename')209# self._write_to_file(_filename=f, append=True, object_key='lastname')210# self._write_to_file(_filename=f, append=True, object_key='title')211# self._write_to_file(_filename=f, append=True, object_key='mobile')212# self._write_to_file(_filename=f, append=True, object_key='email')213# self._write_to_file(_filename=f, append=True, object_key='address')214# self._write_to_file(_filename=f, append=True, object_key='date_of_birth')215# self._write_to_file(_filename=f, append=True, object_key='bmi_parameters')216# self._write_to_file(_filename=f, append=True, object_key='nationality')217# self._write_to_file(_filename=f, append=True, object_key='occupation')218# self._write_to_file(_filename=f, append=True, object_key='iban')219# self._write_to_file(_filename=f, append=True, object_key='direct_debit_authorization')220# self._write_to_file(_filename=f, append=True, object_key='previous_insurance')221# self._write_to_file(_filename=f, append=True, object_key='transfer_value')222# self._write_to_file(_filename=f, append=True, object_key='transfer_value_known')223# self._write_to_file(_filename=f, append=True, object_key='transfer_requested')224# self._write_to_file(_filename=f, append=True, object_key='civil_servant')225# self._write_to_file(_filename=f, append=True, object_key='age_contribution_relief')226# self._write_to_file(_filename=f, append=True, object_key='daily_sickness_allowance')227# self._write_to_file(_filename=f, append=True, object_key='health_questions')228# self._write_to_file(_filename=f, append=True, object_key='insurance_start_date')229# self._write_to_file(_filename=f, append=True, object_key='request_consultation')230# self._write_to_file(_filename=f, append=True, object_key='consultation_requested_date')231# self._write_to_file(_filename=f, append=True, object_key='consultation_appointment')232# self._write_to_file(_filename=f, append=True, object_key='consultation_completed')233# self._write_to_file(_filename=f, append=True, object_key='tariff')234# self._write_to_file(_filename=f, append=True, object_key='cost_participation')235# # self._write_to_file(_filename=f, append=True, object_key='health_box')236# self._write_to_file(_filename=f, append=True, object_key='account_created')237# self._write_to_file(_filename=f, append=True, object_key='last_signup_stage_completed')238# self._write_to_file(_filename=f, append=True, object_key='signup_completed')239# self._write_to_file(_filename=f, append=True, object_key='underwriting_completed')240# self._write_to_file(_filename=f, append=True, object_key='offer_to_be_accepted')241# self._write_to_file(_filename=f, append=True, object_key='offer_accepted')242# self._write_to_file(_filename=f, append=True, object_key='contract_signed')243# self._write_to_file(_filename=f, append=True, object_key='expected_rejection')244# self._write_to_file(_filename=f, append=True, object_key='signup_rejected')245#246# _EXPECTED_ITEMS_LIST = ['forename',247# 'lastname',248# 'title',249# 'mobile',250# 'email',251# 'address',252# 'date_of_birth',253# 'bmi_parameters',254# 'nationality',255# 'iban',256# 'direct_debit_authorization',257# 'previous_insurance',258# 'transfer_value',...

Full Screen

Full Screen

parser.py

Source:parser.py Github

copy

Full Screen

...94 if suite['context'] == "required" and self.met_required:95 raise ParserError('context "required" forbidden when using the '96 "'required' key")97 self.contexts.append(suite['context'])98def _write_to_file(dir, fn, s, utf8=False):99 try:100 enc = 'utf-8' if utf8 else 'ascii'101 with open(os.path.join(dir, fn), 'w', encoding=enc) as f:102 f.write(s)103 except UnicodeEncodeError:104 # this can only happen if trying to encode in ascii105 # a value which contains non-ASCII chars in the YAML106 raise ParserError("non-ASCII characters found in ASCII-only field")107def _flush_host(host, outdir):108 if 'ostree' in host:109 val = host['ostree']110 assert type(val) in [str, dict]111 if type(val) is str:112 assert val == "latest"113 _write_to_file(outdir, "ostree_revision", "")114 else:115 _write_to_file(outdir, "ostree_remote", val.get('remote', ''))116 _write_to_file(outdir, "ostree_branch", val.get('branch', ''))117 _write_to_file(outdir, "ostree_revision", val.get('revision', ''))118 val = host.get("specs", {})119 _write_to_file(outdir, "min_ram", str(val.get("ram", 2048)))120 _write_to_file(outdir, "min_cpus", str(val.get("cpus", 1)))121 _write_to_file(outdir, "min_disk", str(val.get("disk", 20)))122 _write_to_file(outdir, "min_secondary_disk",123 str(val.get("secondary-disk", 0)))124 _write_to_file(outdir, "distro", host['distro'])125def flush_suite(suite, outdir):126 os.makedirs(outdir)127 if 'host' in suite:128 dir = os.path.join(outdir, "host")129 os.mkdir(dir)130 _flush_host(suite['host'], dir)131 _write_to_file(outdir, 'envtype', 'host')132 _write_to_file(outdir, 'controller', 'host')133 if 'container' in suite:134 _write_to_file(outdir, "image", suite['container']['image'])135 _write_to_file(outdir, 'envtype', 'container')136 _write_to_file(outdir, 'controller', 'container')137 if 'cluster' in suite:138 cluster = suite['cluster']139 for i, host in enumerate(cluster['hosts']):140 dir = os.path.join(outdir, "host-%d" % i)141 os.mkdir(dir)142 _flush_host(host, dir)143 _write_to_file(dir, "name", host['name'])144 _write_to_file(outdir, 'nhosts', str(i+1))145 if 'container' in cluster:146 _write_to_file(outdir, "image", cluster['container']['image'])147 _write_to_file(outdir, 'controller', 'container')148 else:149 _write_to_file(outdir, 'controller', 'host')150 _write_to_file(outdir, 'envtype', 'cluster')151 if 'tests' in suite:152 _write_to_file(outdir, "tests", '\n'.join(suite['tests']), utf8=True)153 _write_to_file(outdir, "branches",154 '\n'.join(suite.get('branches', ['master'])))155 timeout = common.str_to_timeout(suite.get('timeout', '2h'))156 _write_to_file(outdir, "timeout", str(timeout))157 _write_to_file(outdir, "context", suite.get('context'))158 if 'extra-repos' in suite:159 repos = ''160 for repo in suite['extra-repos']:161 repos += "[%s]\n" % repo['name']162 for key, val in repo.items():163 repos += "%s=%s\n" % (key, val)164 if repos != "":165 _write_to_file(outdir, "papr-extras.repo", repos)166 if 'packages' in suite:167 packages = []168 for pkg in suite['packages']:169 packages.append(shlex.quote(pkg))170 _write_to_file(outdir, "packages", ' '.join(packages))171 if 'artifacts' in suite:172 _write_to_file(outdir, "artifacts", '\n'.join(suite['artifacts']))173 if 'env' in suite:174 envs = ''175 for k, v in suite['env'].items():176 # NB: the schema already ensures that k is ASCII177 # only, so utf8=True will only affect the value178 envs += 'export %s="%s"\n' % (k, v)179 _write_to_file(outdir, "envs", envs, utf8=True)180 if 'build' in suite:181 v = suite['build']182 if type(v) is bool and v:183 _write_to_file(outdir, "build", '')184 elif type(v) is dict:185 _write_to_file(outdir, "build", '')186 _write_to_file(outdir, "build.config_opts",187 v.get('config-opts', ''))188 _write_to_file(outdir, "build.build_opts",189 v.get('build-opts', ''))190 _write_to_file(outdir, "build.install_opts",...

Full Screen

Full Screen

requests_with_cache.py

Source:requests_with_cache.py Github

copy

Full Screen

...34PERMANENT_CACHE_FNAME = "permanent_cache.txt"5TEMP_CACHE_FNAME = "this_page_cache.txt"67def _write_to_file(cache, fname):8 with open(fname, 'w') as outfile:9 outfile.write(json.dumps(cache, indent=2))1011def _read_from_file(fname):12 try:13 with open(fname, 'r') as infile:14 res = infile.read()15 return json.loads(res)16 except:17 return {}1819def add_to_cache(cache_file, cache_key, cache_value):20 temp_cache = _read_from_file(cache_file)21 temp_cache[cache_key] = cache_value22 _write_to_file(temp_cache, cache_file)2324def clear_cache(cache_file=TEMP_CACHE_FNAME):25 _write_to_file({}, cache_file)2627def make_cache_key(baseurl, params_d, private_keys=["api_key"]):28 """Makes a long string representing the query.29 Alphabetize the keys from the params dictionary so we get the same order each time.30 Omit keys with private info."""31 alphabetized_keys = sorted(params_d.keys())32 res = []33 for k in alphabetized_keys:34 if k not in private_keys:35 res.append("{}-{}".format(k, params_d[k]))36 return baseurl + "_".join(res)3738def get(baseurl, params={}, private_keys_to_ignore=["api_key"], permanent_cache_file=PERMANENT_CACHE_FNAME, temp_cache_file=TEMP_CACHE_FNAME):39 full_url = requests.get(baseurl, params) ...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful