コード例 #1
0
ファイル: test_main.py プロジェクト: trolldbois/nameko
    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
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
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
コード例 #5
0
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))
コード例 #6
0
ファイル: test_main.py プロジェクト: trolldbois/nameko
    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)
コード例 #7
0
    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
コード例 #8
0
ファイル: test_main.py プロジェクト: onefinestay/nameko
    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
コード例 #9
0
ファイル: test_main.py プロジェクト: xlcodeme/nameko
    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
コード例 #10
0
ファイル: test_main.py プロジェクト: zwd1990/nameko
    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
コード例 #11
0
ファイル: test_main.py プロジェクト: onefinestay/nameko
    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
コード例 #12
0
ファイル: test_main.py プロジェクト: trolldbois/nameko
    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)
コード例 #13
0
ファイル: test_main.py プロジェクト: trolldbois/nameko
    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]}
コード例 #14
0
ファイル: test_main.py プロジェクト: zhoudaqing/nameko
    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]}
コード例 #15
0
ファイル: test_main.py プロジェクト: onefinestay/nameko
    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]}
コード例 #16
0
ファイル: nameko_shell.py プロジェクト: Yupeek/maiev
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])
コード例 #17
0
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)
コード例 #18
0
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