22Tests for state persistence functionality.
33"""
44
5- import unittest
6- from unittest .mock import patch , MagicMock
75import json
86import random
7+ import unittest
8+ from unittest .mock import MagicMock , patch
9+
10+ from src .core import game_logic
11+ from src .utils .file_operations import read_phrases_file
912
1013# Don't import nicegui directly since we'll mock it
1114# from nicegui import app
1215
13- from src .core import game_logic
14- from src .utils .file_operations import read_phrases_file
1516
1617
1718class TestStatePersistence (unittest .TestCase ):
@@ -287,7 +288,7 @@ class TestStateSync(unittest.TestCase):
287288 def test_nicegui_211_compatibility (self ):
288289 """Test compatibility with NiceGUI 2.11+ (no use of ui.broadcast)."""
289290 import inspect
290-
291+
291292 # Check game_logic.py for ui.broadcast references
292293 import src .core .game_logic as game_logic
293294 source_code = inspect .getsource (game_logic )
@@ -300,8 +301,8 @@ def test_nicegui_211_compatibility(self):
300301
301302 def test_view_synchronization (self ):
302303 """Test that state is synchronized between home and stream views."""
303- from unittest .mock import patch , MagicMock , call
304-
304+ from unittest .mock import MagicMock , call , patch
305+
305306 # Mock the required components
306307 mock_ui = MagicMock ()
307308 mock_board_views = {
@@ -340,8 +341,8 @@ def test_view_synchronization(self):
340341
341342 def test_toggle_updates_all_clients (self ):
342343 """Test that toggling a tile updates all connected clients."""
343- from unittest .mock import patch , MagicMock , call
344-
344+ from unittest .mock import MagicMock , call , patch
345+
345346 # Mock clicked_tiles and board for simplicity
346347 mock_clicked_tiles = set ()
347348 mock_board = [["Phrase" ]]
@@ -384,9 +385,9 @@ class TestActiveUsers(unittest.TestCase):
384385
385386 def test_user_connection_tracking (self ):
386387 """Test that user connections are properly tracked."""
387- from unittest .mock import patch , MagicMock
388388 import json
389-
389+ from unittest .mock import MagicMock , patch
390+
390391 # Create fresh dictionaries for test isolation
391392 test_connected_clients = {
392393 "/" : set (),
@@ -414,8 +415,8 @@ def test_user_connection_tracking(self):
414415 patch ('src.ui.routes.active_home_users' , 0 , create = True ):
415416
416417 # Import the functions we want to test
417- from src .ui .routes import home_page , health
418-
418+ from src .ui .routes import health , home_page
419+
419420 # Create a dummy view container
420421 mock_ui .card .return_value .__enter__ .return_value = mock_ui .card .return_value
421422 mock_ui .label .return_value = MagicMock ()
@@ -444,8 +445,8 @@ class TestMobileUI(unittest.TestCase):
444445
445446 def test_buttons_have_text (self ):
446447 """Test that control buttons have both text and icons."""
447- from unittest .mock import patch , MagicMock
448-
448+ from unittest .mock import MagicMock , patch
449+
449450 # Create mocks
450451 mock_ui = MagicMock ()
451452 mock_button = MagicMock ()
0 commit comments