# Path: magnate/config.py
# STATE_DIR = os.path.expanduser('~/.stellarmagnate')
# USER_DIR = os.path.expanduser('~/.stellarmagnate')
# SYSTEM_CONFIG_FILE = '/etc/stellarmagnate/magnate.cfg'
# USER_CONFIG_FILE = os.path.join(STATE_DIR, 'magnate.cfg')
# LOG_FILE = os.path.join(STATE_DIR, 'magnate.log')
# DEFAULT_CONFIG = """
# # Directory in which the game data lives.  The data is further divided into subdirectories herein:
# # base/   Commodity names and price ranges, ship types, locations, and such.
# # schema/ schema for the data files in base *deprecated*, moving to voluptuous
# # assets/ Images and other binary files
# data_dir: {data_dir}/base
# 
# # Game state dir
# # Saves, logs, and other data that changes during operation are saved as subdirs of this
# state_dir: {state_dir}
# 
# # Name of the User Interface plugin to use
# ui_plugin: urwid
# 
# # Whether to use uvloop instead of the stdlib asyncio event loop
# use_uvloop: False
# 
# # Configuration of logging output.  This is given directly to twiggy.dict_cnfig()
# logging:
#   version: "1.0"
#   outputs:
#     logfile:
#       output: twiggy.outputs.FileOutput
#       args:
#         - {log_file}
#   emitters:
#     all:
#       level: WARNING
#       output_name: logfile
#       filters: []
# """.format(data_dir='/usr/share/stellarmagnate', log_file=LOG_FILE, state_dir=STATE_DIR)
# TESTING_CONFIG = """
# data_dir: {base_dir}
# logging:
#   version: "1.0"
#   outputs:
#     logfile:
#       output: twiggy.outputs.FileOutput
#       args:
#         - {log_file}
#   emitters:
#     all:
#       level: DEBUG
#       output_name: logfile
# """.format(base_dir=os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'data')),
#            log_file=LOG_FILE)
# CONFIG_SCHEMA = Schema({
#     'data_dir': All(str, Length(min=1)),
#     'state_dir': All(str, Length(min=1)),
#     'ui_plugin': All(str, Length(min=1, max=128)),
#     'use_uvloop': bool,
#     # The logging param is passed directly to twiggy.dict_config() which does its own validation
#     'logging': dict,
#     }, required=False)
# def _find_config(conf_files=tuple()):
# def _merge_mapping(merge_to, merge_from, inplace=False):
# def _read_config(paths, testing=False):
# def read_config(conf_files=tuple(), testing=False):
# def write_default_config(filename):
# 
# Path: magnate/errors.py
# class MagnateError(Exception):
# class MagnateConfigError(MagnateError):
# class MagnateSaveError(MagnateError):
# class MagnateNoSaveGame(MagnateSaveError):
# class MagnateInvalidSaveGame(MagnateSaveError):


import os.path
import pytest
import twiggy
from collections.abc import MutableMapping
from magnate import config as c
from magnate import errors
        assert isinstance(cfg['logging'], MutableMapping)
        # Testing that logging is valid twiggy configuration is done in TestTwiggyConfig

    def test_paths_given_some_default_override(self, mocker):
        m = mocker.mock_open(read_data=self.ui_and_data_cfg)
        mocker.patch('builtins.open', m)
        mocker.patch('os.path.isfile', autospec=True, side_effect=lambda path: True)
        cfg = c._read_config(('/fake/path/sm-ui-and-data.cfg',))

        assert self.cfg_keys.symmetric_difference(cfg.keys()) == frozenset()
        assert cfg['data_dir'] == '/dev/zero'
        assert cfg['state_dir'] == os.path.expanduser('~/.stellarmagnate')
        assert cfg['ui_plugin'] == 'the_bestest_widget_set'

    def test_paths_given_all_default_override(self, mocker):
        m = mocker.mock_open(read_data=self.all_cfg)
        mocker.patch('builtins.open', m)
        mocker.patch('os.path.isfile', autospec=True, side_effect=lambda path: True)
        cfg = c._read_config(('/fake/path/sm-all.cfg',))

        assert self.cfg_keys.symmetric_difference(cfg.keys()) == frozenset()
        assert cfg['data_dir'] == '/dev/zero'
        assert cfg['state_dir'] == '/tmp'
        assert cfg['ui_plugin'] == 'the_bestest_widget_set'

    def test_invalid_config(self, mocker):
        m = mocker.mock_open(read_data=self.not_yaml_cfg)
        mocker.patch('builtins.open', m)
        mocker.patch('os.path.isfile', autospec=True, side_effect=lambda path: True)


