# Path: boussole/exceptions.py
# class SettingsInvalidError(BoussoleBaseException):
#     """
#     Exception to be raised when a settings is detected as invalid.
#     """
#     pass
# 
# Path: boussole/conf/json_backend.py
# class SettingsBackendJson(SettingsBackendBase):
#     """
#     JSON backend for settings
# 
#     Attributes:
#         _default_filename: Filename for settings file to load.
#             Value is ``settings.json``.
#         _kind_name: Backend format name.
#             Value is ``json``.
#         _file_extension: Default filename extension.
#             Value is ``json``.
#     """
#     _default_filename = "boussole.json"
#     _kind_name = "json"
#     _file_extension = "json"
# 
#     def dump(self, content, filepath, indent=4):
#         """
#         Dump settings content to filepath.
# 
#         Args:
#             content (str): Settings content.
#             filepath (str): Settings file location.
#         """
#         with open(filepath, "w") as fp:
#             json.dump(content, fp, indent=indent)
# 
#     def parse(self, filepath, content):
#         """
#         Parse opened settings content using JSON parser.
# 
#         Args:
#             filepath (str): Settings object, depends from backend
#             content (str): Settings content from opened file, depends from
#                 backend.
# 
#         Raises:
#             boussole.exceptions.SettingsBackendError: If parser can not decode
#                 a valid JSON object.
# 
#         Returns:
#             dict: Dictionnary containing parsed setting elements.
# 
#         """
#         try:
#             parsed = json.loads(content)
#         except ValueError:
#             msg = "No JSON object could be decoded from file: {}"
#             raise SettingsBackendError(msg.format(filepath))
#         return parsed
# 
# Path: boussole/conf/yaml_backend.py
# class SettingsBackendYaml(SettingsBackendBase):
#     """
#     YAML backend for settings
# 
#     Use PyYaml for parsing and pyaml for dumping.
# 
#     Attributes:
#         _default_filename: Filename for settings file to load.
#             Value is ``settings.yml``.
#         _kind_name: Backend format name.
#             Value is ``yaml``.
#         _file_extension: Default filename extension.
#             Value is ``yml``.
#     """
#     _default_filename = "boussole.yml"
#     _kind_name = "yaml"
#     _file_extension = "yml"
# 
#     def dump(self, content, filepath, indent=4):
#         """
#         Dump settings content to filepath.
# 
#         Args:
#             content (str): Settings content.
#             filepath (str): Settings file location.
#         """
#         with open(filepath, "w") as fp:
#             pyaml.dump(content, dst=fp, indent=indent)
# 
#     def parse(self, filepath, content):
#         """
#         Parse opened settings content using YAML parser.
# 
#         Args:
#             filepath (str): Settings object, depends from backend
#             content (str): Settings content from opened file, depends from
#                 backend.
# 
#         Raises:
#             boussole.exceptions.SettingsBackendError: If parser can not decode
#                 a valid YAML object.
# 
#         Returns:
#             dict: Dictionnary containing parsed setting elements.
# 
#         """
#         try:
#             parsed = yaml.load(content, Loader=yaml.FullLoader)
#         except yaml.YAMLError as exc:
#             msg = "No YAML object could be decoded from file: {}\n{}"
#             raise SettingsBackendError(msg.format(filepath, exc))
#         return parsed


import os
import pytest
from boussole.exceptions import SettingsInvalidError
from boussole.conf.json_backend import SettingsBackendJson
from boussole.conf.yaml_backend import SettingsBackendYaml
# -*- coding: utf-8 -*-



@pytest.mark.parametrize("backend_engine", [
    SettingsBackendJson,
    SettingsBackendYaml,
])
def test_basic(settings, custom_project_settings, backend_engine):
    """
    Load basic settings file fail because of wrong paths
    """
    backend = backend_engine(basedir=settings.fixtures_path)

    with pytest.raises(SettingsInvalidError):
        backend.load()


