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


Python ConfigFactory.parse_string方法代码示例

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


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

示例1: test_self_ref_substitution_dict_recurse

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_string [as 别名]
 def test_self_ref_substitution_dict_recurse(self):
     with pytest.raises(ConfigSubstitutionException):
         ConfigFactory.parse_string(
             """
             x = ${x}
             """
         )
开发者ID:cnspica,项目名称:pyhocon,代码行数:9,代码来源:test_config_parser.py

示例2: test_substitutions_overwrite

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_string [as 别名]
    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,代码行数:37,代码来源:test_config_parser.py

示例3: test_substitution_cycle

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_string [as 别名]
 def test_substitution_cycle(self):
     with pytest.raises(ConfigSubstitutionException):
         ConfigFactory.parse_string(
             """
             a = ${b}
             b = ${c}
             c = ${a}
             """)
开发者ID:davechina,项目名称:pyhocon,代码行数:10,代码来源:test_config_parser.py

示例4: test_string_substitutions

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_string [as 别名]
    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,代码行数:59,代码来源:test_config_parser.py

示例5: test_string_substitutions

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_string [as 别名]
    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,代码行数:59,代码来源:test_config_parser.py

示例6: test_invalid_dict

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_string [as 别名]
    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,代码行数:14,代码来源:test_config_parser.py

示例7: test_fallback_self_ref_substitutions_concat_string

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_string [as 别名]
 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,代码行数:16,代码来源:test_config_parser.py

示例8: test_fallback_self_ref_substitutions_append_plus_equals

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_string [as 别名]
 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,代码行数:16,代码来源:test_config_parser.py

示例9: test_non_existent_substitution

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_string [as 别名]
    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,代码行数:30,代码来源:test_config_parser.py

示例10: test_fallback_self_ref_substitutions_merge

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_string [as 别名]
 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,代码行数:16,代码来源:test_config_parser.py

示例11: test_bad_concat

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_string [as 别名]
 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,代码行数:10,代码来源:test_config_parser.py

示例12: test_int_substitutions

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_string [as 别名]
    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,代码行数:50,代码来源:test_config_parser.py

示例13: test_parse_with_comments

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_string [as 别名]
    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,代码行数:29,代码来源:test_config_parser.py

示例14: test_parse_simple_value

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_string [as 别名]
    def test_parse_simple_value(self):
        config = ConfigFactory.parse_string(
            """t = {
                c = 5
                "d" = true
                e.y = {
                    f: 7
                    g: "hey dude!"
                    h: hey man!
                    i = \"\"\"
                        "first line"
                        "second" line
                        \"\"\"
                }
                j = [1, 2, 3]
                u = 192.168.1.3/32
            }
            """
        )

        assert config.get_string('t.c') == '5'
        assert config.get_int('t.c') == 5
        assert config.get('t.e.y.f') == 7
        assert config.get('t.e.y.g') == 'hey dude!'
        assert config.get('t.e.y.h') == 'hey man!'
        assert [l.strip() for l in config.get('t.e.y.i').split('\n')] == ['', '"first line"', '"second" line', '']
        assert config.get_bool('t.d') is True
        assert config.get_int('t.e.y.f') == 7
        assert config.get('t.j') == [1, 2, 3]
        assert config.get('t.u') == '192.168.1.3/32'
开发者ID:davechina,项目名称:pyhocon,代码行数:32,代码来源:test_config_parser.py

示例15: test_self_append_nonexistent_object

# 需要导入模块: from pyhocon import ConfigFactory [as 别名]
# 或者: from pyhocon.ConfigFactory import parse_string [as 别名]
 def test_self_append_nonexistent_object(self):
     config = ConfigFactory.parse_string(
         """
         x += {a: 1}
         """
     )
     assert config.get("x") == {'a': 1}
开发者ID:cnspica,项目名称:pyhocon,代码行数:9,代码来源:test_config_parser.py


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