How to use create_config method in avocado

Best Python code snippet using avocado_python

config_test.py

Source:config_test.py Github

copy

Full Screen

...3import os.path as path4import tempfile5import re6import asciinema.config as cfg7def create_config(content=None, env={}):8 dir = tempfile.mkdtemp()9 if content:10 path = dir + '/config'11 with open(path, 'w') as f:12 f.write(content)13 return cfg.Config(dir, env)14def read_install_id(install_id_path):15 with open(install_id_path, 'r') as f:16 return f.read().strip()17def test_upgrade_no_config_file():18 config = create_config()19 config.upgrade()20 install_id = read_install_id(config.install_id_path)21 assert re.match('^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}', install_id)22 assert_equal(install_id, config.install_id)23 assert not path.exists(config.config_file_path)24 # it must not change after another upgrade25 config.upgrade()26 assert_equal(read_install_id(config.install_id_path), install_id)27def test_upgrade_config_file_with_api_token():28 config = create_config("[api]\ntoken = foo-bar-baz")29 config.upgrade()30 assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')31 assert_equal(config.install_id, 'foo-bar-baz')32 assert not path.exists(config.config_file_path)33 config.upgrade()34 assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')35def test_upgrade_config_file_with_api_token_and_more():36 config = create_config("[api]\ntoken = foo-bar-baz\nurl = http://example.com")37 config.upgrade()38 assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')39 assert_equal(config.install_id, 'foo-bar-baz')40 assert_equal(config.api_url, 'http://example.com')41 assert path.exists(config.config_file_path)42 config.upgrade()43 assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')44def test_upgrade_config_file_with_user_token():45 config = create_config("[user]\ntoken = foo-bar-baz")46 config.upgrade()47 assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')48 assert_equal(config.install_id, 'foo-bar-baz')49 assert not path.exists(config.config_file_path)50 config.upgrade()51 assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')52def test_upgrade_config_file_with_user_token_and_more():53 config = create_config("[user]\ntoken = foo-bar-baz\n[api]\nurl = http://example.com")54 config.upgrade()55 assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')56 assert_equal(config.install_id, 'foo-bar-baz')57 assert_equal(config.api_url, 'http://example.com')58 assert path.exists(config.config_file_path)59 config.upgrade()60 assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')61def test_default_api_url():62 config = create_config('')63 assert_equal('https://asciinema.org', config.api_url)64def test_default_record_stdin():65 config = create_config('')66 assert_equal(False, config.record_stdin)67def test_default_record_command():68 config = create_config('')69 assert_equal(None, config.record_command)70def test_default_record_env():71 config = create_config('')72 assert_equal('SHELL,TERM', config.record_env)73def test_default_record_idle_time_limit():74 config = create_config('')75 assert_equal(None, config.record_idle_time_limit)76def test_default_record_yes():77 config = create_config('')78 assert_equal(False, config.record_yes)79def test_default_record_quiet():80 config = create_config('')81 assert_equal(False, config.record_quiet)82def test_default_play_idle_time_limit():83 config = create_config('')84 assert_equal(None, config.play_idle_time_limit)85def test_api_url():86 config = create_config("[api]\nurl = http://the/url")87 assert_equal('http://the/url', config.api_url)88def test_api_url_when_override_set():89 config = create_config("[api]\nurl = http://the/url", {90 'ASCIINEMA_API_URL': 'http://the/url2'})91 assert_equal('http://the/url2', config.api_url)92def test_record_command():93 command = 'bash -l'94 config = create_config("[record]\ncommand = %s" % command)95 assert_equal(command, config.record_command)96def test_record_stdin():97 config = create_config("[record]\nstdin = yes")98 assert_equal(True, config.record_stdin)99def test_record_env():100 config = create_config("[record]\nenv = FOO,BAR")101 assert_equal('FOO,BAR', config.record_env)102def test_record_idle_time_limit():103 config = create_config("[record]\nidle_time_limit = 2.35")104 assert_equal(2.35, config.record_idle_time_limit)105 config = create_config("[record]\nmaxwait = 2.35")106 assert_equal(2.35, config.record_idle_time_limit)107def test_record_yes():108 yes = 'yes'109 config = create_config("[record]\nyes = %s" % yes)110 assert_equal(True, config.record_yes)111def test_record_quiet():112 quiet = 'yes'113 config = create_config("[record]\nquiet = %s" % quiet)114 assert_equal(True, config.record_quiet)115def test_play_idle_time_limit():116 config = create_config("[play]\nidle_time_limit = 2.35")117 assert_equal(2.35, config.play_idle_time_limit)118 config = create_config("[play]\nmaxwait = 2.35")...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...10from src.quantumwalk import QuantumWalk111213# Create config14def create_config(input_n, bn_act):15 node_identifiers = [f"{i},{j}" for i in range(input_n+2) for j in range(input_n+2) if (i+j>=input_n) and not (i==0 and j==input_n+1) and not (i==input_n+1 and j==0) and not (i==input_n+1 and j==input_n+1)]1617 assignments = dict(18 [(f"{i},{input_n+1}->{i},{input_n}", bn_act) for i in range(1, input_n+1)]19 + [(f"{input_n+1},{j}->{input_n},{j}", bn_act) for j in range(1, input_n+1)] 20 + [(f"{i},{j}->{i},{j+1}", [1,0]) for i in range(input_n+2) for j in range(input_n+2) if i+j==input_n and j!=input_n]21 + [(f"{i},{j}->{i+1},{j}", bn_act) for i in range(input_n+2) for j in range(input_n+2) if i+j==input_n and i!=input_n]22 )23 assignments[f"{input_n},{input_n+1}->{input_n},{input_n}"] = [0, 0]2425 config = {26 "node_identifiers": node_identifiers,27 "assignments": assignments28 }29 30 if bn_act==["reflect", "reflect"]:31 config_file_name = f"config({input_n};reflect).json"32 else:33 config_file_name = f"config({input_n};sink).json"3435 with open(f'..\configs\{config_file_name}', 'w') as f:36 json.dump(config, f, ensure_ascii=False, indent=4)3738# create_config(input_n=5, bn_act=["reflect", "reflect"])39# create_config(input_n=5, bn_act=[0,0])40# create_config(input_n=7, bn_act=["reflect", "reflect"])41# create_config(input_n=7, bn_act=[0,0])42# create_config(input_n=9, bn_act=["reflect", "reflect"])43# create_config(input_n=9, bn_act=[0,0])44# create_config(input_n=11, bn_act=["reflect", "reflect"])45# create_config(input_n=11, bn_act=[0,0])46# create_config(input_n=13, bn_act=["reflect", "reflect"])47# create_config(input_n=13, bn_act=[0,0])48# create_config(input_n=15, bn_act=["reflect", "reflect"])49# create_config(input_n=15, bn_act=[0,0])50# create_config(input_n=17, bn_act=["reflect", "reflect"])51# create_config(input_n=17, bn_act=[0,0])52# create_config(input_n=19, bn_act=["reflect", "reflect"])53# create_config(input_n=19, bn_act=[0,0])54create_config(input_n=21, bn_act=["reflect", "reflect"])55# create_config(input_n=21, bn_act=[0,0])565758def get_coin(xjRatio):59 theta = np.arctan(np.sqrt(2)/(xjRatio))60 coin = np.array([[0, 0, 0, np.cos(2*theta), np.sin(2*theta)/np.sqrt(2), np.sin(2*theta)/np.sqrt(2)],61 [0, 0, 0, np.sin(2*theta)/np.sqrt(2), -np.cos(theta)**2, np.sin(theta)**2 ],62 [0, 0, 0, np.sin(2*theta)/np.sqrt(2), np.sin(theta)**2, -np.cos(theta)**2 ],63 [np.cos(2*theta), np.sin(2*theta)/np.sqrt(2), np.sin(2*theta)/np.sqrt(2), 0, 0, 0 ],64 [np.sin(2*theta)/np.sqrt(2), -np.cos(theta)**2, np.sin(theta)**2, 0, 0, 0 ],65 [np.sin(2*theta)/np.sqrt(2), np.sin(theta)**2, -np.cos(theta)**2, 0, 0, 0 ], 66 ])67 return coin6869 ...