@pytest.mark.parametrize("filename,backend_engine", [
    ("boussole_polluted.json", SettingsBackendJson),
    ("boussole_custom.json", SettingsBackendJson),

# Path: boussole/exceptions.py
# class SettingsInvalidError(BoussoleBaseException):
#     """
#     Exception to be raised when a settings is detected as invalid.
#     """
#     pass
# 
# Path: boussole/conf/json_backend.py
# class SettingsBackendJson(SettingsBackendBase):
#     """
#     JSON backend for settings
# 
#     Attributes:
#         _default_filename: Filename for settings file to load.
#             Value is ``settings.json``.
#         _kind_name: Backend format name.
#             Value is ``json``.
#         _file_extension: Default filename extension.
#             Value is ``json``.
#     """
#     _default_filename = "boussole.json"
#     _kind_name = "json"
#     _file_extension = "json"
# 
#     def dump(self, content, filepath, indent=4):
#         """
#         Dump settings content to filepath.
# 
#         Args:
#             content (str): Settings content.
#             filepath (str): Settings file location.
#         """
#         with open(filepath, "w") as fp:
#             json.dump(content, fp, indent=indent)
# 
#     def parse(self, filepath, content):
#         """
#         Parse opened settings content using JSON parser.
# 
#         Args:
#             filepath (str): Settings object, depends from backend
#             content (str): Settings content from opened file, depends from
#                 backend.
# 
#         Raises:
#             boussole.exceptions.SettingsBackendError: If parser can not decode
#                 a valid JSON object.
# 
#         Returns:
#             dict: Dictionnary containing parsed setting elements.
# 
#         """
#         try:
#             parsed = json.loads(content)
#         except ValueError:
#             msg = "No JSON object could be decoded from file: {}"
#             raise SettingsBackendError(msg.format(filepath))
#         return parsed
# 
# Path: boussole/conf/yaml_backend.py
# class SettingsBackendYaml(SettingsBackendBase):
#     """
#     YAML backend for settings
# 
#     Use PyYaml for parsing and pyaml for dumping.
# 
#     Attributes:
#         _default_filename: Filename for settings file to load.
#             Value is ``settings.yml``.
#         _kind_name: Backend format name.
#             Value is ``yaml``.
#         _file_extension: Default filename extension.
#             Value is ``yml``.
#     """
#     _default_filename = "boussole.yml"
#     _kind_name = "yaml"
#     _file_extension = "yml"
# 
#     def dump(self, content, filepath, indent=4):
#         """
#         Dump settings content to filepath.
# 
#         Args:
#             content (str): Settings content.
#             filepath (str): Settings file location.
#         """
#         with open(filepath, "w") as fp:
#             pyaml.dump(content, dst=fp, indent=indent)
# 
#     def parse(self, filepath, content):
#         """
#         Parse opened settings content using YAML parser.
# 
#         Args:
#             filepath (str): Settings object, depends from backend
#             content (str): Settings content from opened file, depends from
#                 backend.
# 
#         Raises:
#             boussole.exceptions.SettingsBackendError: If parser can not decode
#                 a valid YAML object.
# 
#         Returns:
#             dict: Dictionnary containing parsed setting elements.
# 
#         """
#         try:
#             parsed = yaml.load(content, Loader=yaml.FullLoader)
#         except yaml.YAMLError as exc:
#             msg = "No YAML object could be decoded from file: {}\n{}"
#             raise SettingsBackendError(msg.format(filepath, exc))
#         return parsed


# Path: tests/050_conf/003_common_backends/002_load.py
import os
import pytest
from boussole.exceptions import SettingsInvalidError
from boussole.conf.json_backend import SettingsBackendJson
from boussole.conf.yaml_backend import SettingsBackendYaml

# -*- coding: utf-8 -*-



@pytest.mark.parametrize("backend_engine", [
    SettingsBackendJson,
    SettingsBackendYaml,
])
def test_basic(settings, custom_project_settings, backend_engine):
    """
    Load basic settings file fail because of wrong paths
    """
    backend = backend_engine(basedir=settings.fixtures_path)

    with pytest.raises(SettingsInvalidError):
        backend.load()


@pytest.mark.parametrize("filename,backend_engine", [
    ("boussole_polluted.json", SettingsBackendJson),
    ("boussole_custom.json", SettingsBackendJson),

    ("boussole_polluted.yml", SettingsBackendYaml),