From 35285e0c88c0652e602a91e03c4a2bf6b493d7c6 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 13 Apr 2021 10:29:52 +0200 Subject: Use f-strings in tests Change-Id: I52f92326fdd903078cce5b6408d96d742bfa42b8 Reviewed-by: Cristian Maureira-Fredes --- sources/pyside6/tests/QtCore/qobject_parent_test.py | 8 +++----- sources/pyside6/tests/QtCore/qthread_prod_cons_test.py | 4 ++-- sources/pyside6/tests/QtNetwork/accessManager_test.py | 3 ++- sources/pyside6/tests/QtWidgets/bug_400.py | 2 +- sources/pyside6/tests/QtWidgets/bug_711.py | 2 +- sources/pyside6/tests/QtWidgets/bug_778.py | 4 ++-- sources/pyside6/tests/QtWidgets/bug_854.py | 4 +++- sources/pyside6/tests/QtWidgets/qstandarditemmodel_test.py | 2 +- sources/pyside6/tests/registry/existence_test.py | 2 +- sources/pyside6/tests/registry/scrape_testresults.py | 2 +- sources/pyside6/tests/tools/list-class-hierarchy.py | 2 +- sources/pyside6/tests/util/color.py | 5 ++--- sources/shiboken6/tests/samplebinding/python_thread_test.py | 4 ++-- 13 files changed, 22 insertions(+), 22 deletions(-) diff --git a/sources/pyside6/tests/QtCore/qobject_parent_test.py b/sources/pyside6/tests/QtCore/qobject_parent_test.py index 776d34461..941766acf 100644 --- a/sources/pyside6/tests/QtCore/qobject_parent_test.py +++ b/sources/pyside6/tests/QtCore/qobject_parent_test.py @@ -103,22 +103,20 @@ class ParentCase(unittest.TestCase): def testFindChild(self): #QObject.findChild() with all QObject parent = QObject() - name = 'object%d' children = [QObject(parent) for i in range(20)] for i, child in enumerate(children): - child.setObjectName(name % i) + child.setObjectName(f'object{i}') for i, child in enumerate(children): - self.assertEqual(child, parent.findChild(QObject, name % i)) + self.assertEqual(child, parent.findChild(QObject, f'object{i}')) def testFindChildWithoutName(self): parent = QObject() - name = 'object%d' children = [QObject(parent) for i in range(20)] for i, child in enumerate(children): - child.setObjectName(name % i) + child.setObjectName(f'object{i}') child = parent.findChild(QObject) self.assertTrue(isinstance(child, QObject)) diff --git a/sources/pyside6/tests/QtCore/qthread_prod_cons_test.py b/sources/pyside6/tests/QtCore/qthread_prod_cons_test.py index 05ea4da04..586a484fe 100644 --- a/sources/pyside6/tests/QtCore/qthread_prod_cons_test.py +++ b/sources/pyside6/tests/QtCore/qthread_prod_cons_test.py @@ -77,7 +77,7 @@ class Producer(QThread): value = int(random()*10) % 10 self.bucket.push(value) self.production_list.append(value) - logging.debug('PRODUCER - pushed %d' % value) + logging.debug(f'PRODUCER - pushed {value}') self.runs += 1 self.msleep(5) @@ -98,7 +98,7 @@ class Consumer(QThread): try: value = self.bucket.pop() self.consumption_list.append(value) - logging.debug('CONSUMER - got %d' % value) + logging.debug(f'CONSUMER - got {value}') self.runs += 1 except IndexError: logging.debug('CONSUMER - empty bucket') diff --git a/sources/pyside6/tests/QtNetwork/accessManager_test.py b/sources/pyside6/tests/QtNetwork/accessManager_test.py index cea54f8d3..c2e02f673 100644 --- a/sources/pyside6/tests/QtNetwork/accessManager_test.py +++ b/sources/pyside6/tests/QtNetwork/accessManager_test.py @@ -70,7 +70,8 @@ class AccessManagerCase(UsesQCoreApplication): def testNetworkRequest(self): manager = QNetworkAccessManager() manager.finished.connect(self.slot_replyFinished) - manager.get(QNetworkRequest(QUrl("http://127.0.0.1:%s" % self.httpd.port()))) + port = self.httpd.port() + manager.get(QNetworkRequest(QUrl(f"http://127.0.0.1:{port}"))) self.app.exec_() self.assertTrue(self.called) diff --git a/sources/pyside6/tests/QtWidgets/bug_400.py b/sources/pyside6/tests/QtWidgets/bug_400.py index 1e308db11..7f067a09a 100644 --- a/sources/pyside6/tests/QtWidgets/bug_400.py +++ b/sources/pyside6/tests/QtWidgets/bug_400.py @@ -46,7 +46,7 @@ class BugTest(UsesQApplication): treeWidget.setColumnCount(1) items = [] for i in range(10): - items.append(QTreeWidgetItem(None, ["item: %i" % i])) + items.append(QTreeWidgetItem(None, [f"item: {i}"])) treeWidget.insertTopLevelItems(0, items); _iter = QTreeWidgetItemIterator(treeWidget) diff --git a/sources/pyside6/tests/QtWidgets/bug_711.py b/sources/pyside6/tests/QtWidgets/bug_711.py index 71f56144e..e78fe85b6 100644 --- a/sources/pyside6/tests/QtWidgets/bug_711.py +++ b/sources/pyside6/tests/QtWidgets/bug_711.py @@ -43,7 +43,7 @@ class TestLabelPixmap(unittest.TestCase): toolbar = QToolBar() for i in range(20): - toolbar.addAction(QAction("Action %d" % i, None)) + toolbar.addAction(QAction(f"Action {i}")) buttons = toolbar.findChildren(QToolButton, "") toolbar.clear() diff --git a/sources/pyside6/tests/QtWidgets/bug_778.py b/sources/pyside6/tests/QtWidgets/bug_778.py index f1325d9a2..fc52ce705 100644 --- a/sources/pyside6/tests/QtWidgets/bug_778.py +++ b/sources/pyside6/tests/QtWidgets/bug_778.py @@ -45,12 +45,12 @@ class QTreeWidgetItemIteratorTest(UsesQApplication): treeWidget.setColumnCount(1) items = [] for i in range(10): - items.append(QTreeWidgetItem(None, ['item: %d' % i])) + items.append(QTreeWidgetItem(None, [f'item: {i}'])) treeWidget.insertTopLevelItems(0, items) index = 0 for it in QTreeWidgetItemIterator(treeWidget): - self.assertEqual(it.value().text(0), 'item: %d' % index) + self.assertEqual(it.value().text(0), f'item: {index}') index += 1 if __name__ == '__main__': diff --git a/sources/pyside6/tests/QtWidgets/bug_854.py b/sources/pyside6/tests/QtWidgets/bug_854.py index 103018754..6ce2b653e 100644 --- a/sources/pyside6/tests/QtWidgets/bug_854.py +++ b/sources/pyside6/tests/QtWidgets/bug_854.py @@ -59,7 +59,9 @@ class VirtualList(QAbstractItemModel): return QModelIndex() def data(self, index, role): - return "(%i, %i)" % (index.row(), index.column()) + row = index.row() + col = index.column() + return f"({row}, {col})" class TestQAbstractItemModel(UsesQApplication): diff --git a/sources/pyside6/tests/QtWidgets/qstandarditemmodel_test.py b/sources/pyside6/tests/QtWidgets/qstandarditemmodel_test.py index 7e55246bf..2061f174d 100644 --- a/sources/pyside6/tests/QtWidgets/qstandarditemmodel_test.py +++ b/sources/pyside6/tests/QtWidgets/qstandarditemmodel_test.py @@ -72,7 +72,7 @@ class QStandardItemModelRef(UsesQApplication): for r in range(5): row = [] for c in range(5): - row.append(QStandardItem("%d,%d" % (r,c)) ) + row.append(QStandardItem(f"{r},{c}")) self.assertEqual(sys.getrefcount(row[c]), 2) model.insertRow(r, row) diff --git a/sources/pyside6/tests/registry/existence_test.py b/sources/pyside6/tests/registry/existence_test.py index 38bba4576..a6121381d 100644 --- a/sources/pyside6/tests/registry/existence_test.py +++ b/sources/pyside6/tests/registry/existence_test.py @@ -154,7 +154,7 @@ class TestSignaturesExists(unittest.TestCase): # We should fix them. continue if key not in found_sigs: - warn("missing key: '{} value={}'".format(key, value), stacklevel=3) + warn(f"missing key: '{key} value={value}'", stacklevel=3) else: found_val = found_sigs[key] if type(value) is list and ( diff --git a/sources/pyside6/tests/registry/scrape_testresults.py b/sources/pyside6/tests/registry/scrape_testresults.py index e0f451d10..07e44199d 100644 --- a/sources/pyside6/tests/registry/scrape_testresults.py +++ b/sources/pyside6/tests/registry/scrape_testresults.py @@ -320,7 +320,7 @@ def get_test_results(starturl): hours, remainder = divmod(runtime, 3600) minutes, seconds = divmod(remainder, 60) - runtime_formatted = '%d:%02d:%06.3f' % (hours, minutes, seconds) + runtime_formatted = f'{hours}:{minutes:%02d}:{seconds:%06.3f}' print(f"Run time: {runtime_formatted}s") if ok: found = eval_data() diff --git a/sources/pyside6/tests/tools/list-class-hierarchy.py b/sources/pyside6/tests/tools/list-class-hierarchy.py index 49ce53d25..03b49bbb4 100644 --- a/sources/pyside6/tests/tools/list-class-hierarchy.py +++ b/sources/pyside6/tests/tools/list-class-hierarchy.py @@ -102,7 +102,7 @@ if __name__=='__main__': sip.setapi('QVariant',2) for m in modules: - exec("from %s import %s" % (l,m), globals(), locals()) + exec(f"from {l} import {m}", globals(), locals()) dictionary += recurse_into(m, eval(m)) librarySymbols[l] = dictionary diff --git a/sources/pyside6/tests/util/color.py b/sources/pyside6/tests/util/color.py index b2637dd90..1602fbb00 100644 --- a/sources/pyside6/tests/util/color.py +++ b/sources/pyside6/tests/util/color.py @@ -28,10 +28,9 @@ '''Function to print a colored line to terminal''' -RED='\033[0;31m%s\033[m' -def print_colored(message, color=RED): - print(color % message) +def print_colored(message): + print(f'\033[0;31m{message}\033[m') # red if __name__ == '__main__': print('42 - the answer') diff --git a/sources/shiboken6/tests/samplebinding/python_thread_test.py b/sources/shiboken6/tests/samplebinding/python_thread_test.py index ca0508182..7b5b773e8 100644 --- a/sources/shiboken6/tests/samplebinding/python_thread_test.py +++ b/sources/shiboken6/tests/samplebinding/python_thread_test.py @@ -64,7 +64,7 @@ class Producer(threading.Thread): value = int(random()*10) % 10 self.bucket.push(value) self.production_list.append(value) - logging.debug('PRODUCER - pushed %d' % value) + logging.debug(f'PRODUCER - pushed {value}') self.runs += 1 #self.msleep(5) time.sleep(0.01) @@ -85,7 +85,7 @@ class Consumer(threading.Thread): if not self.bucket.empty(): value = self.bucket.pop() self.consumption_list.append(value) - logging.debug('CONSUMER - got %d' % value) + logging.debug(f'CONSUMER - got {value}') self.runs += 1 else: logging.debug('CONSUMER - empty bucket') -- cgit v1.2.3