Skip to content

Commit f32bc89

Browse files
jbf302claude
andcommitted
Fix Windows file locking issues in logo caching tests
- Replace TemporaryDirectory with manual mkdtemp for Windows compatibility - Explicitly close PIL Image objects to release file handles - Add Windows-compatible cleanup with retry logic and error handling - Prevents PermissionError [WinError 32] on Windows CI 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d7331c8 commit f32bc89

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

tests/test_logos.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def test_get_available_teams_returns_list(self):
5151
def test_logo_caching_works(self):
5252
"""Test that logo caching works properly."""
5353
# Use temporary directory for test cache
54-
with tempfile.TemporaryDirectory() as temp_dir:
54+
temp_dir = tempfile.mkdtemp()
55+
try:
5556
manager = NFLAssetManager(cache_dir=temp_dir)
5657

5758
# First download should create cache
@@ -65,6 +66,23 @@ def test_logo_caching_works(self):
6566
self.assertIsInstance(logo1, Image.Image)
6667
self.assertIsInstance(logo2, Image.Image)
6768
self.assertEqual(cache_info_1['logos_count'], cache_info_2['logos_count'])
69+
70+
# Close images to release file handles on Windows
71+
logo1.close()
72+
logo2.close()
73+
74+
finally:
75+
# Windows-compatible cleanup
76+
try:
77+
shutil.rmtree(temp_dir)
78+
except (OSError, PermissionError):
79+
# On Windows, wait briefly and try again
80+
import time
81+
time.sleep(0.1)
82+
try:
83+
shutil.rmtree(temp_dir)
84+
except (OSError, PermissionError):
85+
pass # Cleanup failed but test completed successfully
6886

6987

7088
class test_matplotlib_integration(TestCase):
@@ -205,25 +223,36 @@ class test_asset_manager(TestCase):
205223

206224
def test_asset_manager_cache_info(self):
207225
"""Test that asset manager provides cache information."""
208-
with tempfile.TemporaryDirectory() as temp_dir:
226+
temp_dir = tempfile.mkdtemp()
227+
try:
209228
manager = NFLAssetManager(cache_dir=temp_dir)
210229
cache_info = manager.get_cache_info()
211230

212231
self.assertIsInstance(cache_info, dict)
213232
self.assertIn('cache_dir', cache_info)
214233
self.assertIn('logos_count', cache_info)
215234
self.assertIn('total_size_bytes', cache_info)
235+
236+
finally:
237+
try:
238+
shutil.rmtree(temp_dir)
239+
except (OSError, PermissionError):
240+
pass
216241

217242
def test_asset_manager_clear_cache(self):
218243
"""Test cache clearing functionality."""
219-
with tempfile.TemporaryDirectory() as temp_dir:
244+
temp_dir = tempfile.mkdtemp()
245+
try:
220246
manager = NFLAssetManager(cache_dir=temp_dir)
221247

222248
# Download a logo to create cache
223249
try:
224-
manager.get_logo('KC')
250+
logo = manager.get_logo('KC')
225251
cache_info_before = manager.get_cache_info()
226252

253+
# Close image to release file handle
254+
logo.close()
255+
227256
# Clear cache
228257
manager.clear_cache('logos')
229258
cache_info_after = manager.get_cache_info()
@@ -233,4 +262,10 @@ def test_asset_manager_clear_cache(self):
233262

234263
except Exception:
235264
# If logo download fails, that's okay for this test
265+
pass
266+
267+
finally:
268+
try:
269+
shutil.rmtree(temp_dir)
270+
except (OSError, PermissionError):
236271
pass

0 commit comments

Comments
 (0)