# Path: rebasehelper/cli.py
# class CLI:
#     """ Class for processing data from commandline """
# 
#     @staticmethod
#     def build_parser(available_choices_only=False):
#         parser = CustomArgumentParser(description=PROGRAM_DESCRIPTION,
#                                       formatter_class=CustomHelpFormatter)
# 
#         group = None
#         current_group = 0
#         for option in traverse_options(OPTIONS + plugin_manager.get_options()):
#             available_choices = option.pop("available_choices", option.get("choices"))
#             if available_choices_only:
#                 option["choices"] = available_choices
# 
#             option_kwargs = dict(option)
#             for key in ("group", "default", "name"):
#                 if key in option_kwargs:
#                     del option_kwargs[key]
# 
#             if "group" in option:
#                 if not group or current_group != option["group"]:
#                     current_group = option["group"]
#                     group = parser.add_mutually_exclusive_group()
#                 actions_container = group
#             else:
#                 actions_container = parser
# 
#             # default is set to SUPPRESS to prevent arguments which were not specified on command line from being
#             # added to namespace. This allows rebase-helper to determine which arguments are used with their
#             # default value. This is later used for merging CLI arguments with config.
#             actions_container.add_argument(*option["name"], action=CustomAction, default=argparse.SUPPRESS,
#                                            actual_default=option.get("default"), **option_kwargs)
# 
#         return parser
# 
#     def __init__(self, args=None):
#         """parse arguments"""
#         if args is None:
#             args = sys.argv[1:]
#         # sanitize builder options to prevent ArgumentParser from processing them
#         for opt in ['--builder-options', '--srpm-builder-options']:
#             try:
#                 i = args.index(opt)
#                 args[i:i+2] = ['='.join(args[i:i+2])]
#             except ValueError:
#                 continue
#         self.parser = CLI.build_parser(available_choices_only=True)
#         self.args = self.parser.parse_args(args)
# 
#     def __getattr__(self, name):
#         try:
#             return getattr(self.args, name)
#         except AttributeError:
#             return object.__getattribute__(self, name)
# 
# Path: rebasehelper/config.py
# class Config:
# 
#     def __init__(self, config_file=None):
#         self.path_to_config = self.get_config_path(config_file)
#         self.config = self.get_config()
# 
#     def __getattr__(self, name):
#         return self.config.get(name)
# 
#     @staticmethod
#     def get_config_path(config_file):
#         # ensure XDG_CONFIG_HOME is set
#         if 'XDG_CONFIG_HOME' not in os.environ:
#             os.environ['XDG_CONFIG_HOME'] = os.path.expandvars(os.path.join('$HOME', '.config'))
#         path = os.path.expandvars(config_file or os.path.join(CONFIG_PATH, CONFIG_FILENAME))
#         return os.path.abspath(path)
# 
#     def get_config(self):
#         conf = {}
#         if os.path.isfile(self.path_to_config):
#             config = configparser.ConfigParser()
#             config.read(self.path_to_config)
#             for section in config.sections():
#                 conf.update({k.replace('-', '_'): v for k, v in config.items(section)})
# 
#         return conf
# 
#     def merge(self, cli):
#         self.config.update(vars(cli.args))
# 
#         for option in traverse_options(OPTIONS + plugin_manager.get_options()):
#             if 'dest' in option:
#                 dest = option['dest']
#             else:
#                 args = [n.lstrip('-').replace('-', '_') for n in option['name'] if n.startswith('--')]
#                 if args:
#                     dest = args[0]
# 
#             if dest and dest not in self.config:
#                 self.config[dest] = option.get('default')
# 
# Path: rebasehelper/constants.py
# ENCODING: str = locale.getpreferredencoding()


import configparser
import os
import pytest  # type: ignore
from rebasehelper.cli import CLI
from rebasehelper.config import Config
from rebasehelper.constants import ENCODING
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Authors: Petr Hráček <phracek@redhat.com>
#          Tomáš Hozza <thozza@redhat.com>
#          Nikola Forró <nforro@redhat.com>
#          František Nečas <fifinecas@seznam.cz>





class TestConfig:
    CONFIG_FILE: str = 'test_config.cfg'

    @pytest.fixture
    def config_file(self, config_args):
        config = configparser.ConfigParser()
        config.add_section('Section1')
        for key, value in config_args.items():
            config.set('Section1', key, value)

