How to use the pyhocon.ConfigFactory.parse_string function in pyhocon

To help you get started, we’ve selected a few pyhocon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chimpler / pyhocon / tests / test_config_parser.py View on Github external
def test_invalid_assignment(self):
        with pytest.raises(ParseSyntaxException):
            ConfigFactory.parse_string('common_modules [perl]')

        with pytest.raises(ParseException):
            ConfigFactory.parse_string('common_modules {} {perl: 1}')

        with pytest.raises(ParseSyntaxException):
            ConfigFactory.parse_string(
                """
                a = {f: 5}
github chimpler / pyhocon / tests / test_config_parser.py View on Github external
def test_quoted_unquoted_strings_with_ws(self):
        config = ConfigFactory.parse_string(
            """
            a = foo  "bar"   dummy
            """)

        assert config == {
            'a': 'foo  bar   dummy'
        }
github chimpler / pyhocon / tests / test_config_parser.py View on Github external
def test_object_field_substitution(self):
        config = ConfigFactory.parse_string(
            """
            A = ${Test}

            Test {
                field1 = 1
                field2 = ${Test.field1}"2"
                field3 = ${Test.field2}"3"
            }
            """
        )

        assert config.get_string("A.field1") == "1"
        assert config.get_string("A.field2") == "12"
        assert config.get_string("A.field3") == "123"
        assert config.get_string("Test.field1") == "1"
        assert config.get_string("Test.field2") == "12"
github chimpler / pyhocon / tests / test_config_parser.py View on Github external
def test_unquoted_strings_with_ws(self):
        config = ConfigFactory.parse_string(
            """
            a = foo  bar
            """)

        assert config == {
            'a': 'foo  bar'
        }
github chimpler / pyhocon / tests / test_config_parser.py View on Github external
def test_list_of_lists_with_merge(self):
        config = ConfigFactory.parse_string(
            """
            b = [5, 6]
            a: [
                ${b} [1, 2]
                [3, 4] ${b}
                [1, 2] ${b} [7, 8]
            ]
            """
        )
        assert config['a'] == [
            [5, 6, 1, 2],
            [3, 4, 5, 6],
            [1, 2, 5, 6, 7, 8]
        ]
github chimpler / pyhocon / tests / test_config_parser.py View on Github external
def test_include_substitution(self):
        with tempfile.NamedTemporaryFile('w') as fdin:
            fdin.write('y = ${x}')
            fdin.flush()

            config = ConfigFactory.parse_string(
                """
                include "{tmp_file}"
                x = 42
                """.format(tmp_file=fdin.name)
            )
            assert config['x'] == 42
            assert config['y'] == 42
github chimpler / pyhocon / tests / test_config_parser.py View on Github external
def test_attr_syntax(self):
        config = ConfigFactory.parse_string(
            """
            a: 1
            b: {
              pb: 5
            }
            """)
        assert 5 == config.b.pb
github chimpler / pyhocon / tests / test_config_parser.py View on Github external
def test_self_ref_child(self):
        config = ConfigFactory.parse_string(
            """
                a.b = 3
                a.b = ${a.b}
                a.b = ${a.b}
                a.c = [1,2]
                a.c = ${a.c}
                a.d = {foo: bar}
                a.d = ${a.d}

            """
        )
        assert config.get("a") == {'b': 3, 'c': [1, 2], 'd': {'foo': 'bar'}}
github chimpler / pyhocon / tests / test_config_parser.py View on Github external
def test_list_of_lists_with_merge(self):
        config = ConfigFactory.parse_string(
            """
            b = [5, 6]
            a: [
                ${b} [1, 2]
                [3, 4] ${b}
                [1, 2] ${b} [7, 8]
            ]
            """
        )
        assert config['a'] == [
            [5, 6, 1, 2],
            [3, 4, 5, 6],
            [1, 2, 5, 6, 7, 8]
        ]
github chimpler / pyhocon / tests / test_config_parser.py View on Github external
def test_comma_to_separate_expr(self):
        config = ConfigFactory.parse_string(
            """
            a=1,
            b="abc",
            c=the man,
            d=woof,
            a-b-c-d=test,
            a b c d=test2,
            "a b c d e"=test3
            """
        )
        assert config.get('a') == 1
        assert config.get('b') == 'abc'
        assert config.get('c') == 'the man'
        assert config.get('d') == 'woof'
        assert config.get('a-b-c-d') == 'test'
        assert config.get('a b c d') == 'test2'