|
13 | 13 |
|
14 | 14 | # External dependencies. |
15 | 15 | from executor.contexts import RemoteContext |
16 | | -from humanfriendly.testing import TemporaryDirectory, TestCase, run_cli |
| 16 | +from humanfriendly.testing import TemporaryDirectory, TestCase, run_cli, touch |
17 | 17 | from six.moves import configparser |
18 | 18 |
|
19 | 19 | # The module we're testing. |
@@ -140,6 +140,18 @@ def test_argument_validation(self): |
140 | 140 | returncode, output = run_cli(main, '-n', '/root') |
141 | 141 | assert returncode != 0 |
142 | 142 |
|
| 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 | + |
143 | 155 | def test_dry_run(self): |
144 | 156 | """Make sure dry run doesn't remove any backups.""" |
145 | 157 | with TemporaryDirectory(prefix='rotate-backups-', suffix='-test-suite') as root: |
|
0 commit comments