|
1 | 1 | # Test suite for the `rotate-backups' Python package. |
2 | 2 | # |
3 | 3 | # Author: Peter Odding <peter@peterodding.com> |
4 | | -# Last Change: February 14, 2020 |
| 4 | +# Last Change: May 17, 2020 |
5 | 5 | # URL: https://github.com/xolox/python-rotate-backups |
6 | 6 |
|
7 | 7 | """Test suite for the `rotate-backups` package.""" |
@@ -486,6 +486,21 @@ def test_invalid_timestamp_pattern(self): |
486 | 486 | timestamp_pattern=r'(?P<year>\d{4})-(?P<month>\d{2})', |
487 | 487 | ) |
488 | 488 |
|
| 489 | + def test_optional_captures(self): |
| 490 | + """Test that the hour/minute/second captures are truly optional.""" |
| 491 | + with TemporaryDirectory(prefix='rotate-backups-', suffix='-test-suite') as root: |
| 492 | + touch(os.path.join(root, 'prometheus-grafana-production-09-04-2020.tar.gz')) |
| 493 | + program = RotateBackups( |
| 494 | + rotation_scheme=dict(monthly='always'), |
| 495 | + timestamp_pattern=r'(?P<day>\d{2})-(?P<month>\d{2})-(?P<year>\d{4})', |
| 496 | + ) |
| 497 | + location = coerce_location(root) |
| 498 | + backups = program.collect_backups(location) |
| 499 | + assert len(backups) == 1 |
| 500 | + assert backups[0].timestamp.day == 9 |
| 501 | + assert backups[0].timestamp.month == 4 |
| 502 | + assert backups[0].timestamp.year == 2020 |
| 503 | + |
489 | 504 | def create_sample_backup_set(self, root): |
490 | 505 | """Create a sample backup set to be rotated.""" |
491 | 506 | for name in SAMPLE_BACKUP_SET: |
|
0 commit comments