Skip to content

Commit

Permalink
Fix configparser.NoSectionError
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jun 17, 2022
1 parent 18a791e commit 1093ac7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion audiorename/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def __init__(self, job: 'Job', section: str,
attr = job.config.getint(section, option)
else:
attr = job.config.get(section, option)
except configparser.NoOptionError:
except (configparser.NoOptionError,
configparser.NoSectionError):
pass

if attr is not None:
Expand Down
2 changes: 2 additions & 0 deletions test/files/config/minimal.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[rename]
backup_folder = /tmp/minimal
17 changes: 11 additions & 6 deletions test/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,20 @@ def test_remap_classical(self):
job(remap_classical=True).metadata_actions.remap_classical, True)


class TestJobWithConfigParser(unittest.TestCase):
def make_job_with_config(config_file: str) -> Job:
args = ArgsDefault()
args.config = helper.get_testfile('config', config_file)
return Job(args)


def get_job(self, *config_file: str) -> Job:
args = ArgsDefault()
args.config = helper.get_testfile(*config_file)
return Job(args)
class TestJobWithConfigParser(unittest.TestCase):

def setUp(self):
self.job = self.get_job('config', 'all-true.ini')
self.job = make_job_with_config('all-true.ini')

def test_minimal_config_file(self):
job = make_job_with_config('minimal.ini')
self.assertEqual(job.rename.backup_folder, '/tmp/minimal')

def test_section_selection(self):
self.assertEqual(self.job.selection.source, '/tmp')
Expand Down

0 comments on commit 1093ac7

Please sign in to comment.