Skip to content

Commit

Permalink
Change the coafile warning/output
Browse files Browse the repository at this point in the history
  • Loading branch information
Nosferatul committed Jun 24, 2017
1 parent fea06f5 commit 3e590f5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
26 changes: 15 additions & 11 deletions coalib/settings/ConfigurationGathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
from coalib.settings.Section import Section
from coalib.settings.SectionFilling import fill_settings
from coalib.settings.Setting import Setting, path
from string import Template

COAFILE_OUTPUT = Template('$type \'$file\' $found!\n'
'Here\'s what you can do:\n'
'* add `--save` to generate a config file with '
'your current options\n'
'* add `-I` to suppress any use of config files\n')


def merge_section_dicts(lower, higher):
Expand Down Expand Up @@ -59,18 +66,15 @@ def load_config_file(filename, log_printer, silent=False):
except FileNotFoundError:
if not silent:
if os.path.basename(filename) == Constants.default_coafile:
log_printer.warn('The default coafile {0!r} was not found. '
'You can generate a configuration file with '
'your current options by adding the `--save` '
'flag or suppress any use of config '
'files with `-I`.'
.format(Constants.default_coafile))
log_printer.warn(COAFILE_OUTPUT
.substitute(type='Default coafile',
file=Constants.default_coafile,
found='not found'))
else:
log_printer.err('The requested coafile {0!r} does not exist. '
'You can generate it with your current '
'options by adding the `--save` flag or '
'suppress any use of config files with `-I`.'
.format(filename))
log_printer.err(COAFILE_OUTPUT
.substitute(type='Requested coafile',
file=filename,
found='does not exist'))
sys.exit(2)

return {'default': Section('default')}
Expand Down
4 changes: 2 additions & 2 deletions tests/coalaCITest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def test_nonexistent(self, debug=False):
coala.main, 'coala', '--non-interactive', '-c', 'nonex', 'test')
self.assertFalse(stdout)
self.assertRegex(
stderr,
".*\\[ERROR\\].*The requested coafile '.*' does not exist. .+\n")
stderr,
".*\\[ERROR\\].*Requested coafile '.*' does not exist")
self.assertNotEqual(retval, 0,
'coala must return nonzero when errors occured')

Expand Down
6 changes: 3 additions & 3 deletions tests/coalaJSONTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_nonexistent(self):
coala.main, 'coala', '--json', '-c', 'nonex', 'test')
test_text = '{\n "results": {}\n}\n'
self.assertEqual(stdout, test_text)
self.assertRegex(stderr, ".*requested coafile '.*' does not exist. .+")
self.assertRegex(stderr, ".*Requested coafile '.*' does not exist")
self.assertNotEqual(retval, 0,
'coala must return nonzero when errors occured')

Expand Down Expand Up @@ -116,8 +116,8 @@ def test_text_logs(self):
coala.main, 'coala', '--json', '-c', 'nonex')
test_text = '{\n "results": {}\n}\n'
self.assertRegex(
stderr,
".*\\[ERROR\\].*The requested coafile '.*' does not exist. .+\n")
stderr,
".*\\[ERROR\\].*Requested coafile '.*' does not exist")
self.assertEqual(stdout, test_text)
self.assertNotEqual(retval, 0,
'coala must return nonzero when errors occured')
Expand Down

0 comments on commit 3e590f5

Please sign in to comment.