2015-07-26 21:06:03 -07:00
|
|
|
import os
|
2014-12-20 11:37:25 -08:00
|
|
|
|
2015-07-26 21:06:03 -07:00
|
|
|
from flexmock import flexmock
|
2016-04-10 15:59:36 -07:00
|
|
|
import pytest
|
2014-12-20 11:37:25 -08:00
|
|
|
|
2017-07-08 22:33:51 -07:00
|
|
|
from borgmatic.commands import borgmatic as module
|
2015-07-18 18:35:29 -07:00
|
|
|
|
|
|
|
|
2014-12-20 11:37:25 -08:00
|
|
|
def test_parse_arguments_with_no_arguments_uses_defaults():
|
2015-07-26 21:06:03 -07:00
|
|
|
flexmock(os.path).should_receive('exists').and_return(True)
|
|
|
|
|
2016-06-10 11:21:53 -07:00
|
|
|
parser = module.parse_arguments()
|
2014-12-20 11:37:25 -08:00
|
|
|
|
2016-06-10 11:21:53 -07:00
|
|
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME
|
|
|
|
assert parser.excludes_filename == module.DEFAULT_EXCLUDES_FILENAME
|
2017-07-10 09:43:25 -07:00
|
|
|
assert parser.verbosity is None
|
2014-12-20 11:37:25 -08:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_filename_arguments_overrides_defaults():
|
2015-07-26 21:06:03 -07:00
|
|
|
flexmock(os.path).should_receive('exists').and_return(True)
|
|
|
|
|
2016-06-10 11:21:53 -07:00
|
|
|
parser = module.parse_arguments('--config', 'myconfig', '--excludes', 'myexcludes')
|
2014-12-20 11:37:25 -08:00
|
|
|
|
|
|
|
assert parser.config_filename == 'myconfig'
|
|
|
|
assert parser.excludes_filename == 'myexcludes'
|
2017-07-10 09:43:25 -07:00
|
|
|
assert parser.verbosity is None
|
2014-12-20 11:37:25 -08:00
|
|
|
|
|
|
|
|
2015-07-26 21:06:03 -07:00
|
|
|
def test_parse_arguments_with_missing_default_excludes_file_sets_filename_to_none():
|
|
|
|
flexmock(os.path).should_receive('exists').and_return(False)
|
|
|
|
|
2016-06-10 11:21:53 -07:00
|
|
|
parser = module.parse_arguments()
|
2015-07-26 21:06:03 -07:00
|
|
|
|
2016-06-10 11:21:53 -07:00
|
|
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME
|
2017-07-10 09:43:25 -07:00
|
|
|
assert parser.excludes_filename is None
|
|
|
|
assert parser.verbosity is None
|
2015-07-26 21:06:03 -07:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_missing_overridden_excludes_file_retains_filename():
|
|
|
|
flexmock(os.path).should_receive('exists').and_return(False)
|
|
|
|
|
2016-06-10 11:21:53 -07:00
|
|
|
parser = module.parse_arguments('--excludes', 'myexcludes')
|
2015-07-26 21:06:03 -07:00
|
|
|
|
2016-06-10 11:21:53 -07:00
|
|
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME
|
2015-07-26 21:06:03 -07:00
|
|
|
assert parser.excludes_filename == 'myexcludes'
|
2017-07-10 09:43:25 -07:00
|
|
|
assert parser.verbosity is None
|
2015-07-26 21:06:03 -07:00
|
|
|
|
|
|
|
|
2015-07-17 21:58:50 -07:00
|
|
|
def test_parse_arguments_with_verbosity_flag_overrides_default():
|
2015-07-26 21:06:03 -07:00
|
|
|
flexmock(os.path).should_receive('exists').and_return(True)
|
|
|
|
|
2016-06-10 11:21:53 -07:00
|
|
|
parser = module.parse_arguments('--verbosity', '1')
|
2014-12-20 11:37:25 -08:00
|
|
|
|
2016-06-10 11:21:53 -07:00
|
|
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME
|
|
|
|
assert parser.excludes_filename == module.DEFAULT_EXCLUDES_FILENAME
|
2015-07-17 21:58:50 -07:00
|
|
|
assert parser.verbosity == 1
|
2014-12-20 11:37:25 -08:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_invalid_arguments_exits():
|
2015-07-26 21:06:03 -07:00
|
|
|
flexmock(os.path).should_receive('exists').and_return(True)
|
2017-07-10 09:43:25 -07:00
|
|
|
|
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
module.parse_arguments('--posix-me-harder')
|