File size: 1,142 Bytes
a8784d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Temp-file registry: 'Clear all' must genuinely unlink tracked files."""
import os

from src import workspace


def test_new_temp_tracked_then_cleared():
    before = workspace.tracked_count()
    p1 = workspace.new_temp(suffix=".pdf")
    p2 = workspace.new_temp(suffix=".zip")
    assert os.path.exists(p1) and os.path.exists(p2)
    assert workspace.tracked_count() == before + 2

    removed = workspace.clear_all()
    assert removed >= 2
    assert not os.path.exists(p1) and not os.path.exists(p2)
    assert workspace.tracked_count() == 0


def test_discard_unlinks_and_untracks():
    p = workspace.new_temp(suffix=".pdf")
    before = workspace.tracked_count()
    assert workspace.discard(p) is True
    assert not os.path.exists(p)
    assert workspace.tracked_count() == before - 1
    # idempotent: discarding again is harmless
    assert workspace.discard(p) is False


def test_clear_all_tolerates_missing_file():
    p = workspace.new_temp(suffix=".tmp")
    os.remove(p)                      # vanish underneath the registry
    workspace.clear_all()             # must not raise
    assert workspace.tracked_count() == 0