2015-07-27 06:06:03 +02:00
|
|
|
import os
|
2014-12-20 20:37:25 +01:00
|
|
|
import sys
|
|
|
|
|
2015-07-27 06:06:03 +02:00
|
|
|
from flexmock import flexmock
|
2016-04-11 00:59:36 +02:00
|
|
|
import pytest
|
2014-12-20 20:37:25 +01:00
|
|
|
|
|
|
|
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-27 06:06:03 +02:00
|
|
|
flexmock(os.path).should_receive('exists').and_return(True)
|
|
|
|
|
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-27 06:06:03 +02:00
|
|
|
flexmock(os.path).should_receive('exists').and_return(True)
|
|
|
|
|
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-27 06:06:03 +02:00
|
|
|
def test_parse_arguments_with_missing_default_excludes_file_sets_filename_to_none():
|
|
|
|
flexmock(os.path).should_receive('exists').and_return(False)
|
|
|
|
|
|
|
|
parser = module.parse_arguments(COMMAND_NAME)
|
|
|
|
|
|
|
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME_PATTERN.format(COMMAND_NAME)
|
|
|
|
assert parser.excludes_filename == None
|
|
|
|
assert parser.verbosity == None
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_missing_overridden_excludes_file_retains_filename():
|
|
|
|
flexmock(os.path).should_receive('exists').and_return(False)
|
|
|
|
|
|
|
|
parser = module.parse_arguments(COMMAND_NAME, '--excludes', 'myexcludes')
|
|
|
|
|
|
|
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME_PATTERN.format(COMMAND_NAME)
|
|
|
|
assert parser.excludes_filename == 'myexcludes'
|
|
|
|
assert parser.verbosity == None
|
|
|
|
|
|
|
|
|
2015-07-18 06:58:50 +02:00
|
|
|
def test_parse_arguments_with_verbosity_flag_overrides_default():
|
2015-07-27 06:06:03 +02:00
|
|
|
flexmock(os.path).should_receive('exists').and_return(True)
|
|
|
|
|
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():
|
2015-07-27 06:06:03 +02:00
|
|
|
flexmock(os.path).should_receive('exists').and_return(True)
|
2014-12-20 20:37:25 +01:00
|
|
|
original_stderr = sys.stderr
|
|
|
|
sys.stderr = sys.stdout
|
|
|
|
|
|
|
|
try:
|
2016-04-11 00:59:36 +02:00
|
|
|
with pytest.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
|