当前位置: 首页>>代码示例>>Python>>正文


Python pyhocon.ConfigFactory类代码示例

本文整理汇总了Python中pyhocon.ConfigFactory的典型用法代码示例。如果您正苦于以下问题:Python ConfigFactory类的具体用法?Python ConfigFactory怎么用?Python ConfigFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ConfigFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_self_ref_substitution_dict_recurse

 def test_self_ref_substitution_dict_recurse(self):
     with pytest.raises(ConfigSubstitutionException):
         ConfigFactory.parse_string(
             """
             x = ${x}
             """
         )
开发者ID:cnspica,项目名称:pyhocon,代码行数:7,代码来源:test_config_parser.py

示例2: test_substitutions_overwrite

    def test_substitutions_overwrite(self):
        config1 = ConfigFactory.parse_string(
            """
            a = 123
            a = ${?test}
            a = 5
            """
        )

        assert config1["a"] == 5

        config2 = ConfigFactory.parse_string(
            """
            {
              database {
                host = "localhost"
                port = 8000
                url = ${database.host}":"${database.port}
              }

              database {
                host = ${?DB_HOST}
              }

              database {
                host = "other.host.net"
                port = 433
              }
            }
            """
        )

        assert config2["database"]["host"] == "other.host.net"
        assert config2["database"]["port"] == 433
        assert config2["database"]["url"] == "other.host.net:433"
开发者ID:peoplepattern,项目名称:pyhocon,代码行数:35,代码来源:test_config_parser.py

示例3: convert

    def convert(input_file=None, output_file=None, format='json'):
        """Convert to json, properties or yaml

        :param format: json, properties or yaml
        :type format: basestring
        :return: json, properties or yaml string representation
        """

        if input_file is None:
            content = sys.stdin.read()
            config = ConfigFactory.parse_string(content)
        else:
            config = ConfigFactory.parse_file(input_file)

        if format.lower() == 'json':
            res = HOCONConverter.to_json(config)
        elif format.lower() == 'properties':
            res = HOCONConverter.to_properties(config)
        elif format.lower() == 'yaml':
            res = HOCONConverter.to_yaml(config)
        else:
            raise Exception("Format must be 'json', 'properties' or 'yaml'")

        if output_file is None:
            print(res)
        else:
            with open(output_file, "w") as fd:
                fd.write(res)
开发者ID:peoplepattern,项目名称:pyhocon,代码行数:28,代码来源:tool.py

示例4: test_substitution_cycle

 def test_substitution_cycle(self):
     with pytest.raises(ConfigSubstitutionException):
         ConfigFactory.parse_string(
             """
             a = ${b}
             b = ${c}
             c = ${a}
             """)
开发者ID:davechina,项目名称:pyhocon,代码行数:8,代码来源:test_config_parser.py

