Skip to content

Commit

Permalink
Add argument parsing test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Javier Collado committed Nov 25, 2016
1 parent 530d982 commit e25359b
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,47 @@
import logging

from unittest import TestCase
from StringIO import StringIO

from rabbithole.cli import configure_logging
import yaml

from mock import patch
from rabbithole.cli import (
configure_logging,
parse_arguments,
)


class TestParseArguments(TestCase):

"""Argument parsing test cases."""

def test_systemexit_raised_on_config_file_does_not_exist(self):
"""SystemExit is raised if the configuration file does not exist."""
# Do not include error output in test output
with self.assertRaises(SystemExit), patch('rabbithole.cli.sys.stderr'):
parse_arguments(['file-does-not-exist'])

def test_systemexit_raised_on_config_file_invalid(self):
"""SystemExit is raised if the configuration file is invalid."""
with self.assertRaises(SystemExit), \
patch('rabbithole.cli.sys.stderr'), \
patch('rabbithole.cli.os') as os, \
patch('rabbithole.cli.open') as open:
os.path.isfile.return_value = True
open().__enter__.return_value = StringIO('>invalid yaml<')
parse_arguments(['some file'])

def test_config_file_load_success(self):
"""Config file successfully loaded."""
expected_value = {'a': 'value'}
with patch('rabbithole.cli.os') as os, \
patch('rabbithole.cli.open') as open:
os.path.isfile.return_value = True
open().__enter__.return_value = StringIO(yaml.dump(expected_value))
args = parse_arguments(['some file'])

self.assertDictEqual(args.config, expected_value)


class TestConfigureLogging(TestCase):
Expand Down

0 comments on commit e25359b

Please sign in to comment.