def test_parse_configuration_with_extra_option_should_raise(): section_names = (module.CONFIG_SECTION_LOCATION, module.CONFIG_SECTION_RETENTION) parser = insert_mock_parser(section_names) for section_name in section_names: parser.should_receive('options').with_args(section_name).and_return( module.CONFIG_FORMAT[section_name] + ('extra',), ) with assert_raises(ValueError): module.parse_configuration(flexmock())
def main(): parser = ArgumentParser() parser.add_argument( '--config', dest='config_filename', default='/etc/atticmatic/config', help='Configuration filename', ) parser.add_argument( '--excludes', dest='excludes_filename', default='/etc/atticmatic/excludes', help='Excludes filename', ) parser.add_argument( '--verbose', action='store_true', help='Display verbose progress information', ) args = parser.parse_args() try: location_config, retention_config = parse_configuration(args.config_filename) create_archive(args.excludes_filename, args.verbose, *location_config) prune_archives(location_config.repository, args.verbose, *retention_config) except (ValueError, CalledProcessError), error: print(error, file=sys.stderr) sys.exit(1)
def test_parse_configuration_should_return_config_data(): section_names = (module.CONFIG_SECTION_LOCATION, module.CONFIG_SECTION_RETENTION) parser = insert_mock_parser(section_names) for section_name in section_names: parser.should_receive('options').with_args(section_name).and_return( module.CONFIG_FORMAT[section_name], ) expected_config = ( module.LocationConfig(flexmock(), flexmock()), module.RetentionConfig(flexmock(), flexmock(), flexmock()), ) sections = ( (module.CONFIG_SECTION_LOCATION, expected_config[0], 'get'), (module.CONFIG_SECTION_RETENTION, expected_config[1], 'getint'), ) for section_name, section_config, method_name in sections: for index, option_name in enumerate(module.CONFIG_FORMAT[section_name]): ( parser.should_receive(method_name).with_args(section_name, option_name) .and_return(section_config[index]) ) config = module.parse_configuration(flexmock()) assert config == expected_config
def main(): try: args = parse_arguments(*sys.argv[1:]) location_config, retention_config = parse_configuration(args.config_filename) repository = location_config['repository'] create_archive(args.excludes_filename, args.verbose, **location_config) prune_archives(args.verbose, repository, retention_config) check_archives(args.verbose, repository) except (ValueError, IOError, CalledProcessError) as error: print(error, file=sys.stderr) sys.exit(1)
def main(): try: args = parse_arguments(*sys.argv[1:]) location_config, retention_config = parse_configuration( args.config_filename) repository = location_config['repository'] create_archive(args.excludes_filename, args.verbose, **location_config) prune_archives(args.verbose, repository, retention_config) check_archives(args.verbose, repository) except (ValueError, IOError, CalledProcessError) as error: print(error, file=sys.stderr) sys.exit(1)
def test_parse_configuration_should_return_section_configs(): parser = insert_mock_parser() mock_module = flexmock(module) mock_module.should_receive('validate_configuration_format').with_args( parser, module.CONFIG_FORMAT, ).once() mock_section_configs = (flexmock(),) * len(module.CONFIG_FORMAT) for section_format, section_config in zip(module.CONFIG_FORMAT, mock_section_configs): mock_module.should_receive('parse_section_options').with_args( parser, section_format, ).and_return(section_config).once() parsed_config = module.parse_configuration('filename') assert parsed_config == module.Parsed_config(*mock_section_configs)
def test_parse_configuration_should_return_section_configs(): parser = insert_mock_parser() config_format = (flexmock(name='items'), flexmock(name='things')) mock_module = flexmock(module) mock_module.should_receive('validate_configuration_format').with_args( parser, config_format, ).once() mock_section_configs = (flexmock(), flexmock()) for section_format, section_config in zip(config_format, mock_section_configs): mock_module.should_receive('parse_section_options').with_args( parser, section_format, ).and_return(section_config).once() parsed_config = module.parse_configuration('filename', config_format) assert parsed_config == type(parsed_config)(*mock_section_configs)
def main(): try: command_name = os.path.basename(sys.argv[0]) args = parse_arguments(command_name, *sys.argv[1:]) backend = load_backend(command_name) config = parse_configuration(args.config_filename, backend.CONFIG_FORMAT) repository = config.location['repository'] backend.initialize(config.storage) backend.create_archive( args.excludes_filename, args.verbosity, config.storage, **config.location ) backend.prune_archives(args.verbosity, repository, config.retention) backend.check_archives(args.verbosity, repository, config.consistency) except (ValueError, IOError, CalledProcessError) as error: print(error, file=sys.stderr) sys.exit(1)
def test_parse_configuration_should_return_section_configs(): parser = insert_mock_parser() mock_module = flexmock(module) mock_module.should_receive('validate_configuration_format').with_args( parser, module.CONFIG_FORMAT, ).once() mock_section_configs = (flexmock(), flexmock()) for section_format, section_config in zip(module.CONFIG_FORMAT, mock_section_configs): mock_module.should_receive('parse_section_options').with_args( parser, section_format, ).and_return(section_config).once() section_configs = module.parse_configuration('filename') assert section_configs == mock_section_configs
def test_parse_configuration_with_file_open_error_should_raise(): parser = insert_mock_parser() parser.should_receive('read').and_return([]) with assert_raises(ValueError): module.parse_configuration('filename', config_format=flexmock())
def test_parse_configuration_with_extra_section_should_raise(): insert_mock_parser((module.CONFIG_SECTION_LOCATION, module.CONFIG_SECTION_RETENTION, 'extra')) with assert_raises(ValueError): module.parse_configuration(flexmock())
def test_parse_configuration_with_missing_section_should_raise(): insert_mock_parser((module.CONFIG_SECTION_LOCATION,)) with assert_raises(ValueError): module.parse_configuration(flexmock())