# Path: sprinter/core/globals.py
# def create_default_config():
#     """ Create a default configuration object, with all parameters filled """
#     config = configparser.RawConfigParser()
#     config.add_section('global')
#     config.set('global', 'env_source_rc', False)
#     config.add_section('shell')
#     config.set('shell', 'bash', "true")
#     config.set('shell', 'zsh', "true")
#     config.set('shell', 'gui', "true")
#     return config
# 
# def _configure_shell(config):
#     """ Checks and queries values for the shell """
#     config.has_section('shell') or config.add_section('shell')
#     logger.info(
#         "What shells or environments would you like sprinter to work with?\n"
#         "(Sprinter will not try to inject into environments not specified here.)\n"
#         "If you specify 'gui', sprinter will attempt to inject it's state into graphical programs as well.\n"
#         "i.e. environment variables sprinter set will affect programs as well, not just shells\n"
#         "WARNING: injecting into the GUI can be very dangerous. it usually requires a restart\n"
#         " to modify any environmental configuration."
#     )
#     environments = list(enumerate(sorted(SHELL_CONFIG), start=1))
#     logger.info("[0]: All, " + ", ".join(["[%d]: %s" % (index, val) for index, val in environments]))
#     desired_environments = lib.prompt("type the environment, comma-separated", default="0")
#     for index, val in environments:
#         if str(index) in desired_environments or "0" in desired_environments:
#             config.set('shell', val, 'true')
#         else:
#             config.set('shell', val, 'false')


from mock import patch
from sprinter.core.globals import create_default_config, _configure_shell


class TestGlobalConfig(object):
    """ Tests for the global logic """

    def setup(self):
        self.config = create_default_config()

    def test_global_config_prompt(self):
        """ _configure_shell with 0 should turn all shells on """
        self.config.remove_section('shell')
        with patch('sprinter.lib.prompt') as prompt:
            prompt.return_value = "0"
            _configure_shell(self.config)
            for k, v in self.config.items('shell'):
                assert v == 'true'

    def test_global_config_prompt_special_configs(self):
        """ If no global config exists, it should prompt for the values it needs, and create a file """
        self.config.remove_section('shell')
        with patch('sprinter.lib.prompt') as prompt:
            prompt.return_value = "2,3"

# Path: sprinter/core/globals.py
# def create_default_config():
#     """ Create a default configuration object, with all parameters filled """
#     config = configparser.RawConfigParser()
#     config.add_section('global')
#     config.set('global', 'env_source_rc', False)
#     config.add_section('shell')
#     config.set('shell', 'bash', "true")
#     config.set('shell', 'zsh', "true")
#     config.set('shell', 'gui', "true")
#     return config
# 
# def _configure_shell(config):
#     """ Checks and queries values for the shell """
#     config.has_section('shell') or config.add_section('shell')
#     logger.info(
#         "What shells or environments would you like sprinter to work with?\n"
#         "(Sprinter will not try to inject into environments not specified here.)\n"
#         "If you specify 'gui', sprinter will attempt to inject it's state into graphical programs as well.\n"
#         "i.e. environment variables sprinter set will affect programs as well, not just shells\n"
#         "WARNING: injecting into the GUI can be very dangerous. it usually requires a restart\n"
#         " to modify any environmental configuration."
#     )
#     environments = list(enumerate(sorted(SHELL_CONFIG), start=1))
#     logger.info("[0]: All, " + ", ".join(["[%d]: %s" % (index, val) for index, val in environments]))
#     desired_environments = lib.prompt("type the environment, comma-separated", default="0")
#     for index, val in environments:
#         if str(index) in desired_environments or "0" in desired_environments:
#             config.set('shell', val, 'true')
#         else:
#             config.set('shell', val, 'false')


# Path: sprinter/core/tests/test_globals.py
from mock import patch
from sprinter.core.globals import create_default_config, _configure_shell



class TestGlobalConfig(object):
    """ Tests for the global logic """

    def setup(self):
        self.config = create_default_config()

    def test_global_config_prompt(self):
        """ _configure_shell with 0 should turn all shells on """
        self.config.remove_section('shell')
        with patch('sprinter.lib.prompt') as prompt:
            prompt.return_value = "0"
            _configure_shell(self.config)
            for k, v in self.config.items('shell'):
                assert v == 'true'

    def test_global_config_prompt_special_configs(self):
        """ If no global config exists, it should prompt for the values it needs, and create a file """
        self.config.remove_section('shell')
        with patch('sprinter.lib.prompt') as prompt:
            prompt.return_value = "2,3"

            _configure_shell(self.config)