@@ -10,13 +10,13 @@ def test_cache_under_limit(tmp_path, monkeypatch):
1010 """Test that writing a file under the size limit does not trigger eviction."""
1111 # Set a tiny limit: 100 bytes
1212 monkeypatch .setenv ("ODYSSEUS_TTS_CACHE_MAX_BYTES" , "100" )
13-
13+
1414 # Initialize service with pytest's temporary directory
1515 service = TTSService (cache_dir = str (tmp_path ))
16-
16+
1717 # Write a 40-byte file (under the 100-byte limit)
1818 service ._put_cache ("test_key" , b"x" * 40 )
19-
19+
2020 # Verify the file was written and nothing was deleted
2121 files = list (tmp_path .glob ("*.*" ))
2222 assert len (files ) == 1
@@ -27,32 +27,32 @@ def test_cache_exceeds_limit_triggers_eviction(tmp_path, monkeypatch):
2727 # Set limit to 100 bytes. 80% target capacity will be 80 bytes.
2828 monkeypatch .setenv ("ODYSSEUS_TTS_CACHE_MAX_BYTES" , "100" )
2929 service = TTSService (cache_dir = str (tmp_path ))
30-
30+
3131 # 1. Setup: Manually create two older files (40 bytes each)
3232 file1 = tmp_path / "oldest.wav"
3333 file2 = tmp_path / "middle.wav"
34-
34+
3535 file1 .write_bytes (b"a" * 40 )
3636 file2 .write_bytes (b"b" * 40 )
37-
37+
3838 # Spoof timestamps so file1 is explicitly older than file2
3939 now = time .time ()
4040 os .utime (file1 , (now - 100 , now - 100 )) # 100 seconds ago
4141 os .utime (file2 , (now - 50 , now - 50 )) # 50 seconds ago
42-
42+
4343 # 2. Action: Write a 3rd file using the service method (40 bytes)
4444 # Total cache is now 120 bytes, which exceeds 100.
4545 # It should delete oldest (file1) to drop to 80 bytes (which matches the 80% target).
4646 service ._put_cache ("newest" , b"c" * 40 )
47-
47+
4848 # 3. Assertions
4949 # The newest file should exist (saved as .wav because it lacks MP3 magic bytes)
5050 newest_file = tmp_path / "newest.wav"
51-
51+
5252 assert not file1 .exists (), "The oldest file should have been evicted."
5353 assert file2 .exists (), "The middle file should still exist."
5454 assert newest_file .exists (), "The newest file should have been saved."
55-
55+
5656 # Verify the final directory size is <= 80 bytes
5757 total_size = sum (f .stat ().st_size for f in tmp_path .glob ("*.*" ))
5858 assert total_size <= 80
@@ -61,12 +61,12 @@ def test_cache_limit_disabled(tmp_path, monkeypatch):
6161 """Test that setting max bytes to 0 disables eviction."""
6262 monkeypatch .setenv ("ODYSSEUS_TTS_CACHE_MAX_BYTES" , "0" )
6363 service = TTSService (cache_dir = str (tmp_path ))
64-
64+
6565 # Write 3 large files that would normally trigger eviction
6666 service ._put_cache ("file1" , b"x" * 1000 )
6767 service ._put_cache ("file2" , b"x" * 1000 )
6868 service ._put_cache ("file3" , b"x" * 1000 )
69-
69+
7070 # Ensure nothing was deleted
7171 files = list (tmp_path .glob ("*.*" ))
7272 assert len (files ) == 3
@@ -94,4 +94,4 @@ def mock_unlink(self_path):
9494 pytest .fail (f"_put_cache raised an exception during failed eviction: { e } " )
9595
9696 # The new file should still be written successfully
97- assert (tmp_path / "new_key.wav" ).exists ()
97+ assert (tmp_path / "new_key.wav" ).exists ()
0 commit comments