def test_environment_vars_in_config(self, yaml_config, env_vars, expected_config): setup_yaml_parser() with patch.dict(os.environ, env_vars): results = yaml.safe_load(yaml_config) assert results == expected_config
def test_config(project_root): config_file = os.path.join(project_root, "config.yml") setup_yaml_parser() with open(config_file) as stream: config = yaml.unsafe_load(stream.read()) with nameko.config.patch(config, clear=True): yield
def test_main(mock_os, tmpdir, capsys): config = tmpdir.join('config.yaml') config.write(""" FOO: ${FOO:foobar} BAR: ${BAR} """) parser = setup_parser() setup_yaml_parser() args = parser.parse_args([ 'show-config', '--config', config.strpath, ]) mock_os.environ = {'BAR': '[1,2,3]'} ShowConfig.main(args) out, _ = capsys.readouterr() expected = dedent(""" BAR: - 1 - 2 - 3 FOO: foobar """).strip() assert out.strip() == expected
def test_main(mock_os, tmpdir, capsys): config = tmpdir.join('config.yaml') config.write(""" FOO: ${FOO:foobar} BAR: ${BAR} """) parser = setup_parser() setup_yaml_parser() args = parser.parse_args([ 'show-config', '--config', config.strpath, ]) mock_os.environ = { 'BAR': '[1,2,3]' } ShowConfig.main(args) out, _ = capsys.readouterr() expected = dedent(""" BAR: - 1 - 2 - 3 FOO: foobar """).strip() assert out.strip() == expected
def main(): parser = setup_parser() args = parser.parse_args() setup_yaml_parser() try: run.main(args) except (CommandError, ConfigurationError) as exc: print("Error: {}".format(exc))
def test_detect_nested_env_vars(self, yaml_config, should_match): # pragma: no cover setup_yaml_parser() if should_match: with pytest.raises(ConfigurationError): yaml.safe_load(yaml_config) else: assert yaml.safe_load(yaml_config)
def test_unhandled_recursion(self, yaml_config, env_vars, expected_config): # pragma: no cover setup_yaml_parser() with patch.dict('os.environ'): for key, val in env_vars.items(): os.environ[key] = val results = yaml.load(yaml_config) assert results == expected_config
def test_unhandled_recursion( self, yaml_config, env_vars, expected_config ): # pragma: no cover setup_yaml_parser() with patch.dict('os.environ'): for key, val in env_vars.items(): os.environ[key] = val results = yaml.unsafe_load(yaml_config) assert results == expected_config
def test_environment_vars_in_config(self, yaml_config, env_vars, expected_config): setup_yaml_parser() with patch.dict('os.environ'): for key, val in env_vars.items(): os.environ[key] = val results = yaml.load(yaml_config) assert results == expected_config
def test_environment_vars_recursive_in_config( self, yaml_config, env_vars, expected_config ): # pragma: no cover setup_yaml_parser() with patch.dict('os.environ'): for key, val in env_vars.items(): os.environ[key] = val results = yaml.unsafe_load(yaml_config) assert results == expected_config
def test_environment_vars_in_config( self, yaml_config, env_vars, expected_config ): setup_yaml_parser() with patch.dict('os.environ'): for key, val in env_vars.items(): os.environ[key] = val results = yaml.unsafe_load(yaml_config) assert results == expected_config
def test_environment_vars_recursive_in_config(self, yaml_config, env_vars, expected_config): setup_yaml_parser() with patch.dict(os.environ, env_vars): if has_regex_module: # pragma: no cover results = yaml.safe_load(yaml_config) assert results == expected_config else: # pragma: no cover with pytest.raises(ConfigurationError) as exc: yaml.safe_load(yaml_config) assert "Nested environment variable lookup" in str(exc.value)
def test_cannot_recurse(self): setup_yaml_parser() yaml_config = """ FOO: ${VAR1} BAR: - 1 - 2 - 3 """ with patch.dict(os.environ, {"VAR1": "${VAR1}"}): results = yaml.safe_load(yaml_config) assert results == {'FOO': "${VAR1}", 'BAR': [1, 2, 3]}
def test_cannot_recurse(self): setup_yaml_parser() yaml_config = """ FOO: ${VAR1} BAR: - 1 - 2 - 3 """ with patch.dict('os.environ'): os.environ["VAR1"] = "${VAR1}" results = yaml.load(yaml_config) assert results == {'FOO': "${VAR1}", 'BAR': [1, 2, 3]}
def test_cannot_recurse(self): setup_yaml_parser() yaml_config = """ FOO: ${VAR1} BAR: - 1 - 2 - 3 """ with patch.dict('os.environ'): os.environ["VAR1"] = "${VAR1}" results = yaml.unsafe_load(yaml_config) assert results == {'FOO': "${VAR1}", 'BAR': [1, 2, 3]}
def main(): setup_yaml_parser() with open("/app/config.yaml") as fle: config = yaml.unsafe_load(fle) if len(sys.argv) > 1: config[AMQP_URI_CONFIG_KEY] = sys.argv[1] try: ctx = {} ctx['n'] = make_nameko_helper(config) ctx['maiev'] = ctx['n'].rpc c = get_config() c.IPCompleter.debug = True c.IPCompleter.use_jedi = False start_ipython( [], banner1="maiev shell to %s\nuse maiev.service_name.method(args)" % config[AMQP_URI_CONFIG_KEY], user_ns=ctx, config=c, ) except Exception: traceback.print_exc() print("failed to start shell to %s" % config[AMQP_URI_CONFIG_KEY])
def get_nameko_config(): setup_yaml_parser() config_path: str = f'/app/{PROJECT_NAME}_{APP_NAME}_service.yml' assert os.path.exists(config_path) with open(config_path) as f: return yaml.unsafe_load(f)
def test_config(project_root): config_file = os.path.join(project_root, "config.yml") setup_yaml_parser() with open(config_file) as stream: config = yaml.load(stream.read()) return config