# Path: magnate/config.py
# STATE_DIR = os.path.expanduser('~/.stellarmagnate')
# USER_DIR = os.path.expanduser('~/.stellarmagnate')
# SYSTEM_CONFIG_FILE = '/etc/stellarmagnate/magnate.cfg'
# USER_CONFIG_FILE = os.path.join(STATE_DIR, 'magnate.cfg')
# LOG_FILE = os.path.join(STATE_DIR, 'magnate.log')
# DEFAULT_CONFIG = """
# # Directory in which the game data lives.  The data is further divided into subdirectories herein:
# # base/   Commodity names and price ranges, ship types, locations, and such.
# # schema/ schema for the data files in base *deprecated*, moving to voluptuous
# # assets/ Images and other binary files
# data_dir: {data_dir}/base
# 
# # Game state dir
# # Saves, logs, and other data that changes during operation are saved as subdirs of this
# state_dir: {state_dir}
# 
# # Name of the User Interface plugin to use
# ui_plugin: urwid
# 
# # Whether to use uvloop instead of the stdlib asyncio event loop
# use_uvloop: False
# 
# # Configuration of logging output.  This is given directly to twiggy.dict_cnfig()
# logging:
#   version: "1.0"
#   outputs:
#     logfile:
#       output: twiggy.outputs.FileOutput
#       args:
#         - {log_file}
#   emitters:
#     all:
#       level: WARNING
#       output_name: logfile
#       filters: []
# """.format(data_dir='/usr/share/stellarmagnate', log_file=LOG_FILE, state_dir=STATE_DIR)
# TESTING_CONFIG = """
# data_dir: {base_dir}
# logging:
#   version: "1.0"
#   outputs:
#     logfile:
#       output: twiggy.outputs.FileOutput
#       args:
#         - {log_file}
#   emitters:
#     all:
#       level: DEBUG
#       output_name: logfile
# """.format(base_dir=os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'data')),
#            log_file=LOG_FILE)
# CONFIG_SCHEMA = Schema({
#     'data_dir': All(str, Length(min=1)),
#     'state_dir': All(str, Length(min=1)),
#     'ui_plugin': All(str, Length(min=1, max=128)),
#     'use_uvloop': bool,
#     # The logging param is passed directly to twiggy.dict_config() which does its own validation
#     'logging': dict,
#     }, required=False)
# def _find_config(conf_files=tuple()):
# def _merge_mapping(merge_to, merge_from, inplace=False):
# def _read_config(paths, testing=False):
# def read_config(conf_files=tuple(), testing=False):
# def write_default_config(filename):
# 
# Path: magnate/errors.py
# class MagnateError(Exception):
# class MagnateConfigError(MagnateError):
# class MagnateSaveError(MagnateError):
# class MagnateNoSaveGame(MagnateSaveError):
# class MagnateInvalidSaveGame(MagnateSaveError):


# Path: tests/units/test_config.py
import os.path
import pytest
import twiggy
from collections.abc import MutableMapping
from magnate import config as c
from magnate import errors

        assert isinstance(cfg['logging'], MutableMapping)
        # Testing that logging is valid twiggy configuration is done in TestTwiggyConfig

    def test_paths_given_some_default_override(self, mocker):
        m = mocker.mock_open(read_data=self.ui_and_data_cfg)
        mocker.patch('builtins.open', m)
        mocker.patch('os.path.isfile', autospec=True, side_effect=lambda path: True)
        cfg = c._read_config(('/fake/path/sm-ui-and-data.cfg',))

        assert self.cfg_keys.symmetric_difference(cfg.keys()) == frozenset()
        assert cfg['data_dir'] == '/dev/zero'
        assert cfg['state_dir'] == os.path.expanduser('~/.stellarmagnate')
        assert cfg['ui_plugin'] == 'the_bestest_widget_set'

    def test_paths_given_all_default_override(self, mocker):
        m = mocker.mock_open(read_data=self.all_cfg)
        mocker.patch('builtins.open', m)
        mocker.patch('os.path.isfile', autospec=True, side_effect=lambda path: True)
        cfg = c._read_config(('/fake/path/sm-all.cfg',))

        assert self.cfg_keys.symmetric_difference(cfg.keys()) == frozenset()
        assert cfg['data_dir'] == '/dev/zero'
        assert cfg['state_dir'] == '/tmp'
        assert cfg['ui_plugin'] == 'the_bestest_widget_set'

    def test_invalid_config(self, mocker):
        m = mocker.mock_open(read_data=self.not_yaml_cfg)
        mocker.patch('builtins.open', m)
        mocker.patch('os.path.isfile', autospec=True, side_effect=lambda path: True)


        with pytest.raises(errors.MagnateConfigError) as e: