Skip to content

Commit

Permalink
Guard against empty rotation scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Jul 19, 2015
1 parent 0a407fb commit 3824d29
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion rotate_backups/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""

# Semi-standard module versioning.
__version__ = '2.0'
__version__ = '2.1'

# Standard library modules.
import collections
Expand Down Expand Up @@ -129,7 +129,12 @@ def __init__(self, rotation_scheme, include_list=None, exclude_list=None, dry_ru
:param io_scheduling_class: Use ``ionice`` to set the I/O scheduling class
(expected to be one of the strings 'idle',
'best-effort' or 'realtime').
:raises: :exc:`~exceptions.ValueError` when the rotation scheme
dictionary is empty (this would cause all backups to be
deleted).
"""
if not rotation_scheme:
raise ValueError("Refusing to use empty rotation scheme! (all backups would be deleted)")
self.rotation_scheme = rotation_scheme
self.include_list = include_list
self.exclude_list = exclude_list
Expand Down
5 changes: 4 additions & 1 deletion rotate_backups/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import coloredlogs

# The module we're testing.
from rotate_backups import RotateBackups
from rotate_backups.cli import main

# Initialize a logger for this module.
Expand Down Expand Up @@ -86,7 +87,9 @@ def setUp(self):
coloredlogs.install(level=logging.DEBUG)

def test_argument_validation(self):
"""Test argument validation of the ``ionice`` scheduling class."""
"""Test argument validation."""
# Test that an empty rotation scheme raises an exception.
self.assertRaises(ValueError, RotateBackups, rotation_scheme={})
# Test that an invalid ionice scheduling class causes an error to be reported.
assert run_cli('--ionice=unsupported-class') != 0
# Test that an invalid rotation scheme causes an error to be reported.
Expand Down

0 comments on commit 3824d29

Please sign in to comment.