Best Python code snippet using tox_python
_quickstart.py
Source:_quickstart.py
...192 return ["pytest"]193 if "trial" in commands:194 return ["twisted"]195 return []196def post_process_input(map_):197 envlist = [env for env in tox.PYTHON.QUICKSTART_PY_ENVS if map_.get(env) is True]198 map_["envlist"] = ", ".join(envlist)199 map_["commands"] = "\n ".join([cmd.strip() for cmd in map_["commands"]])200 map_["deps"] = "\n ".join([dep.strip() for dep in set(map_["deps"])])201def generate(map_):202 """Generate project based on values in *d*."""203 dpath = map_.get("path", os.getcwd())204 altpath = os.path.join(dpath, ALTERNATIVE_CONFIG_NAME)205 while True:206 name = map_.get("name", tox.INFO.DEFAULT_CONFIG_NAME)207 targetpath = os.path.join(dpath, name)208 if not os.path.isfile(targetpath):209 break210 do_prompt(map_, "name", "{} exists - choose an alternative".format(targetpath), altpath)211 with codecs.open(targetpath, "w", encoding="utf-8") as f:212 f.write(prepare_content(QUICKSTART_CONF.format(**map_)))213 print(214 "Finished: {} has been created. For information on this file, "215 "see https://tox.readthedocs.io/en/latest/config.html\n"216 "Execute `tox` to test your project.".format(targetpath)217 )218def prepare_content(content):219 return "\n".join([line.rstrip() for line in content.split("\n")])220def parse_args():221 parser = argparse.ArgumentParser(222 description="Command-line script to quickly tox config file for a Python project."223 )224 parser.add_argument(225 "root",226 type=str,227 nargs="?",228 default=".",229 help="Custom root directory to write config to. Defaults to current directory.",230 )231 parser.add_argument(232 "--version", action="version", version="%(prog)s {}".format(tox.__version__)233 )234 return parser.parse_args()235def main():236 args = parse_args()237 map_ = {"path": args.root}238 try:239 ask_user(map_)240 except (KeyboardInterrupt, EOFError):241 print("\n[Interrupted.]")242 return 1243 post_process_input(map_)244 generate(map_)245if __name__ == "__main__":...
test_quickstart.py
Source:test_quickstart.py
...96 self.name = name97 exp = exp or self.STANDARD_EPECTATIONS98 # NOTE extra mangling here ensures formatting is the same in file and exp99 map_ = {"deps": list_modificator(exp[1]), "commands": list_modificator(exp[2])}100 post_process_input(map_)101 map_["envlist"] = exp[0]102 self.content = prepare_content(QUICKSTART_CONF.format(**map_))103 def __str__(self):104 return self.name105@pytest.mark.usefixtures("work_in_clean_dir")106@pytest.mark.parametrize(107 argnames="answers, exp, cnf",108 ids=lambda param: str(param),109 argvalues=(110 (111 _answers([4, "Y", "Y", "Y", "Y", "Y", "N", "pytest", "pytest"]),112 _exp(113 "choose versions individually and use pytest",114 [ALL_PY_ENVS_WO_LAST_AS_STRING, "pytest", "pytest"],...
__init__.py
Source:__init__.py
1import os2import json3from kapitan.resources import jinja2_render_file, yaml_load4from kapitan.inputs import kadet5import glob6import yaml7import time8inventory = kadet.inventory()9def set_team_name(obj, team_name):10 obj.root.metadata["labels"]["team_name"] = team_name11 return obj12def set_namespace(obj, namespace):13 obj.root.metadata["namespace"] = namespace14 return obj15def get_root_path(path, target_name):16 drive, tail = os.path.split(path)17 if tail == target_name:18 return drive19 else:20 return get_root_path(drive, target_name)21def get_post_process_input_output_path(post_process_input):22 for i in inventory.parameters.kapitan.compile:23 if i.name == post_process_input:24 return i.output_path25 raise ValueError("'post_process_input' {post_process_input} not found")26def main(input_params):27 team_name = input_params.get("team_name", "no-owner")28 if "namespace" in input_params:29 namespace = input_params.get("namespace")30 else:31 raise ValueError("'namespace' key not found in 'input_params'")32 if "post_process_inputs" in input_params:33 post_process_inputs = input_params.get("post_process_inputs")34 else:35 raise ValueError("'post_process_inputs' key not found in 'input_params'")36 # get path where files have been compiled on this run37 target_name = inventory.parameters.kapitan.vars.target38 compile_path = input_params.get("compile_path")39 root_path = get_root_path(compile_path, target_name)40 all_objects = {}41 for post_process_input in post_process_inputs:42 output = kadet.BaseObj()43 p = get_post_process_input_output_path(post_process_input)44 dir_file_path = os.path.join(root_path, target_name, p)45 for file in glob.glob(dir_file_path + "/*.yaml", recursive=True):46 # remove file extension47 file_name = os.path.basename(file).replace(".yaml", "")48 with open(file) as fp:49 yaml_stream = yaml.safe_load_all(fp)50 objects_for_file = []51 for obj in yaml_stream:52 o = kadet.BaseObj.from_dict(obj)53 o = set_team_name(o, team_name)54 o = set_namespace(o, namespace)55 objects_for_file.append(o)56 all_objects.update({file_name: objects_for_file})57 fp.close()58 output = kadet.BaseObj()59 for file_name, obj in all_objects.items():60 output.root[file_name] = obj...
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!!