def test_valid_args(self):
		args = _make_args_array(_get_valid_args_map())
		options, args = tarsnap_manager._parse_args(args)
		self.assertEquals(_DEFAULT_KEY_FILE, options.key_file)
		self.assertFalse(options.dry_run)
		self.assertFalse(options.skip_delete)
		self.assertEquals(_DEFAULT_ARCHIVE_NAME, options.archive_name)
		self.assertEquals(_DEFAULT_WEEKDAY, options.weekday)
		self.assertEquals(_DEFAULT_NUM_DAYS, options.num_days)
		self.assertEquals(_DEFAULT_NUM_WEEKS, options.num_weeks)
		self.assertEquals(_DEFAULT_NUM_MONTHS, options.num_months)

		# Assert that the dry_run option is recognized.
		args = _make_args_array(_get_valid_args_map())
		args.append('--dry_run')
		args.append('--skip_delete')
		options, args = tarsnap_manager._parse_args(args)
		self.assertTrue(options.dry_run)
		self.assertTrue(options.skip_delete)
	def setUp(self):
		# Use the fake methods for testing.
		self.prev_run = tarsnap_manager._run
		tarsnap_manager._run = self._fake_run

		# Clear the command called with.
		self.run_cmd = None

		self.filename = 'filename_value'
		# Create the options.
		args = _make_args_array(_get_valid_args_map())
		self.options, args = tarsnap_manager._parse_args(args)
	def setUp(self):
		# Use the fake methods for testing.
		self.prev_make_archive = tarsnap_manager._make_archive
		self.prev_delete_archive = tarsnap_manager._delete_archive
		tarsnap_manager._make_archive = self._fake_make_archive
		tarsnap_manager._delete_archive = self._fake_delete_archive

		# Clear the archive names called with.
		self.make_archive_filename = None
		self.delete_archive_filename = None

		# February 3 2012 is a Friday.
		self.d = date(2012, 2, 3)
		self.paths = ('/path1', '/path2')
		self.archive_name = 'foo'
		# Create the options.
		args = _make_args_array(_get_valid_args_map())
		self.options, args = tarsnap_manager._parse_args(args)
		self.options.archive_name = self.archive_name
	def test_invalid_args(self):
		args = _get_valid_args_map()
		del args['key_file']
		with self.assertRaises(SystemExit):
			tarsnap_manager._parse_args(_make_args_array(args))

		args = _get_valid_args_map()
		args['archive_name'] = ''
		with self.assertRaises(SystemExit):
			tarsnap_manager._parse_args(_make_args_array(args))

		args = _get_valid_args_map()
		args['weekday'] = 0
		with self.assertRaises(SystemExit):
			tarsnap_manager._parse_args(_make_args_array(args))

		args = _get_valid_args_map()
		args['weekday'] = 8
		with self.assertRaises(SystemExit):
			tarsnap_manager._parse_args(_make_args_array(args))

		args = _get_valid_args_map()
		args['num_days'] = 0
		with self.assertRaises(SystemExit):
			tarsnap_manager._parse_args(_make_args_array(args))

		args = _get_valid_args_map()
		args['num_weeks'] = -1
		with self.assertRaises(SystemExit):
			tarsnap_manager._parse_args(_make_args_array(args))

		args = _get_valid_args_map()
		args['num_months'] = -1
		with self.assertRaises(SystemExit):
			tarsnap_manager._parse_args(_make_args_array(args))