From 1cf79beeb8eb109e2b38708fff24347e1968e8ff Mon Sep 17 00:00:00 2001 From: Loren Eteval Date: Wed, 7 Oct 2026 09:57:52 +0800 Subject: [PATCH] Improve logical block spacing Signed-off-by: Loren Eteval --- Furious/Widget/ServerTableView.py | 2 ++ tests/test_metrics_behavior.py | 4 ++++ tests/test_qt_interactions.py | 26 ++++++++++++++++++++++++++ tests/test_repository_contracts.py | 3 +++ tests/test_stylesheet_states.py | 5 +++++ tests/test_ui_behavior.py | 13 +++++++++++++ 6 files changed, 53 insertions(+) diff --git a/Furious/Widget/ServerTableView.py b/Furious/Widget/ServerTableView.py index 3f18f675..20c02a78 100644 --- a/Furious/Widget/ServerTableView.py +++ b/Furious/Widget/ServerTableView.py @@ -400,6 +400,7 @@ class DuplicateServersProgressDialog(AppQTransientDialog): self.finishedDuplication = True self.profileIds = [] + self.accept() def retranslate(self): @@ -1487,6 +1488,7 @@ class ServerTableView( """Change metadata without replacing profiles or disturbing live runtimes.""" selected = self._selectedProfileIds() current = self._currentProfileId() + changed = set(Storage.setUserServersFavorite(selected, favorite)) if not changed: diff --git a/tests/test_metrics_behavior.py b/tests/test_metrics_behavior.py index b852fe0c..e89a3806 100644 --- a/tests/test_metrics_behavior.py +++ b/tests/test_metrics_behavior.py @@ -202,14 +202,17 @@ class MetricsPageAndGraphTest(unittest.TestCase): def testGlobalRetranslationRefreshesEndpointOnceWithoutChangingHistory(self): with isolatedSettings(): AppSettings.set('Language', 'EN') + manager = MetricsHistory() page = MetricsPage(manager) + manager.recordSample({DOWNLOAD_SPEED_METRIC: 32}) samples = manager.rawSamples() try: for locale in ('RU', 'ZH', 'EN'): AppSettings.set('Language', locale) + with mock.patch.object( page.endpointInfoWidget, 'retranslate', @@ -217,6 +220,7 @@ class MetricsPageAndGraphTest(unittest.TestCase): ) as translate: Mixins.QTranslatable.retranslateAll() self.assertEqual(translate.call_count, 1) + self.assertEqual( page.metricsCard.downloadTitleLabel.text(), _('Download') ) diff --git a/tests/test_qt_interactions.py b/tests/test_qt_interactions.py index 0a28e330..241d440f 100644 --- a/tests/test_qt_interactions.py +++ b/tests/test_qt_interactions.py @@ -2116,6 +2116,7 @@ class ProfileMutationBatchTest(unittest.TestCase): profiles[0].metadata.subscriptionManaged = True profiles[0].metadata.subscriptionProfileKey = 'remote-key' profiles[1].metadata.subscriptionSource = 'group-b' + table.selectAll() metadataChanged = QSignalSpy(table.sourceModel.dataChanged) @@ -2128,17 +2129,24 @@ class ProfileMutationBatchTest(unittest.TestCase): if not action.isSeparator() and action.textCompare('Add to Favorites') ) + add.trigger() + self.assertTrue(all(profile.metadata.favorite for profile in profiles)) self.assertEqual(metadataChanged.count(), 1) + add.trigger() + self.assertEqual(metadataChanged.count(), 1) + table.filterFavorites(True) table.filterBySubscription('group-a') table.search('profile-0000') + self.assertEqual( table._visibleProfileIds(), [profiles[0].metadata.profileId] ) + table.selectAll() remove = next( action @@ -2147,6 +2155,7 @@ class ProfileMutationBatchTest(unittest.TestCase): and action.textCompare('Remove from Favorites') ) remove.trigger() + self.assertEqual(table.proxyModel.rowCount(), 0) self.assertEqual(table._selectedProfileIds(), []) self.assertIs(Storage.UserServers()[0], profiles[0]) @@ -2155,7 +2164,9 @@ class ProfileMutationBatchTest(unittest.TestCase): ) self.assertEqual(Storage.UserActivatedItemIndex(), 3) controller.startReconnection.assert_not_called() + table.filterFavorites(False) + self.assertEqual( table._visibleProfileIds(), [profiles[0].metadata.profileId] ) @@ -2163,11 +2174,13 @@ class ProfileMutationBatchTest(unittest.TestCase): def testSmallDuplicationPublishesOneBatchOfIndependentManualCopies(self): with self.table(4) as (table, controller): originals = list(Storage.UserServers()) + for profile in originals: profile.metadata.subscriptionSource = 'group-a' profile.metadata.subscriptionManaged = True profile.metadata.subscriptionProfileKey = profile.metadata.profileId originals[0].metadata.favorite = True + table.sourceModel.sort(0, QtCore.Qt.DescendingOrder) table.search('000[01]') table.selectAll() @@ -2238,6 +2251,7 @@ class ProfileMutationBatchTest(unittest.TestCase): self.assertEqual(dialog.copiedCount, 3) self.assertTrue(dialog.finishedDuplication) self.assertEqual(dialog.profileIds, []) + originalIds = {profile.metadata.profileId for profile in originals} copies = [ profile @@ -2245,6 +2259,7 @@ class ProfileMutationBatchTest(unittest.TestCase): if profile.metadata.profileId not in originalIds and profile.itemRemark != 'newcomer' ] + self.assertEqual( sorted(profile.itemRemark for profile in copies), ['profile-0000', 'profile-0001', 'profile-0003'], @@ -2314,20 +2329,27 @@ class ProfileMutationBatchTest(unittest.TestCase): table.selectAll() table.duplicateSelectedItem() dialog = table.findChild(DuplicateServersProgressDialog) + self.assertIsNotNone(dialog) self.assertTrue(waitFor(lambda: dialog.copiedCount > 0)) + QTest.mouseClick(dialog.cancelButton, QtCore.Qt.LeftButton) + self.assertTrue(waitFor(lambda: not isValid(dialog))) self.assertLess(len(Storage.UserServers()), 2000) + count = len(Storage.UserServers()) table.duplicateSelectedItem() pending = table.findChild(DuplicateServersProgressDialog) + self.assertIsNotNone(pending) + table.deleteLater() QtCore.QCoreApplication.sendPostedEvents( table, QtCore.QEvent.DeferredDelete ) processQtEvents() + self.assertFalse(isValid(pending)) self.assertEqual(len(Storage.UserServers()), count) @@ -2337,6 +2359,7 @@ class ProfileMutationBatchTest(unittest.TestCase): table.duplicateSelectedItem() dialog = table.findChild(DuplicateServersProgressDialog) self.assertIsNotNone(dialog) + table.cleanup() processQtEvents() @@ -2346,6 +2369,7 @@ class ProfileMutationBatchTest(unittest.TestCase): def testProgressDialogsUseSharedRetranslationWithoutLosingProgress(self): with self.table(10) as (table, controller): AppSettings.set('Language', 'EN') + dialogs = ( ( ImportURIsProgressDialog(('fixture',) * 10, parent=table), @@ -2372,6 +2396,7 @@ class ProfileMutationBatchTest(unittest.TestCase): for locale in ('RU', 'ZH', 'EN'): AppSettings.set('Language', locale) + with ExitStack() as stack: translations = [ stack.enter_context( @@ -2383,6 +2408,7 @@ class ProfileMutationBatchTest(unittest.TestCase): ) for dialog, *_fields in dialogs ] + Mixins.QTranslatable.retranslateAll() for (dialog, title, status, counter), translated in zip( diff --git a/tests/test_repository_contracts.py b/tests/test_repository_contracts.py index 8ea1445d..93ff14b1 100644 --- a/tests/test_repository_contracts.py +++ b/tests/test_repository_contracts.py @@ -102,8 +102,10 @@ class RepositoryContractTest(unittest.TestCase): self.assertIs(repository.data()[1], profiles[0]) self.assertEqual(dict(profiles[0].connection), originalConnection) self.assertFalse(profiles[1].metadata.favorite) + repository.sync() restored = UserServers().data() + self.assertEqual( [profile.metadata.profileId for profile in restored], [profile.metadata.profileId for profile in repository.data()], @@ -111,6 +113,7 @@ class RepositoryContractTest(unittest.TestCase): self.assertEqual( [profile.metadata.favorite for profile in restored], [False, True] ) + self.assertEqual(repository.setProfilesFavorite([unique], False), [unique]) def testRoutingRepositoryRoundTripPreservesUnknownDocuments(self): diff --git a/tests/test_stylesheet_states.py b/tests/test_stylesheet_states.py index 41086e08..efad2c43 100644 --- a/tests/test_stylesheet_states.py +++ b/tests/test_stylesheet_states.py @@ -77,15 +77,20 @@ class StyleSheetStateRenderingTest(unittest.TestCase): try: button.show() processQtEvents() + point = (button.width() - 12, button.height() // 2) unchecked = button.grab().toImage().pixelColor(*point) + button.setChecked(True) checked = button.grab().toImage().pixelColor(*point) + self.assertNotEqual(checked, unchecked) self.assertEqual( checked, QColor(AppStyleSheet.Palettes[theme]['accent_soft']) ) + button.setChecked(False) + self.assertEqual( button.grab().toImage().pixelColor(*point), unchecked ) diff --git a/tests/test_ui_behavior.py b/tests/test_ui_behavior.py index ca8bf0be..38ce5526 100644 --- a/tests/test_ui_behavior.py +++ b/tests/test_ui_behavior.py @@ -2981,6 +2981,7 @@ class DialogBehaviorTest(unittest.TestCase): def testCustomMessageRetranslationKeepsPayloadAndUpdatesDialogControls(self): with isolatedSettings(): AppSettings.set('Language', 'EN') + box = MBoxImportError() box.setWindowTitle(_('Duplicate')) box.setHeading(_('Delete')) @@ -2992,6 +2993,7 @@ class DialogBehaviorTest(unittest.TestCase): for locale in ('RU', 'ZH', 'EN'): AppSettings.set('Language', locale) Mixins.QTranslatable.retranslateAll() + self.assertEqual(box.windowTitle(), _('Duplicate')) self.assertEqual(box.heading(), _('Delete')) self.assertEqual(box.text(), _('Invalid data')) @@ -3018,11 +3020,13 @@ class DialogBehaviorTest(unittest.TestCase): try: for locale in ('RU', 'ZH', 'EN'): AppSettings.set('Language', locale) + with mock.patch.object( managed, 'retranslate', wraps=managed.retranslate ) as translate: Mixins.QTranslatable.retranslateAll() self.assertEqual(translate.call_count, 1) + self.assertEqual(protected.text(), 'Cancel') self.assertEqual(managed.text(), _('Save')) self.assertEqual(plain.text(), _('Cancel')) @@ -3033,6 +3037,7 @@ class DialogBehaviorTest(unittest.TestCase): def testActionRetranslationLeavesManagedChildrenToTheirOwnPass(self): with isolatedSettings(): AppSettings.set('Language', 'EN') + owner = QWidget() menu = AppQMenu(parent=owner) managed = AppQAction('Save', parent=menu) @@ -3043,19 +3048,23 @@ class DialogBehaviorTest(unittest.TestCase): try: for locale in ('RU', 'ZH', 'EN'): AppSettings.set('Language', locale) + with mock.patch.object( managed, 'setText', wraps=managed.setText ) as update: Mixins.QTranslatable.retranslateAll() self.assertEqual(update.call_count, 1) + self.assertEqual(parent.text(), _('Server')) self.assertEqual(managed.text(), _('Save')) self.assertEqual(protected.text(), 'Cancel') plain = QAction('Cancel', menu) menu.addAction(plain) + AppSettings.set('Language', 'ZH') Mixins.QTranslatable.retranslateAll() + self.assertEqual(plain.text(), _('Cancel')) finally: owner.deleteLater() @@ -3064,6 +3073,7 @@ class DialogBehaviorTest(unittest.TestCase): def testMessageGeometryRefreshesAfterManagedButtonTranslation(self): with isolatedSettings(): AppSettings.set('Language', 'EN') + box = AppQMessageBox() button = AppQPushButton(_('Copy Error')) box.addButton(button, box.ButtonRole.ActionRole) @@ -3075,6 +3085,7 @@ class DialogBehaviorTest(unittest.TestCase): AppSettings.set('Language', locale) Mixins.QTranslatable.retranslateAll() processQtEvents() + self.assertEqual(button.text(), _('Copy Error')) self.assertGreaterEqual( button.width(), box._preferredButtonWidth(button) @@ -3083,8 +3094,10 @@ class DialogBehaviorTest(unittest.TestCase): AppSettings.set('Language', 'RU') Mixins.QTranslatable.retranslateAll() + deleteQObject(box) processQtEvents() + self.assertFalse(isValid(box)) finally: if isValid(box):