File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed
Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 88Licensed under Fair Source 0.9
99"""
1010
11+ from unittest .mock import MagicMock , patch
12+
1113import pytest
1214
1315# Import from archived wizards location
3234from empathy_llm_toolkit import EmpathyLLM
3335
3436
37+ # Mock anthropic package for tests
38+ @pytest .fixture
39+ def mock_anthropic ():
40+ """Mock anthropic module so tests don't require actual package"""
41+ mock_module = MagicMock ()
42+ mock_client = MagicMock ()
43+ mock_module .Anthropic .return_value = mock_client
44+ with patch .dict ("sys.modules" , {"anthropic" : mock_module }):
45+ yield mock_module
46+
47+
3548# Test fixtures
3649@pytest .fixture
37- def llm_with_security ():
50+ def llm_with_security (mock_anthropic ):
3851 """EmpathyLLM instance with security enabled"""
3952 return EmpathyLLM (provider = "anthropic" , api_key = "test-key" , enable_security = True )
4053
4154
4255@pytest .fixture
43- def llm_without_security ():
56+ def llm_without_security (mock_anthropic ):
4457 """EmpathyLLM instance without security"""
4558 return EmpathyLLM (provider = "anthropic" , api_key = "test-key" , enable_security = False )
4659
Original file line number Diff line number Diff line change 2323)
2424
2525
26+ def _close_all_file_handlers ():
27+ """Close all file handlers to allow temp dir cleanup on Windows"""
28+ for name in list (logging .Logger .manager .loggerDict .keys ()):
29+ logger = logging .getLogger (name )
30+ for handler in logger .handlers [:]:
31+ if isinstance (handler , logging .FileHandler ):
32+ handler .close ()
33+ logger .removeHandler (handler )
34+
35+
2636@pytest .fixture
2737def temp_dir ():
2838 """Create temporary directory for test files"""
2939 tmp = tempfile .mkdtemp ()
3040 yield tmp
31- shutil .rmtree (tmp )
41+ # Close file handlers before cleanup (Windows compatibility)
42+ _close_all_file_handlers ()
43+ shutil .rmtree (tmp , ignore_errors = True )
3244
3345
3446@pytest .fixture (autouse = True )
@@ -37,6 +49,8 @@ def reset_logging_config():
3749 LoggingConfig ._configured = False
3850 LoggingConfig ._loggers = {}
3951 yield
52+ # Close file handlers before cleanup
53+ _close_all_file_handlers ()
4054 LoggingConfig ._configured = False
4155 LoggingConfig ._loggers = {}
4256
You can’t perform that action at this time.
0 commit comments