Skip to content

Commit

Permalink
Merge pull request #12 from crccheck/no-config
Browse files Browse the repository at this point in the history
No config
  • Loading branch information
crccheck committed Oct 21, 2014
2 parents 30d5746 + d539f8c commit c9ea831
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions leadbutt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from calendar import timegm
import datetime
import os.path
import sys

from docopt import docopt
Expand Down Expand Up @@ -51,6 +52,10 @@ def load(fp):

if config_file == '-':
return load(sys.stdin)
if not os.path.exists(config_file):
sys.stderr.write('ERROR: Must either run next to config.yaml or'
' specify a config file.\n' + __doc__)
sys.exit(2)
with open(config_file) as fp:
return load(fp)

Expand Down
7 changes: 7 additions & 0 deletions test_leadbutt.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def test_config_handles_malformed_yaml(self, mock_stdin, mock_stderr):
self.assertEqual(e.exception.code, 1)
self.assertTrue(mock_stderr.write.called)

@mock.patch('sys.stderr')
def test_config_handles_missing_file(self, mock_stderr):
with self.assertRaises(SystemExit) as e:
leadbutt.get_config('whatever_the_default_config_is')
self.assertEqual(e.exception.code, 2)
self.assertTrue(mock_stderr.write.called)


class get_optionsTest(unittest.TestCase):
def test_get_options_returns_right_option(self):
Expand Down

0 comments on commit c9ea831

Please sign in to comment.