# Path: rebasehelper/cli.py
# class CLI:
#     """ Class for processing data from commandline """
# 
#     @staticmethod
#     def build_parser(available_choices_only=False):
#         parser = CustomArgumentParser(description=PROGRAM_DESCRIPTION,
#                                       formatter_class=CustomHelpFormatter)
# 
#         group = None
#         current_group = 0
#         for option in traverse_options(OPTIONS + plugin_manager.get_options()):
#             available_choices = option.pop("available_choices", option.get("choices"))
#             if available_choices_only:
#                 option["choices"] = available_choices
# 
#             option_kwargs = dict(option)
#             for key in ("group", "default", "name"):
#                 if key in option_kwargs:
#                     del option_kwargs[key]
# 
#             if "group" in option:
#                 if not group or current_group != option["group"]:
#                     current_group = option["group"]
#                     group = parser.add_mutually_exclusive_group()
#                 actions_container = group
#             else:
#                 actions_container = parser
# 
#             # default is set to SUPPRESS to prevent arguments which were not specified on command line from being
#             # added to namespace. This allows rebase-helper to determine which arguments are used with their
#             # default value. This is later used for merging CLI arguments with config.
#             actions_container.add_argument(*option["name"], action=CustomAction, default=argparse.SUPPRESS,
#                                            actual_default=option.get("default"), **option_kwargs)
# 
#         return parser
# 
#     def __init__(self, args=None):
#         """parse arguments"""
#         if args is None:
#             args = sys.argv[1:]
#         # sanitize builder options to prevent ArgumentParser from processing them
#         for opt in ['--builder-options', '--srpm-builder-options']:
#             try:
#                 i = args.index(opt)
#                 args[i:i+2] = ['='.join(args[i:i+2])]
#             except ValueError:
#                 continue
#         self.parser = CLI.build_parser(available_choices_only=True)
#         self.args = self.parser.parse_args(args)
# 
#     def __getattr__(self, name):
#         try:
#             return getattr(self.args, name)
#         except AttributeError:
#             return object.__getattribute__(self, name)
# 
# Path: rebasehelper/config.py
# class Config:
# 
#     def __init__(self, config_file=None):
#         self.path_to_config = self.get_config_path(config_file)
#         self.config = self.get_config()
# 
#     def __getattr__(self, name):
#         return self.config.get(name)
# 
#     @staticmethod
#     def get_config_path(config_file):
#         # ensure XDG_CONFIG_HOME is set
#         if 'XDG_CONFIG_HOME' not in os.environ:
#             os.environ['XDG_CONFIG_HOME'] = os.path.expandvars(os.path.join('$HOME', '.config'))
#         path = os.path.expandvars(config_file or os.path.join(CONFIG_PATH, CONFIG_FILENAME))
#         return os.path.abspath(path)
# 
#     def get_config(self):
#         conf = {}
#         if os.path.isfile(self.path_to_config):
#             config = configparser.ConfigParser()
#             config.read(self.path_to_config)
#             for section in config.sections():
#                 conf.update({k.replace('-', '_'): v for k, v in config.items(section)})
# 
#         return conf
# 
#     def merge(self, cli):
#         self.config.update(vars(cli.args))
# 
#         for option in traverse_options(OPTIONS + plugin_manager.get_options()):
#             if 'dest' in option:
#                 dest = option['dest']
#             else:
#                 args = [n.lstrip('-').replace('-', '_') for n in option['name'] if n.startswith('--')]
#                 if args:
#                     dest = args[0]
# 
#             if dest and dest not in self.config:
#                 self.config[dest] = option.get('default')
# 
# Path: rebasehelper/constants.py
# ENCODING: str = locale.getpreferredencoding()


# Path: rebasehelper/tests/test_config.py
import configparser
import os
import pytest  # type: ignore
from rebasehelper.cli import CLI
from rebasehelper.config import Config
from rebasehelper.constants import ENCODING

# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Authors: Petr Hráček <phracek@redhat.com>
#          Tomáš Hozza <thozza@redhat.com>
#          Nikola Forró <nforro@redhat.com>
#          František Nečas <fifinecas@seznam.cz>





class TestConfig:
    CONFIG_FILE: str = 'test_config.cfg'

    @pytest.fixture
    def config_file(self, config_args):
        config = configparser.ConfigParser()
        config.add_section('Section1')
        for key, value in config_args.items():
            config.set('Section1', key, value)

        with open(self.CONFIG_FILE, 'w', encoding=ENCODING) as configfile: