# Path: bugwarrior/config/load.py
# BUGWARRIORRC = "BUGWARRIORRC"
# def configure_logging(logfile, loglevel):
# def get_config_path():
# def remove_inactive_flavors(rawconfig, main_section):
# def load_config(main_section, interactive):
#     def __init__(self, *args, allow_no_value=True, **kwargs):
#     def getint(self, section, option):
#     def optionxform(option):
# class BugwarriorConfigParser(configparser.ConfigParser):
# 
# Path: tests/base.py
# class ConfigTest(unittest.TestCase):
#     """
#     Creates config files, configures the environment, and cleans up afterwards.
#     """
#     def setUp(self):
#         self.old_environ = os.environ.copy()
#         self.tempdir = tempfile.mkdtemp(prefix='bugwarrior')
# 
#         # Create temporary config files.
#         self.taskrc = os.path.join(self.tempdir, '.taskrc')
#         self.lists_path = os.path.join(self.tempdir, 'lists')
#         os.mkdir(self.lists_path)
#         with open(self.taskrc, 'w+') as fout:
#             fout.write('data.location=%s\n' % self.lists_path)
# 
#         # Configure environment.
#         os.environ['HOME'] = self.tempdir
#         os.environ.pop(config.BUGWARRIORRC, None)
#         os.environ.pop('TASKRC', None)
#         os.environ.pop('XDG_CONFIG_HOME', None)
#         os.environ.pop('XDG_CONFIG_DIRS', None)
# 
#     def tearDown(self):
#         shutil.rmtree(self.tempdir, ignore_errors=True)
#         os.environ = self.old_environ
# 
#     @pytest.fixture(autouse=True)
#     def inject_fixtures(self, caplog):
#         self.caplog = caplog
# 
#     def validate(self):
#         conf = schema.validate_config(self.config, 'general', 'configpath')
#         conf['general'].data = data.BugwarriorData(self.lists_path)
#         conf['general'].interactive = False
#         return conf
# 
#     def assertValidationError(self, expected):
# 
#         with self.assertRaises(SystemExit):
#             self.validate()
# 
#         # Only one message should be logged.
#         self.assertEqual(len(self.caplog.records), 1)
# 
#         self.assertIn(expected, self.caplog.records[0].message)


import os
from unittest import TestCase
from bugwarrior.config import load
from ..base import ConfigTest
    def create(self, path):
        """
        Create an empty file in the temporary directory, return the full path.
        """
        fpath = os.path.join(self.tempdir, path)
        if not os.path.exists(os.path.dirname(fpath)):
            os.makedirs(os.path.dirname(fpath))
        open(fpath, 'a').close()
        return fpath

    def test_default(self):
        """
        If it exists, use the file at $XDG_CONFIG_HOME/bugwarrior/bugwarriorrc
        """
        rc = self.create('.config/bugwarrior/bugwarriorrc')
        self.assertEqual(load.get_config_path(), rc)

    def test_legacy(self):
        """
        Falls back on .bugwarriorrc if it exists
        """
        rc = self.create('.bugwarriorrc')
        self.assertEqual(load.get_config_path(), rc)

    def test_xdg_first(self):
        """
        If both files above exist, the one in $XDG_CONFIG_HOME takes precedence
        """
        self.create('.bugwarriorrc')
        rc = self.create('.config/bugwarrior/bugwarriorrc')

# Path: bugwarrior/config/load.py
# BUGWARRIORRC = "BUGWARRIORRC"
# def configure_logging(logfile, loglevel):
# def get_config_path():
# def remove_inactive_flavors(rawconfig, main_section):
# def load_config(main_section, interactive):
#     def __init__(self, *args, allow_no_value=True, **kwargs):
#     def getint(self, section, option):
#     def optionxform(option):
# class BugwarriorConfigParser(configparser.ConfigParser):
# 
# Path: tests/base.py
# class ConfigTest(unittest.TestCase):
#     """
#     Creates config files, configures the environment, and cleans up afterwards.
#     """
#     def setUp(self):
#         self.old_environ = os.environ.copy()
#         self.tempdir = tempfile.mkdtemp(prefix='bugwarrior')
# 
#         # Create temporary config files.
#         self.taskrc = os.path.join(self.tempdir, '.taskrc')
#         self.lists_path = os.path.join(self.tempdir, 'lists')
#         os.mkdir(self.lists_path)
#         with open(self.taskrc, 'w+') as fout:
#             fout.write('data.location=%s\n' % self.lists_path)
# 
#         # Configure environment.
#         os.environ['HOME'] = self.tempdir
#         os.environ.pop(config.BUGWARRIORRC, None)
#         os.environ.pop('TASKRC', None)
#         os.environ.pop('XDG_CONFIG_HOME', None)
#         os.environ.pop('XDG_CONFIG_DIRS', None)
# 
#     def tearDown(self):
#         shutil.rmtree(self.tempdir, ignore_errors=True)
#         os.environ = self.old_environ
# 
#     @pytest.fixture(autouse=True)
#     def inject_fixtures(self, caplog):
#         self.caplog = caplog
# 
#     def validate(self):
#         conf = schema.validate_config(self.config, 'general', 'configpath')
#         conf['general'].data = data.BugwarriorData(self.lists_path)
#         conf['general'].interactive = False
#         return conf
# 
#     def assertValidationError(self, expected):
# 
#         with self.assertRaises(SystemExit):
#             self.validate()
# 
#         # Only one message should be logged.
#         self.assertEqual(len(self.caplog.records), 1)
# 
#         self.assertIn(expected, self.caplog.records[0].message)


# Path: tests/config/test_load.py
import os
from unittest import TestCase
from bugwarrior.config import load
from ..base import ConfigTest

    def create(self, path):
        """
        Create an empty file in the temporary directory, return the full path.
        """
        fpath = os.path.join(self.tempdir, path)
        if not os.path.exists(os.path.dirname(fpath)):
            os.makedirs(os.path.dirname(fpath))
        open(fpath, 'a').close()
        return fpath

    def test_default(self):
        """
        If it exists, use the file at $XDG_CONFIG_HOME/bugwarrior/bugwarriorrc
        """
        rc = self.create('.config/bugwarrior/bugwarriorrc')
        self.assertEqual(load.get_config_path(), rc)

    def test_legacy(self):
        """
        Falls back on .bugwarriorrc if it exists
        """
        rc = self.create('.bugwarriorrc')
        self.assertEqual(load.get_config_path(), rc)

    def test_xdg_first(self):
        """
        If both files above exist, the one in $XDG_CONFIG_HOME takes precedence
        """
        self.create('.bugwarriorrc')
        rc = self.create('.config/bugwarrior/bugwarriorrc')

        self.assertEqual(load.get_config_path(), rc)