diff --git a/import2ledger/config.py b/import2ledger/config.py index 33944f2..eb65cca 100644 --- a/import2ledger/config.py +++ b/import2ledger/config.py @@ -206,7 +206,7 @@ class Configuration: finally: self.args.use_config = prev_section - def _get_section(self, section_name): + def get_section(self, section_name): if section_name is None: section_name = self.args.use_config return self.conffile[section_name] @@ -226,7 +226,7 @@ class Configuration: return self._get_from_dict(self.dates, section_name) def get_loglevel(self, section_name=None): - section_config = self._get_section(section_name) + section_config = self.get_section(section_name) level_name = section_config['loglevel'] try: return getattr(logging, level_name.upper()) @@ -234,7 +234,7 @@ class Configuration: raise errors.UserInputConfigurationError("not a valid loglevel", level_name) def get_output_path(self, section_name=None): - section_config = self._get_section(section_name) + section_config = self.get_section(section_name) return self._s_to_path(section_config['output_path']) def open_output_file(self, section_name=None): @@ -242,7 +242,7 @@ class Configuration: return self._open_path(path, self.stdout, 'a') def get_template(self, config_key, section_name=None, factory=template.Template): - section_config = self._get_section(section_name) + section_config = self.get_section(section_name) try: template_s = section_config[config_key] except KeyError: diff --git a/tests/test_config.py b/tests/test_config.py index 44e6abe..dc6a303 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -47,6 +47,13 @@ def test_template_parsing(): assert "\nIncome:Donations -{amount}\n" in tmpl_s assert "\n;IncomeTag: Donations\n" in tmpl_s +def test_get_section(): + config = config_from_file('test_config.ini', ['--date-format', '%m/%d/%Y']) + section = config.get_section('Templates') + assert section['output_path'] == 'Template.output' + assert section['date_format'] == '%m/%d/%Y' + assert section['signed_currencies'] == 'EUR' + @pytest.mark.parametrize('arg_s', [None, '-', 'output.ledger']) def test_output_path(arg_s): arglist = [] if arg_s is None else ['-O', arg_s]