-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfix_freeze_pattern.py
More file actions
77 lines (62 loc) · 2.16 KB
/
fix_freeze_pattern.py
File metadata and controls
77 lines (62 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
"""
Script to fix the frozen_time.freeze() pattern in test files.
Replaces:
frozen_time.freeze("2025-01-15 12:00:00")
With:
# Use freeze_at fixture to set a custom time
"""
import re
from pathlib import Path
# Test files that need fixing
test_files = [
"tests/test_item_recurrence.py",
"tests/test_item_goals.py",
"tests/test_item_dates.py",
"tests/test_item_finish_offset.py",
"tests/test_item_parsing.py",
"tests/test_item_alerts.py",
"tests/test_integration_database.py",
]
def fix_freeze_pattern(content):
"""
Replace frozen_time.freeze() with a comment.
The frozen_time fixture already freezes to a default time.
"""
# Pattern to match frozen_time.freeze("datetime string")
pattern = r'(\s*)frozen_time\.freeze\(["\']([^"\']+)["\']\)'
def replacer(match):
indent = match.group(1)
datetime_str = match.group(2)
return f'{indent}# Time frozen to {datetime_str} via frozen_time fixture'
return re.sub(pattern, replacer, content)
def add_freeze_at_to_signature(content):
"""
If a test uses frozen_time and calls .freeze(), it should use freeze_at instead.
This is more complex, so we'll just add a comment for now.
"""
return content
def main():
for filepath in test_files:
path = Path(filepath)
if not path.exists():
print(f"Skipping {filepath} - not found")
continue
print(f"Processing {filepath}...")
# Read file
content = path.read_text()
# Count occurrences
count = len(re.findall(r'frozen_time\.freeze', content))
if count == 0:
print(f" No frozen_time.freeze() calls found")
continue
# Fix pattern
new_content = fix_freeze_pattern(content)
# Write back
path.write_text(new_content)
print(f" Replaced {count} occurrences")
if __name__ == "__main__":
main()
print("\nDone! The files have been updated.")
print("Note: Tests still need fixture signatures updated from 'frozen_time' to 'freeze_at'")
print("if they need custom times, but removing .freeze() calls will stop the errors.")