How to use as_yaml method in prospector

Best Python code snippet using prospector_python

config.py

Source:config.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from __future__ import absolute_import, division, print_function, unicode_literals3__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'4__copyright__ = "Copyright (C) 2015 The OctoPrint Project - Released under terms of the AGPLv3 License"5import click6click.disable_unicode_literals_warning = True7import logging8from octoprint import init_settings, FatalStartupError9from octoprint.cli import standard_options, bulk_options, get_ctx_obj_option10import yaml11import json12import pprint13def _to_settings_path(path):14 if not isinstance(path, (list, tuple)):15 path = list(filter(lambda x: x, map(lambda x: x.strip(), path.split("."))))16 return path17def _set_helper(settings, path, value, data_type=None):18 path = _to_settings_path(path)19 method = settings.set20 if data_type is not None:21 name = None22 if data_type == bool:23 name = "setBoolean"24 elif data_type == float:25 name = "setFloat"26 elif data_type == int:27 name = "setInt"28 if name is not None:29 method = getattr(settings, name)30 method(path, value)31 settings.save()32#~~ "octoprint config" commands33@click.group()34def config_commands():35 pass36@config_commands.group(name="config")37@click.pass_context38def config(ctx):39 """Basic config manipulation."""40 logging.basicConfig(level=logging.DEBUG if get_ctx_obj_option(ctx, "verbosity", 0) > 0 else logging.WARN)41 try:42 ctx.obj.settings = init_settings(get_ctx_obj_option(ctx, "basedir", None), get_ctx_obj_option(ctx, "configfile", None))43 except FatalStartupError as e:44 click.echo(e.message, err=True)45 click.echo("There was a fatal error initializing the settings manager.", err=True)46 ctx.exit(-1)47@config.command(name="set")48@standard_options(hidden=True)49@click.argument("path", type=click.STRING)50@click.argument("value", type=click.STRING)51@click.option("--bool", "as_bool", is_flag=True,52 help="Interpret value as bool")53@click.option("--float", "as_float", is_flag=True,54 help="Interpret value as float")55@click.option("--int", "as_int", is_flag=True,56 help="Interpret value as int")57@click.option("--json", "as_json", is_flag=True,58 help="Parse value from json")59@click.pass_context60def set_command(ctx, path, value, as_bool, as_float, as_int, as_json):61 """Sets a config path to the provided value."""62 if as_json:63 try:64 value = json.loads(value)65 except Exception as e:66 click.echo(e.message, err=True)67 ctx.exit(-1)68 data_type = None69 if as_bool:70 data_type = bool71 elif as_float:72 data_type = float73 elif as_int:74 data_type = int75 _set_helper(ctx.obj.settings, path, value, data_type=data_type)76@config.command(name="remove")77@standard_options(hidden=True)78@click.argument("path", type=click.STRING)79@click.pass_context80def remove_command(ctx, path):81 """Removes a config path."""82 _set_helper(ctx.obj.settings, path, None)83@config.command(name="append_value")84@standard_options(hidden=True)85@click.argument("path", type=click.STRING)86@click.argument("value", type=click.STRING)87@click.option("--json", "as_json", is_flag=True)88@click.pass_context89def append_value_command(ctx, path, value, as_json=False):90 """Appends value to list behind config path."""91 path = _to_settings_path(path)92 if as_json:93 try:94 value = json.loads(value)95 except Exception as e:96 click.echo(e.message, err=True)97 ctx.exit(-1)98 current = ctx.obj.settings.get(path)99 if current is None:100 current = []101 if not isinstance(current, list):102 click.echo("Cannot append to non-list value at given path", err=True)103 ctx.exit(-1)104 current.append(value)105 _set_helper(ctx.obj.settings, path, current)106@config.command(name="insert_value")107@standard_options(hidden=True)108@click.argument("path", type=click.STRING)109@click.argument("index", type=click.INT)110@click.argument("value", type=click.STRING)111@click.option("--json", "as_json", is_flag=True)112@click.pass_context113def insert_value_command(ctx, path, index, value, as_json=False):114 """Inserts value at index of list behind config key."""115 path = _to_settings_path(path)116 if as_json:117 try:118 value = json.loads(value)119 except Exception as e:120 click.echo(e.message, err=True)121 ctx.exit(-1)122 current = ctx.obj.settings.get(path)123 if current is None:124 current = []125 if not isinstance(current, list):126 click.echo("Cannot insert into non-list value at given path", err=True)127 ctx.exit(-1)128 current.insert(index, value)129 _set_helper(ctx.obj.settings, path, current)130@config.command(name="remove_value")131@standard_options(hidden=True)132@click.argument("path", type=click.STRING)133@click.argument("value", type=click.STRING)134@click.option("--json", "as_json", is_flag=True)135@click.pass_context136def remove_value_command(ctx, path, value, as_json=False):137 """Removes value from list at config path."""138 path = _to_settings_path(path)139 if as_json:140 try:141 value = json.loads(value)142 except Exception as e:143 click.echo(e.message, err=True)144 ctx.exit(-1)145 current = ctx.obj.settings.get(path)146 if current is None:147 current = []148 if not isinstance(current, list):149 click.echo("Cannot remove value from non-list value at given path", err=True)150 ctx.exit(-1)151 if not value in current:152 click.echo("Value is not contained in list at given path")153 ctx.exit()154 current.remove(value)155 _set_helper(ctx.obj.settings, path, current)156@config.command(name="get")157@click.argument("path", type=click.STRING)158@click.option("--json", "as_json", is_flag=True,159 help="Output value formatted as JSON")160@click.option("--yaml", "as_yaml", is_flag=True,161 help="Output value formatted as YAML")162@click.option("--raw", "as_raw", is_flag=True,163 help="Output value as raw string representation")164@standard_options(hidden=True)165@click.pass_context166def get_command(ctx, path, as_json=False, as_yaml=False, as_raw=False):167 """Retrieves value from config path."""168 path = _to_settings_path(path)169 value = ctx.obj.settings.get(path, merged=True)170 if as_json:171 output = json.dumps(value)172 elif as_yaml:173 output = yaml.safe_dump(value, default_flow_style=False, indent=4, allow_unicode=True)174 elif as_raw:175 output = value176 else:177 output = pprint.pformat(value)178 click.echo(output)179@config.command(name="effective")180@click.option("--json", "as_json", is_flag=True,181 help="Output value formatted as JSON")182@click.option("--yaml", "as_yaml", is_flag=True,183 help="Output value formatted as YAML")184@click.option("--raw", "as_raw", is_flag=True,185 help="Output value as raw string representation")186@standard_options(hidden=True)187@click.pass_context188def effective_command(ctx, as_json=False, as_yaml=False, as_raw=False):189 """Retrieves the full effective config."""190 value = ctx.obj.settings.effective191 if as_json:192 output = json.dumps(value)193 elif as_yaml:194 output = yaml.safe_dump(value, default_flow_style=False, indent=4, allow_unicode=True)195 elif as_raw:196 output = value197 else:198 output = pprint.pformat(value)...

Full Screen

Full Screen

unit_conf.py

Source:unit_conf.py Github

copy

Full Screen

...21 },22 "dbs": ["sofi", "galileo"],23 }24@pytest.fixture25def as_yaml(request):26 config = request.param27 with tempfile.NamedTemporaryFile("w", suffix=".yaml") as f:28 yaml.dump(config, f)29 os.environ["SETTINGS_MODULE"] = f.name30 yield config31def compare_cfg(cfg, data):32 for key, value in data.items():33 if isinstance(value, dict):34 compare_cfg(getattr(cfg, key), value)35 else:36 assert dict(cfg)[key] == value37def bad_config():38 return {"aws": None}39@pytest.mark.parametrize("as_yaml", [good_config()], indirect=["as_yaml"])...

Full Screen

Full Screen

test_definition_forms.py

Source:test_definition_forms.py Github

copy

Full Screen

...6 def test_minimal_definition(self):7 entry = SpecificEntityList("http://loinc.org/", entities={'abc': None, 'def': None})8 vde = ValueSetDefinitionEntry(include=entry)9 defn = ValueSetDefinition(resourceID="SIMPLE", about="http://something.org/smthing", entry=[vde])10 print(as_yaml(defn))11 def test_code_system(self):12 hpo = CodeSystemReference('HPO', 'Human Phenotype Ontology', href='https://hpo.jax.org/app/')13 entry = CompleteCodeSystemReference(hpo)14 vde = ValueSetDefinitionEntry(include=entry)15 defn = ValueSetDefinition('HPO', about="http://ontologies.r.us/valueset/allofHPO", entry=[vde])16 print(as_yaml(defn))17 print(dump(defn))18if __name__ == '__main__':...

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 prospector 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