示例5: test_string_substitutions

    def test_string_substitutions(self):
        config1 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = str
                        e = "str      "
                    }
                }
                d = ${a.b.c}
                f = ${a.b.e}
            }
            """
        )

        assert config1.get("a.b.c") == "str"
        assert config1.get("d") == "str"
        assert config1.get("f") == "str      "

        config2 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = str
                        e = "str      "
                    }
                }
                d = test  ${a.b.c}
                f = test  ${a.b.e}
            }
            """
        )

        assert config2.get("a.b.c") == "str"
        assert config2.get("d") == "test  str"
        assert config2.get("f") == "test  str      "

        config3 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = str
                        e = "str      "
                    }
                }
                d = test  ${a.b.c}  me
                f = test  ${a.b.e}  me
            }
            """
        )

        assert config3.get("a.b.c") == "str"
        assert config3.get("d") == "test  str  me"
        assert config3.get("f") == "test  str        me"
开发者ID:peoplepattern,项目名称:pyhocon,代码行数:57,代码来源:test_config_parser.py

示例6: test_string_substitutions

    def test_string_substitutions(self):
        config1 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = str
                        e = "str      "
                    }
                }
                d = ${a.b.c}
                f = ${a.b.e}
            }
            """
        )

        assert config1.get('a.b.c') == 'str'
        assert config1.get('d') == 'str'
        assert config1.get('f') == 'str      '

        config2 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = str
                        e = "str      "
                    }
                }
                d = test  ${a.b.c}
                f = test  ${a.b.e}
            }
            """
        )

        assert config2.get('a.b.c') == 'str'
        assert config2.get('d') == 'test  str'
        assert config2.get('f') == 'test  str      '

        config3 = ConfigFactory.parse_string(
            u"""
            {
                a: {
                    b: {
                        c = str
                        e = "str      "
                    }
                }
                d = test  ${a.b.c}  me
                f = test  ${a.b.e}  me
            }
            """
        )

        assert config3.get('a.b.c') == 'str'
        assert config3.get('d') == 'test  str  me'
        assert config3.get('f') == 'test  str        me'
开发者ID:davechina,项目名称:pyhocon,代码行数:57,代码来源:test_config_parser.py

示例7: test_invalid_dict

    def test_invalid_dict(self):
        with pytest.raises(ParseSyntaxException):
            ConfigFactory.parse_string(
                """
                a = {
                    f: 5
                    g
                }
                """)

        with pytest.raises(ParseSyntaxException):
            ConfigFactory.parse_string('a = {g}')
开发者ID:davechina,项目名称:pyhocon,代码行数:12,代码来源:test_config_parser.py

示例8: test_fallback_self_ref_substitutions_concat_string

 def test_fallback_self_ref_substitutions_concat_string(self):
     config1 = ConfigFactory.parse_string(
         """
         string = abc
         """
     )
     config2 = ConfigFactory.parse_string(
         """
         string = ${string}def
         """,
         resolve=False
     )
     config2 = config2.with_fallback(config1)
     assert config2.get("string") == 'abcdef'
开发者ID:cnspica,项目名称:pyhocon,代码行数:14,代码来源:test_config_parser.py

示例9: test_fallback_self_ref_substitutions_append_plus_equals

 def test_fallback_self_ref_substitutions_append_plus_equals(self):
     config1 = ConfigFactory.parse_string(
         """
         list = [ 1, 2, 3 ]
         """
     )
     config2 = ConfigFactory.parse_string(
         """
         list += [ 4, 5, 6 ]
         """,
         resolve=False
     )
     config2 = config2.with_fallback(config1)
     assert config2.get("list") == [1, 2, 3, 4, 5, 6]
开发者ID:cnspica,项目名称:pyhocon,代码行数:14,代码来源:test_config_parser.py

示例10: test_fallback_self_ref_substitutions_merge

 def test_fallback_self_ref_substitutions_merge(self):
     config1 = ConfigFactory.parse_string(
         """
         dict = { x: 1 }
         """
     )
     config2 = ConfigFactory.parse_string(
         """
         dict = ${dict} { y: 2 }
         """,
         resolve=False
     )
     config2 = config2.with_fallback(config1)
     assert config2.get("dict") == {'x': 1, 'y': 2}
开发者ID:cnspica,项目名称:pyhocon,代码行数:14,代码来源:test_config_parser.py

示例11: test_non_existent_substitution

    def test_non_existent_substitution(self):
        with pytest.raises(ConfigSubstitutionException):
            ConfigFactory.parse_string(
                """
                    common_modules = ${non_existent}
                """
            )

        with pytest.raises(ConfigSubstitutionException):
            ConfigFactory.parse_string(
                """
                    common_modules = abc ${non_existent}
                """
            )

        with pytest.raises(ConfigSubstitutionException):
            ConfigFactory.parse_string(
                """
                    common_modules = ${non_existent} abc
                """
            )

        with pytest.raises(ConfigSubstitutionException):
            ConfigFactory.parse_string(
                """
                    common_modules = abc ${non_existent} def
                """
            )
开发者ID:davechina,项目名称:pyhocon,代码行数:28,代码来源:test_config_parser.py

示例12: test_bad_concat

 def test_bad_concat(self):
     ConfigFactory.parse_string('a = 45\n')
     with pytest.raises(ConfigWrongTypeException):
         ConfigFactory.parse_string('a = [4] "4"')
     with pytest.raises(ConfigWrongTypeException):
         ConfigFactory.parse_string('a = "4" [5]')
     with pytest.raises(ConfigWrongTypeException):
         ConfigFactory.parse_string('a = {b: 5} "4"')
开发者ID:davechina,项目名称:pyhocon,代码行数:8,代码来源:test_config_parser.py

示例13: test_int_substitutions

    def test_int_substitutions(self):
        config1 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = 5
                    }
                }
                d = ${a.b.c}
            }
            """
        )

        assert config1.get('a.b.c') == 5
        assert config1.get('d') == 5

        config2 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = 5
                    }
                }
                d = test ${a.b.c}
            }
            """
        )

        assert config2.get('a.b.c') == 5
        assert config2.get('d') == 'test 5'

        config3 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = 5
                    }
                }
                d = test ${a.b.c} me
            }
            """
        )

        assert config3.get('a.b.c') == 5
        assert config3.get('d') == 'test 5 me'
开发者ID:davechina,项目名称:pyhocon,代码行数:48,代码来源:test_config_parser.py

示例14: test_parse_null

 def test_parse_null(self):
     config = ConfigFactory.parse_string(
         """
         a = null
         """
     )
     assert config.get('a') is None
开发者ID:davechina,项目名称:pyhocon,代码行数:7,代码来源:test_config_parser.py

示例15: test_parse_with_comments

    def test_parse_with_comments(self):
        config = ConfigFactory.parse_string(
            """
            // comment 1
            # comment 2
            {
                c = test   // comment 0
                g = 6 test   # comment 0
                # comment 3
                a: { # comment 4
                    b: test,                # comment 5
                } # comment 6
                t = [1, # comment 7
                     2, # comment 8
                     3, # comment 9
                ]
            } # comment 10
            // comment 11
            // comment 12
            """
        )

        assert config.get('c') == 'test'
        assert config.get('g') == '6 test'
        assert config.get('a.b') == 'test'
        assert config.get_string('a.b') == 'test'
        assert config.get('t') == [1, 2, 3]
开发者ID:davechina,项目名称:pyhocon,代码行数:27,代码来源:test_config_parser.py


注:本文中的pyhocon.ConfigFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。