Skip to content

Commit 9e7040e

Browse files
committed
more fixes
1 parent ef571d4 commit 9e7040e

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

tests-qt/test_systemtray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def test_settings_ui_creation_error_handling(qtbot, mock_dependencies):
418418
# Mock the error dialog to avoid actual UI display during tests
419419
with patch('nowplaying.systemtray.Tray._show_installation_error') as mock_error_dialog, \
420420
patch('nowplaying.settingsui.SettingsUI',
421-
side_effect=Exception("Settings UI creation failed")):
421+
side_effect=RuntimeError("Settings UI creation failed")):
422422

423423
# This should trigger the installation error dialog
424424
nowplaying.systemtray.Tray(beam=False)

tests/test_artistextras_wikimedia.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,16 @@ async def test_wikimedia_http_error_handling(bootstrap):
164164

165165
def make_mock_http_error(status_code):
166166

167-
async def mock_http_error(*args, **kwargs):
168-
raise ClientResponseError(request_info=None,
167+
async def mock_http_error(*args, **kwargs): # pylint: disable=unused-argument
168+
# Create a mock request_info with real_url attribute
169+
class MockRequestInfo: # pylint: disable=too-few-public-methods
170+
''' Mock request info for ClientResponseError '''
171+
def __init__(self):
172+
self.real_url = (
173+
"https://en.wikipedia.org/api/rest_v1/page/summary/Test_Artist"
174+
)
175+
176+
raise ClientResponseError(request_info=MockRequestInfo(),
169177
history=(),
170178
status=status_code,
171179
message=f"HTTP {status_code}")

tests/test_imagecache.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,18 @@ async def imagecache_with_dir(bootstrap):
5555
config = bootstrap
5656
dbdir = config.testdir.joinpath('imagecache')
5757
dbdir.mkdir()
58-
yield nowplaying.imagecache.ImageCache(cachedir=dbdir)
58+
cache = nowplaying.imagecache.ImageCache(cachedir=dbdir)
59+
yield cache
60+
61+
# Cleanup: close cache to release file handles
62+
with contextlib.suppress(Exception):
63+
if hasattr(cache, 'close'):
64+
cache.close()
65+
# Force close any database connections
66+
if hasattr(cache, 'databasefile'):
67+
with contextlib.suppress(sqlite3.Error, Exception):
68+
conn = sqlite3.connect(cache.databasefile)
69+
conn.close()
5970

6071

6172
@pytest_asyncio.fixture
@@ -64,12 +75,26 @@ async def imagecache_with_stopevent(bootstrap):
6475
config = bootstrap
6576
dbdir = config.testdir.joinpath('imagecache')
6677
dbdir.mkdir()
78+
created_caches = []
6779

6880
def _create_imagecache(stopevent=None):
69-
return nowplaying.imagecache.ImageCache(cachedir=dbdir, stopevent=stopevent)
81+
cache = nowplaying.imagecache.ImageCache(cachedir=dbdir, stopevent=stopevent)
82+
created_caches.append(cache)
83+
return cache
7084

7185
yield _create_imagecache
7286

87+
# Cleanup: close all created caches to release file handles
88+
for cache in created_caches:
89+
with contextlib.suppress(Exception):
90+
if hasattr(cache, 'close'):
91+
cache.close()
92+
# Force close any database connections
93+
if hasattr(cache, 'databasefile'):
94+
with contextlib.suppress(sqlite3.Error, Exception):
95+
conn = sqlite3.connect(cache.databasefile)
96+
conn.close()
97+
7398

7499
@pytest.mark.skipif(sys.platform == "win32", reason="Windows cannot close fast enough")
75100
@pytest.mark.asyncio

tests/test_subprocesses.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,23 @@ def test_windows_process_termination_timeout(subprocess_manager):
327327
''' Test that Windows gets longer termination timeouts '''
328328
class WindowsSlowProcess(MockProcess):
329329
''' Simulate Windows process that's slow to terminate '''
330+
def __init__(self, *args, **kwargs):
331+
super().__init__(*args, **kwargs)
332+
self._join_call_count = 0
333+
330334
def join(self, timeout=None):
335+
''' Mock process join for Windows slow termination '''
331336
# On Windows, simulate that termination takes longer
332-
if timeout and timeout >= 7: # Our Windows timeout
337+
# First call (graceful shutdown with 8s timeout) - process stays alive
338+
# Second call (after terminate, with 7s timeout) - process dies
339+
self._join_call_count += 1
340+
341+
if self._join_call_count == 1:
342+
# First call - graceful shutdown fails, process stays alive
343+
pass
344+
elif self._join_call_count >= 2 and timeout and timeout >= 7:
345+
# Second call after terminate - process dies
333346
self._alive = False
334-
# If timeout is too short, process stays alive
335347

336348
mock_process = WindowsSlowProcess(name='trackpoll')
337349
subprocess_manager.processes['trackpoll']['process'] = mock_process

0 commit comments

Comments
 (0)