Skip to content

Commit 12190d2

Browse files
committed
Reproduce #12 in test suite
For more information: #12
1 parent 2be50fb commit 12190d2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

rotate_backups/tests.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# External dependencies.
1515
from executor.contexts import RemoteContext
16-
from humanfriendly.testing import TemporaryDirectory, TestCase, run_cli
16+
from humanfriendly.testing import TemporaryDirectory, TestCase, run_cli, touch
1717
from six.moves import configparser
1818

1919
# The module we're testing.
@@ -140,6 +140,18 @@ def test_argument_validation(self):
140140
returncode, output = run_cli(main, '-n', '/root')
141141
assert returncode != 0
142142

143+
def test_invalid_dates(self):
144+
"""Make sure filenames with invalid dates don't cause an exception."""
145+
with TemporaryDirectory(prefix='rotate-backups-', suffix='-test-suite') as root:
146+
file_with_valid_date = os.path.join(root, 'snapshot-201808030034.tar.gz')
147+
file_with_invalid_date = os.path.join(root, 'snapshot-180731150101.tar.gz')
148+
for filename in file_with_valid_date, file_with_invalid_date:
149+
touch(filename)
150+
program = RotateBackups(rotation_scheme=dict(monthly='always'))
151+
backups = program.collect_backups(root)
152+
assert len(backups) == 1
153+
assert backups[0].pathname == file_with_valid_date
154+
143155
def test_dry_run(self):
144156
"""Make sure dry run doesn't remove any backups."""
145157
with TemporaryDirectory(prefix='rotate-backups-', suffix='-test-suite') as root:

0 commit comments

Comments
 (0)