How to use the pyhocon.exceptions.ConfigWrongTypeException 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_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"')
github chimpler / pyhocon / tests / test_config_parser.py View on Github external
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"')
github chimpler / pyhocon / tests / test_config_parser.py View on Github external
us {
        name = "first domain"
    }
}
www.example-ö.com {
    us {
        name = "second domain"
    }
}
        """

        config = ConfigFactory.parse_string(input_string)

        assert config.get_string(u'www.sample.com.us.name') == 'first domain'
        assert config.get_string(u'www.example-ö.com.us.name') == 'second domain'
        with pytest.raises(ConfigWrongTypeException):
            config.put(u'www.example-ö', 'append_failure', append=True)
        with pytest.raises(ConfigMissingException):
            config.get_string(u'missing_unicode_key_ö')
        with pytest.raises(ConfigException):
            config.get_bool(u'www.example-ö.com.us.name')
        with pytest.raises(ConfigException):
            config.get_list(u'www.example-ö.com.us.name')
        with pytest.raises(ConfigException):
            config.get_config(u'www.example-ö.com.us.name')
        with pytest.raises(ConfigWrongTypeException):
            config.get_string(u'www.example-ö.com.us.name.missing')
github chimpler / pyhocon / tests / test_config_tree.py View on Github external
def test_config_tree_quoted_string(self):
        config_tree = ConfigTree()
        config_tree.put("a.b.c", "value")
        assert config_tree.get("a.b.c") == "value"

        with pytest.raises(ConfigMissingException):
            assert config_tree.get("a.b.d")

        with pytest.raises(ConfigMissingException):
            config_tree.get("a.d.e")

        with pytest.raises(ConfigWrongTypeException):
            config_tree.get("a.b.c.e")
github chimpler / pyhocon / tests / test_config_parser.py View on Github external
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"')
github chimpler / pyhocon / pyhocon / config_tree.py View on Github external
self[key_elt] = value
                elif isinstance(l_value, list) and isinstance(value, ConfigValues):
                    self._push_history(key_elt, value)
                    value.overriden_value = l_value
                    value.parent = self
                    value.key = key_elt
                    self[key_elt] = value
                elif isinstance(l_value, list):
                    self[key_elt] = l_value + value
                    self._push_history(key_elt, l_value)
                elif l_value is None:
                    self._push_history(key_elt, value)
                    self[key_elt] = value

                else:
                    raise ConfigWrongTypeException(
                        u"Cannot concatenate the list {key}: {value} to {prev_value} of {type}".format(
                            key='.'.join(key_path),
                            value=value,
                            prev_value=l_value,
                            type=l_value.__class__.__name__)
                    )
            else:
                # if there was an override keep overide value
                if isinstance(value, ConfigValues):
                    value.parent = self
                    value.key = key_elt
                    value.overriden_value = self.get(key_elt, None)
                self._push_history(key_elt, value)
                self[key_elt] = value
        else:
            next_config_tree = super(ConfigTree, self).get(key_elt)
github chimpler / pyhocon / pyhocon / config_tree.py View on Github external
raise ConfigMissingException(u"No configuration setting found for key {key}".format(key='.'.join(key_path[:key_index + 1])))
            else:
                return default

        if key_index == len(key_path) - 1:
            if isinstance(elt, NoneValue):
                return None
            elif isinstance(elt, list):
                return [None if isinstance(x, NoneValue) else x for x in elt]
            else:
                return elt
        elif isinstance(elt, ConfigTree):
            return elt._get(key_path, key_index + 1, default)
        else:
            if default is UndefinedKey:
                raise ConfigWrongTypeException(
                    u"{key} has type {type} rather than dict".format(key='.'.join(key_path[:key_index + 1]),
                                                                     type=type(elt).__name__))
            else:
                return default
github chimpler / pyhocon / pyhocon / config_tree.py View on Github external
if self.has_substitution():
            return self

        # remove None tokens
        tokens = [token for token in self.tokens if token is not None]

        if not tokens:
            return None

        # check if all tokens are compatible
        first_tok_type = determine_type(tokens[0])
        for index, token in enumerate(tokens[1:]):
            tok_type = determine_type(token)
            if first_tok_type is not tok_type:
                raise ConfigWrongTypeException(
                    "Token '{token}' of type {tok_type} (index {index}) must be of type {req_tok_type} (line: {line}, col: {col})".format(
                        token=token,
                        index=index + 1,
                        tok_type=tok_type.__name__,
                        req_tok_type=first_tok_type.__name__,
                        line=lineno(self._loc, self._instring),
                        col=col(self._loc, self._instring)))

        if first_tok_type is ConfigTree:
            child = []
            if hasattr(self, 'overriden_value'):
                node = self.overriden_value
                while node:
                    if isinstance(node, ConfigValues):
                        value = node.transform()
                        if isinstance(value, ConfigTree):