Integration tests for argument parsing.
This commit is contained in:
parent
2a45f43167
commit
de40570db4
4 changed files with 54 additions and 5 deletions
5
NEWS
5
NEWS
|
@ -1,3 +1,8 @@
|
|||
default
|
||||
|
||||
* Integration tests for argument parsing.
|
||||
* Documentation updates about repository encryption.
|
||||
|
||||
0.0.2
|
||||
|
||||
* Configuration support for additional attic prune flags: keep_within, keep_hourly, keep_yearly,
|
||||
|
|
|
@ -7,7 +7,11 @@ from atticmatic.attic import create_archive, prune_archives
|
|||
from atticmatic.config import parse_configuration
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
DEFAULT_CONFIG_FILENAME = '/etc/atticmatic/config'
|
||||
DEFAULT_EXCLUDES_FILENAME = '/etc/atticmatic/excludes'
|
||||
|
||||
|
||||
def parse_arguments(*arguments):
|
||||
'''
|
||||
Parse the command-line arguments from sys.argv and return them as an ArgumentParser instance.
|
||||
'''
|
||||
|
@ -15,13 +19,13 @@ def parse_arguments():
|
|||
parser.add_argument(
|
||||
'-c', '--config',
|
||||
dest='config_filename',
|
||||
default='/etc/atticmatic/config',
|
||||
default=DEFAULT_CONFIG_FILENAME,
|
||||
help='Configuration filename',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--excludes',
|
||||
dest='excludes_filename',
|
||||
default='/etc/atticmatic/excludes',
|
||||
default=DEFAULT_EXCLUDES_FILENAME,
|
||||
help='Excludes filename',
|
||||
)
|
||||
parser.add_argument(
|
||||
|
@ -30,12 +34,12 @@ def parse_arguments():
|
|||
help='Display verbose progress information',
|
||||
)
|
||||
|
||||
return parser.parse_args()
|
||||
return parser.parse_args(arguments)
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
args = parse_arguments()
|
||||
args = parse_arguments(*sys.argv[1:])
|
||||
location_config, retention_config = parse_configuration(args.config_filename)
|
||||
|
||||
create_archive(args.excludes_filename, args.verbose, **location_config)
|
||||
|
|
0
atticmatic/tests/integration/__init__.py
Normal file
0
atticmatic/tests/integration/__init__.py
Normal file
40
atticmatic/tests/integration/test_command.py
Normal file
40
atticmatic/tests/integration/test_command.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
import sys
|
||||
|
||||
from nose.tools import assert_raises
|
||||
|
||||
from atticmatic import command as module
|
||||
|
||||
|
||||
def test_parse_arguments_with_no_arguments_uses_defaults():
|
||||
parser = module.parse_arguments()
|
||||
|
||||
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME
|
||||
assert parser.excludes_filename == module.DEFAULT_EXCLUDES_FILENAME
|
||||
assert parser.verbose == False
|
||||
|
||||
|
||||
def test_parse_arguments_with_filename_arguments_overrides_defaults():
|
||||
parser = module.parse_arguments('--config', 'myconfig', '--excludes', 'myexcludes')
|
||||
|
||||
assert parser.config_filename == 'myconfig'
|
||||
assert parser.excludes_filename == 'myexcludes'
|
||||
assert parser.verbose == False
|
||||
|
||||
|
||||
def test_parse_arguments_with_verbose_flag_overrides_default():
|
||||
parser = module.parse_arguments('--verbose')
|
||||
|
||||
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME
|
||||
assert parser.excludes_filename == module.DEFAULT_EXCLUDES_FILENAME
|
||||
assert parser.verbose == True
|
||||
|
||||
|
||||
def test_parse_arguments_with_invalid_arguments_exits():
|
||||
original_stderr = sys.stderr
|
||||
sys.stderr = sys.stdout
|
||||
|
||||
try:
|
||||
with assert_raises(SystemExit):
|
||||
module.parse_arguments('--posix-me-harder')
|
||||
finally:
|
||||
sys.stderr = original_stderr
|
Loading…
Reference in a new issue