31 lines
1014 B
Python
31 lines
1014 B
Python
import os
|
|
import time
|
|
import pytest
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
from agent.scanner import is_file_locked, is_file_stable, DirectoryScanner
|
|
|
|
def test_file_lock_and_stability():
|
|
"""
|
|
Tests detection of file locks, growing files, and stable files.
|
|
"""
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
test_file = Path(tmpdir) / "test_active.bak"
|
|
test_file.write_text("initial data")
|
|
|
|
# 1. Stable file test
|
|
# When file was modified now, with min_stable_seconds=0, it should be immediately stable
|
|
assert is_file_stable(test_file, min_stable_seconds=0) == True
|
|
|
|
# 2. Scanner test with filter
|
|
other_file = Path(tmpdir) / "ignored.txt"
|
|
other_file.write_text("not a backup")
|
|
|
|
scanner = DirectoryScanner(tmpdir, file_patterns="*.bak", min_stable_seconds=0)
|
|
found = scanner.scan()
|
|
assert len(found) == 1
|
|
assert found[0].name == "test_active.bak"
|
|
|
|
print("\n>>> File Lock & Scanner Test Passed!")
|