| 1 |
from fenrirscreenreader.core.debugManager import DebugManager |
| 2 |
|
| 3 |
|
| 4 |
def test_default_debug_file_uses_flat_name(tmp_path, monkeypatch): |
| 5 |
monkeypatch.setattr(DebugManager, "DEFAULT_LOG_DIR", str(tmp_path)) |
| 6 |
manager = DebugManager() |
| 7 |
try: |
| 8 |
manager.open_debug_file() |
| 9 |
|
| 10 |
assert manager.get_debug_file() == str(tmp_path / "fenrir.log") |
| 11 |
assert (tmp_path / "fenrir.log").exists() |
| 12 |
finally: |
| 13 |
manager.close_debug_file() |
| 14 |
|
| 15 |
|
| 16 |
def test_default_debug_file_uses_next_number_when_locked( |
| 17 |
tmp_path, monkeypatch |
| 18 |
): |
| 19 |
monkeypatch.setattr(DebugManager, "DEFAULT_LOG_DIR", str(tmp_path)) |
| 20 |
first_manager = DebugManager() |
| 21 |
second_manager = DebugManager() |
| 22 |
try: |
| 23 |
first_manager.open_debug_file() |
| 24 |
second_manager.open_debug_file() |
| 25 |
|
| 26 |
assert first_manager.get_debug_file() == str(tmp_path / "fenrir.log") |
| 27 |
assert second_manager.get_debug_file() == str( |
| 28 |
tmp_path / "fenrir2.log" |
| 29 |
) |
| 30 |
assert (tmp_path / "fenrir2.log").exists() |
| 31 |
finally: |
| 32 |
second_manager.close_debug_file() |
| 33 |
first_manager.close_debug_file() |
| 34 |
|
| 35 |
|
| 36 |
def test_default_debug_file_reuses_unlocked_flat_name(tmp_path, monkeypatch): |
| 37 |
monkeypatch.setattr(DebugManager, "DEFAULT_LOG_DIR", str(tmp_path)) |
| 38 |
first_manager = DebugManager() |
| 39 |
second_manager = DebugManager() |
| 40 |
try: |
| 41 |
first_manager.open_debug_file() |
| 42 |
first_manager.close_debug_file() |
| 43 |
second_manager.open_debug_file() |
| 44 |
|
| 45 |
assert second_manager.get_debug_file() == str(tmp_path / "fenrir.log") |
| 46 |
finally: |
| 47 |
second_manager.close_debug_file() |
| 48 |
|
| 49 |
|
| 50 |
def test_explicit_debug_file_uses_exact_path(tmp_path): |
| 51 |
debug_file = tmp_path / "custom.log" |
| 52 |
manager = DebugManager(str(debug_file)) |
| 53 |
try: |
| 54 |
manager.open_debug_file() |
| 55 |
|
| 56 |
assert manager.get_debug_file() == str(debug_file) |
| 57 |
assert debug_file.exists() |
| 58 |
finally: |
| 59 |
manager.close_debug_file() |