def _parse_args_consistency_manual(args): args_dict = {} args_dict['prev_date_fname'] = args.replicas_before args_dict['next_date_fname'] = args.replicas_after for path in (args.storage_dump, args_dict['prev_date_fname'], args_dict['next_date_fname']): if not os.path.exists(path): error('File "{0}" does not exist'.format(path)) return args_dict
def _parse_args_consistency(args): args_dict = {} # Filename should contain the date date_str = _date_re.match(os.path.basename(args.storage_dump)) if date_str is None: error('The storage dump filename must be of the form ' '"dump_YYYYMMDD" where the date correspond to the date ' 'of the newest files included') date_str = date_str.group(1) assert date_str is not None try: args_dict['date'] = date = datetime.datetime.strptime( date_str, '%Y%m%d') except ValueError: error('Invalid date {0}'.format(date_str)) if not os.path.exists(args.storage_dump): error('File "{0}" does not exist'.format(args.storage_dump)) if (args.prev_date is not None or args.next_date is not None) and args.delta is not None: error('Missing or conflicting arguments, specify either ' '"--delta" or "--prev-date" and "--next-date"') if args.prev_date is not None and args.next_date is not None: args_dict['prev_date'] = datetime.datetime.strptime( args.prev_date, '%d-%m-%Y', ) args_dict['next_date'] = datetime.datetime.strptime( args.next_date, '%d-%m-%Y', ) elif args.delta is not None: delta = int(args.delta) args_dict['prev_date'] = date - datetime.timedelta(days=delta) args_dict['next_date'] = date + datetime.timedelta(days=delta) else: error('Missing arguments, specify either "--delta" or ' '"--prev-date" and "--next-date"') return args_dict
def test_error_ends_the_program(): with pytest.raises(SystemExit): dumper.error('message', 2)
def test_error_ends_the_program(): dumper.error('message', 2)