-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_watcher_fix.py
More file actions
54 lines (46 loc) · 1.51 KB
/
Copy pathtest_watcher_fix.py
File metadata and controls
54 lines (46 loc) · 1.51 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
"""
Quick test to verify watcher.py fix
"""
import asyncio
import tempfile
import time
from pathlib import Path
# Simulate the buggy version
def buggy_version():
pending_files = {
Path("/tmp/test.wav"): time.time() - 5.0
}
ready_files = []
for file_path, detected_at in list(pending_files.items()):
ready_files.append(file_path) # BUG: only storing path
# Queue ready files
for file_path in ready_files:
del pending_files[file_path]
# BUG: file_path not in pending_files anymore!
pending_time = time.time() - pending_files.get(file_path, time.time())
print(f"Buggy version - pending_time: {pending_time:.2f}s")
# Simulate the fixed version
def fixed_version():
pending_files = {
Path("/tmp/test.wav"): time.time() - 5.0
}
ready_files = []
for file_path, detected_at in list(pending_files.items()):
ready_files.append((file_path, detected_at)) # FIX: store tuple
# Queue ready files
for file_path, detected_at in ready_files:
del pending_files[file_path]
# FIX: we have detected_at from tuple
pending_time = time.time() - detected_at
print(f"Fixed version - pending_time: {pending_time:.2f}s")
if __name__ == "__main__":
print("Testing buggy version:")
try:
buggy_version()
except Exception as e:
print(f"ERROR: {e}")
print("\nTesting fixed version:")
try:
fixed_version()
except Exception as e:
print(f"ERROR: {e}")