2014-12-20 20:37:25 +01:00
|
|
|
import sys
|
|
|
|
|
|
|
|
from nose.tools import assert_raises
|
|
|
|
|
|
|
|
from atticmatic import command as module
|
|
|
|
|
|
|
|
|
2015-07-19 03:35:29 +02:00
|
|
|
COMMAND_NAME = 'foomatic'
|
|
|
|
|
|
|
|
|
2014-12-20 20:37:25 +01:00
|
|
|
def test_parse_arguments_with_no_arguments_uses_defaults():
|
2015-07-19 03:35:29 +02:00
|
|
|
parser = module.parse_arguments(COMMAND_NAME)
|
2014-12-20 20:37:25 +01:00
|
|
|
|
2015-07-19 03:35:29 +02:00
|
|
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME_PATTERN.format(COMMAND_NAME)
|
|
|
|
assert parser.excludes_filename == module.DEFAULT_EXCLUDES_FILENAME_PATTERN.format(COMMAND_NAME)
|
2015-07-18 06:58:50 +02:00
|
|
|
assert parser.verbosity == None
|
2014-12-20 20:37:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_filename_arguments_overrides_defaults():
|
2015-07-19 03:35:29 +02:00
|
|
|
parser = module.parse_arguments(COMMAND_NAME, '--config', 'myconfig', '--excludes', 'myexcludes')
|
2014-12-20 20:37:25 +01:00
|
|
|
|
|
|
|
assert parser.config_filename == 'myconfig'
|
|
|
|
assert parser.excludes_filename == 'myexcludes'
|
2015-07-18 06:58:50 +02:00
|
|
|
assert parser.verbosity == None
|
2014-12-20 20:37:25 +01:00
|
|
|
|
|
|
|
|
2015-07-18 06:58:50 +02:00
|
|
|
def test_parse_arguments_with_verbosity_flag_overrides_default():
|
2015-07-19 03:35:29 +02:00
|
|
|
parser = module.parse_arguments(COMMAND_NAME, '--verbosity', '1')
|
2014-12-20 20:37:25 +01:00
|
|
|
|
2015-07-19 03:35:29 +02:00
|
|
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME_PATTERN.format(COMMAND_NAME)
|
|
|
|
assert parser.excludes_filename == module.DEFAULT_EXCLUDES_FILENAME_PATTERN.format(COMMAND_NAME)
|
2015-07-18 06:58:50 +02:00
|
|
|
assert parser.verbosity == 1
|
2014-12-20 20:37:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_invalid_arguments_exits():
|
|
|
|
original_stderr = sys.stderr
|
|
|
|
sys.stderr = sys.stdout
|
|
|
|
|
|
|
|
try:
|
|
|
|
with assert_raises(SystemExit):
|
2015-07-19 03:35:29 +02:00
|
|
|
module.parse_arguments(COMMAND_NAME, '--posix-me-harder')
|
2014-12-20 20:37:25 +01:00
|
|
|
finally:
|
|
|
|
sys.stderr = original_stderr
|