Full Screen

Full Screen

docker_controller.py

Source:docker_controller.py Github

copy

Full Screen

1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT license.3import json4from .subprocess import Subprocess5class DockerController:6 """Controller class for docker.7 """8 @staticmethod9 def remove_container(container_name: str) -> None:10 command = f"sudo docker rm -f {container_name}"11 _ = Subprocess.run(command=command)12 @staticmethod13 def stop_container(container_name: str) -> None:14 command = f"sudo docker stop {container_name}"15 _ = Subprocess.run(command=command)16 @staticmethod17 def inspect_container(container_name: str) -> dict:18 command = f"sudo docker inspect {container_name}"19 return_str = Subprocess.run(command=command)20 return json.loads(return_str)[0]21 @staticmethod22 def create_container_with_config(create_config: dict) -> dict:23 start_container_command = (24 "sudo docker run -it -d "25 "--cpus {cpu} "26 "--memory {memory} "27 "--name {container_name} "28 "--network host "29 "--log-driver=fluentd "30 "--log-opt tag={fluentd_tag} "31 "--log-opt fluentd-address={fluentd_address} "32 "{volumes} {environments} {labels} "33 "{image_name} {command}"34 )35 start_container_with_gpu_command = (36 "sudo docker run -it -d "37 "--cpus {cpu} "38 "--memory {memory} "39 "--gpus {gpu} "40 "--name {container_name} "41 "--network host "42 "--log-driver=fluentd "43 "--log-opt tag={fluentd_tag} "44 "--log-opt fluentd-address={fluentd_address} "45 "{volumes} {environments} {labels} "46 "{image_name} {command}"47 )48 # Format gpu params49 if "gpu" in create_config:50 start_container_command = start_container_with_gpu_command.format(gpu=create_config["gpu"])51 else:52 start_container_command = start_container_command53 # Format other params54 start_container_command = start_container_command.format(55 # User related.56 cpu=create_config["cpu"],57 memory=create_config["memory"],58 command=create_config["command"],59 image_name=create_config["image_name"],60 volumes=DockerController._build_list_params_str(params=create_config["volumes"], option="-v"),61 # System related.62 container_name=create_config["container_name"],63 fluentd_address=create_config["fluentd_address"],64 fluentd_tag=create_config["fluentd_tag"],65 environments=DockerController._build_dict_params_str(params=create_config["environments"], option="-e"),66 labels=DockerController._build_dict_params_str(params=create_config["labels"], option="-l")67 )68 # Start creating69 _ = Subprocess.run(command=start_container_command)70 # Return inspect info.71 return DockerController.inspect_container(container_name=create_config["container_name"])72 @staticmethod73 def list_container_names() -> list:74 command = "sudo docker ps -a --format \"{{.Names}}\""75 return_str = Subprocess.run(command=command)76 if return_str == "":77 return []78 return return_str.split("\n")79 @staticmethod80 def load_image(image_path: str) -> None:81 command = f"sudo docker load -q -i {image_path}"82 _ = Subprocess.run(command=command)83 # Helper functions.84 @staticmethod85 def _build_list_params_str(params: list, option: str) -> str:86 return_str = ""87 for param in params:88 return_str += f"{option} {param} "89 return return_str.strip()90 @staticmethod91 def _build_dict_params_str(params: dict, option: str) -> str:92 return_str = ""93 for k, v in params.items():94 return_str += f"{option} {k}={v} "...

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