# Path: ntfy/config.py
# DEFAULT_CONFIG = join_path(user_config_dir('ntfy', 'dschep'), 'ntfy.yml')
# 
# def load_config(config_path=DEFAULT_CONFIG):
#     logger = logging.getLogger(__name__)
# 
#     try:
#         config = safe_load(open(expanduser(config_path)))
#     except IOError as e:
#         if e.errno == errno.ENOENT and config_path == DEFAULT_CONFIG:
#             logger.info('{} not found'.format(config_path))
#             config = default_configuration
#         else:
#             logger.error(
#                 'Failed to open {}'.format(config_path), exc_info=True)
#             exit(1)
#     except ValueError as e:
#         logger.error('Failed to load {}'.format(config_path), exc_info=True)
#         exit(1)
# 
#     if 'backend' in config:
#         logger.warning(
#             "The 'backend' config option is deprecated, use 'backends'")
#         if 'backends' in config:
#             logger.warning("Both 'backend' and 'backends' in config, "
#                            "ignoring 'backend'.")
#         else:
#             config['backends'] = [config['backend']]
# 
#     return config


from errno import ENOENT
from os import environ
from sys import version_info
from unittest import TestCase, main, skipIf
from mock import mock_open, patch
from ntfy.config import DEFAULT_CONFIG, load_config


py = version_info.major
py_ = version_info.major, version_info.minor

mock_open_dne_error = mock_open()
mock_open_dne_error.side_effect = IOError(ENOENT, 'foobar')
mock_open_other_error = mock_open()
mock_open_other_error.side_effect = IOError()

builtin_module = '__builtin__' if py == 2 else 'builtins'


class TestLoadConfig(TestCase):
    @patch(builtin_module + '.open', mock_open_dne_error)
    def test_default_config(self):

# Path: ntfy/config.py
# DEFAULT_CONFIG = join_path(user_config_dir('ntfy', 'dschep'), 'ntfy.yml')
# 
# def load_config(config_path=DEFAULT_CONFIG):
#     logger = logging.getLogger(__name__)
# 
#     try:
#         config = safe_load(open(expanduser(config_path)))
#     except IOError as e:
#         if e.errno == errno.ENOENT and config_path == DEFAULT_CONFIG:
#             logger.info('{} not found'.format(config_path))
#             config = default_configuration
#         else:
#             logger.error(
#                 'Failed to open {}'.format(config_path), exc_info=True)
#             exit(1)
#     except ValueError as e:
#         logger.error('Failed to load {}'.format(config_path), exc_info=True)
#         exit(1)
# 
#     if 'backend' in config:
#         logger.warning(
#             "The 'backend' config option is deprecated, use 'backends'")
#         if 'backends' in config:
#             logger.warning("Both 'backend' and 'backends' in config, "
#                            "ignoring 'backend'.")
#         else:
#             config['backends'] = [config['backend']]
# 
#     return config


# Path: tests/test_config.py
from errno import ENOENT
from os import environ
from sys import version_info
from unittest import TestCase, main, skipIf
from mock import mock_open, patch
from ntfy.config import DEFAULT_CONFIG, load_config



py = version_info.major
py_ = version_info.major, version_info.minor

mock_open_dne_error = mock_open()
mock_open_dne_error.side_effect = IOError(ENOENT, 'foobar')
mock_open_other_error = mock_open()
mock_open_other_error.side_effect = IOError()

builtin_module = '__builtin__' if py == 2 else 'builtins'


class TestLoadConfig(TestCase):
    @patch(builtin_module + '.open', mock_open_dne_error)
    def test_default_config(self):

        config = load_config(DEFAULT_CONFIG)