Skip to content

Commit

Permalink
Bring test coverage back up to >= 90%
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Jul 8, 2016
1 parent 5817d01 commit 6af2b15
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions rotate_backups/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Test suite for the `rotate-backups' Python package.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: July 8, 2016
# Last Change: July 9, 2016
# URL: https://github.com/xolox/python-rotate-backups

"""Test suite for the `rotate-backups` package."""
Expand All @@ -16,6 +16,7 @@

# External dependencies.
import coloredlogs
from executor.contexts import RemoteContext
from six.moves import configparser

# The module we're testing.
Expand Down Expand Up @@ -98,20 +99,33 @@ def setUp(self):

def test_retention_period_coercion(self):
"""Test coercion of retention period expressions."""
# Test that invalid values are refused.
self.assertRaises(ValueError, coerce_retention_period, ['not', 'a', 'string'])
# Test that invalid evaluation results are refused.
self.assertRaises(ValueError, coerce_retention_period, 'None')
# Check that the string `always' makes it through alive :-).
assert coerce_retention_period('always') == 'always'
assert coerce_retention_period('Always') == 'always'
# Check that anything else properly evaluates to a number.
assert coerce_retention_period(42) == 42
assert coerce_retention_period('42') == 42
assert coerce_retention_period('21 * 2') == 42

def test_location_coercion(self):
"""Test coercion of locations."""
# Test that invalid values are refused.
self.assertRaises(ValueError, lambda: coerce_location(['not', 'a', 'string']))
# Test that remote locations are properly parsed.
location = coerce_location('some-host:/some/directory')
assert isinstance(location.context, RemoteContext)
assert location.directory == '/some/directory'

def test_argument_validation(self):
"""Test argument validation."""
# 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.
assert run_cli('--hourly=not-a-number') != 0
# Test that invalid location values are properly reported.
self.assertRaises(ValueError, lambda: coerce_location(['not', 'a', 'string']))
# Argument validation tests that require an empty directory.
with TemporaryDirectory(prefix='rotate-backups-', suffix='-test-suite') as root:
# Test that non-existing directories cause an error to be reported.
Expand Down

0 comments on commit 6af2b15

Please sign in to comment.