From bea95c0edfbc81fd9281001f85de7027f626ec95 Mon Sep 17 00:00:00 2001 From: Wolfgang Fahl Date: Sat, 27 Jul 2024 10:57:27 +0200 Subject: [PATCH] reformats --- tests/basetest.py | 1 + tests/test_MediaWikiTable.py | 1 + tests/test_SMWApi.py | 38 ++++++++++++++++++++++-------------- tests/test_Selector.py | 1 + tests/test_WikiPush.py | 1 + tests/test_WikiUser.py | 1 + tests/test_duckinterface.py | 1 + tests/test_lambda.py | 1 + tests/test_sso.py | 1 + tests/test_wikibot.py | 1 + tests/test_wikiclient.py | 1 + tests/test_wikiquery.py | 1 + wikibot3rd/crypt.py | 1 + wikibot3rd/lambda_action.py | 1 + wikibot3rd/smw.py | 7 +++---- wikibot3rd/sso.py | 1 + wikibot3rd/version.py | 1 + wikibot3rd/wikiaction.py | 1 + wikibot3rd/wikibackup.py | 1 + wikibot3rd/wikibot.py | 1 + wikibot3rd/wikiedit.py | 1 + wikibot3rd/wikinuke.py | 1 + wikibot3rd/wikipush.py | 8 +++++--- wikibot3rd/wikiquery.py | 1 + wikibot3rd/wikirestore.py | 1 + wikibot3rd/wikitext.py | 1 + wikibot3rd/wikiupload.py | 1 + 27 files changed, 55 insertions(+), 22 deletions(-) diff --git a/tests/basetest.py b/tests/basetest.py index 26ca79b..a15897f 100644 --- a/tests/basetest.py +++ b/tests/basetest.py @@ -3,6 +3,7 @@ @author: wf """ + import getpass import os import time diff --git a/tests/test_MediaWikiTable.py b/tests/test_MediaWikiTable.py index c00927d..5b408bb 100644 --- a/tests/test_MediaWikiTable.py +++ b/tests/test_MediaWikiTable.py @@ -3,6 +3,7 @@ @author: wf """ + import unittest from datetime import date, datetime diff --git a/tests/test_SMWApi.py b/tests/test_SMWApi.py index bdb796e..2724524 100644 --- a/tests/test_SMWApi.py +++ b/tests/test_SMWApi.py @@ -3,6 +3,7 @@ @author: wf """ + import unittest from datetime import datetime from unittest.mock import patch @@ -432,11 +433,12 @@ def _askForAllResults_mock_sideEffect(query, limit): if query == expectedQuery: return [RESULT_N(i)] - with patch( - "wikibot3rd.smw.SMWClient.askForAllResults" - ) as askForAllResults_mock, patch( - "wikibot3rd.smw.SMWClient.getBoundariesOfQuery" - ) as getBoundariesOfQuery: + with ( + patch("wikibot3rd.smw.SMWClient.askForAllResults") as askForAllResults_mock, + patch( + "wikibot3rd.smw.SMWClient.getBoundariesOfQuery" + ) as getBoundariesOfQuery, + ): getBoundariesOfQuery.return_value = ( datetime.strptime("01/01/2020 00:00:00", "%d/%m/%Y %H:%M:%S"), datetime.strptime("11/01/2020 00:00:00", "%d/%m/%Y %H:%M:%S"), @@ -528,11 +530,14 @@ def askForAllResults_mock_side_effect(query, limit=None, kwargs={}): for smw in self.getSMWs(): if isinstance(smw, SMWClient): # Test default case - with patch( - "wikibot3rd.smw.SMWClient.askForAllResults" - ) as askForAllResults_mock, patch( - "wikibot3rd.smw.SMWClient.askPartitionQuery" - ) as askPartitionQuery_mock: + with ( + patch( + "wikibot3rd.smw.SMWClient.askForAllResults" + ) as askForAllResults_mock, + patch( + "wikibot3rd.smw.SMWClient.askPartitionQuery" + ) as askPartitionQuery_mock, + ): askForAllResults_mock.return_value = [RESULT] askPartitionQuery_mock.return_value = None result = smw.ask(QUERY) @@ -541,11 +546,14 @@ def askForAllResults_mock_side_effect(query, limit=None, kwargs={}): self.assertEqual(askPartitionQuery_mock.call_count, 0) # Test if query division is used if 'queryDivision' attribute is set above 1 smw.queryDivision = 10 - with patch( - "wikibot3rd.smw.SMWClient.askForAllResults" - ) as askForAllResults_mock, patch( - "wikibot3rd.smw.SMWClient.askPartitionQuery" - ) as askPartitionQuery_mock: + with ( + patch( + "wikibot3rd.smw.SMWClient.askForAllResults" + ) as askForAllResults_mock, + patch( + "wikibot3rd.smw.SMWClient.askPartitionQuery" + ) as askPartitionQuery_mock, + ): askForAllResults_mock.return_value = None askPartitionQuery_mock.return_value = [RESULT] result = smw.ask(QUERY) diff --git a/tests/test_Selector.py b/tests/test_Selector.py index 75186f8..cb871ce 100644 --- a/tests/test_Selector.py +++ b/tests/test_Selector.py @@ -2,6 +2,7 @@ Created on 2020-12-20 @author: wf """ + import getpass import logging import sys diff --git a/tests/test_WikiPush.py b/tests/test_WikiPush.py index c4f99b3..2309b47 100644 --- a/tests/test_WikiPush.py +++ b/tests/test_WikiPush.py @@ -3,6 +3,7 @@ @author: wf """ + import io import os import unittest diff --git a/tests/test_WikiUser.py b/tests/test_WikiUser.py index f380176..62465f0 100644 --- a/tests/test_WikiUser.py +++ b/tests/test_WikiUser.py @@ -3,6 +3,7 @@ @author: wf """ + import os import tempfile import unittest diff --git a/tests/test_duckinterface.py b/tests/test_duckinterface.py index 71ec910..7a9c38a 100644 --- a/tests/test_duckinterface.py +++ b/tests/test_duckinterface.py @@ -3,6 +3,7 @@ @author: wf """ + import unittest from tests.basetest import BaseTest diff --git a/tests/test_lambda.py b/tests/test_lambda.py index 0486ac5..0b6e737 100644 --- a/tests/test_lambda.py +++ b/tests/test_lambda.py @@ -3,6 +3,7 @@ @author: wf """ + import unittest from lodstorage.query import Query diff --git a/tests/test_sso.py b/tests/test_sso.py index 1306aef..30a677e 100644 --- a/tests/test_sso.py +++ b/tests/test_sso.py @@ -3,6 +3,7 @@ @author: wf """ + import os import yaml diff --git a/tests/test_wikibot.py b/tests/test_wikibot.py index e7d5fcb..6486877 100644 --- a/tests/test_wikibot.py +++ b/tests/test_wikibot.py @@ -3,6 +3,7 @@ @author: wf """ + import unittest from tests.basetest import BaseTest diff --git a/tests/test_wikiclient.py b/tests/test_wikiclient.py index 1d50060..0a67cb2 100644 --- a/tests/test_wikiclient.py +++ b/tests/test_wikiclient.py @@ -3,6 +3,7 @@ @author: wf """ + from tests.basetest import BaseTest from wikibot3rd.wikiclient import WikiClient diff --git a/tests/test_wikiquery.py b/tests/test_wikiquery.py index 3215a94..b3555b5 100644 --- a/tests/test_wikiquery.py +++ b/tests/test_wikiquery.py @@ -3,6 +3,7 @@ @author: wf """ + import json import unittest from contextlib import redirect_stdout diff --git a/wikibot3rd/crypt.py b/wikibot3rd/crypt.py index 95bfdf1..b033981 100644 --- a/wikibot3rd/crypt.py +++ b/wikibot3rd/crypt.py @@ -3,6 +3,7 @@ @author: wf """ + import base64 import os import secrets diff --git a/wikibot3rd/lambda_action.py b/wikibot3rd/lambda_action.py index 755a31f..9a792ed 100644 --- a/wikibot3rd/lambda_action.py +++ b/wikibot3rd/lambda_action.py @@ -3,6 +3,7 @@ @author: wf """ + import html import re diff --git a/wikibot3rd/smw.py b/wikibot3rd/smw.py index 19c3a3e..d94f091 100644 --- a/wikibot3rd/smw.py +++ b/wikibot3rd/smw.py @@ -3,6 +3,7 @@ @author: wf """ + import re import sys from datetime import datetime @@ -501,10 +502,8 @@ def askForAllResults(self, query, limit=None, kwargs={}): Raises: QueryResultSizeExceedException: Raised if not all results can be retrieved """ - endShowProgress = ( - lambda showProgress, c: print("\n" if not c % 80 == 0 else "") - if showProgress - else None + endShowProgress = lambda showProgress, c: ( + print("\n" if not c % 80 == 0 else "") if showProgress else None ) offset = 0 done = False diff --git a/wikibot3rd/sso.py b/wikibot3rd/sso.py index 05af489..55ed016 100644 --- a/wikibot3rd/sso.py +++ b/wikibot3rd/sso.py @@ -5,6 +5,7 @@ with ChatGPT-4 prompting """ + import base64 import hashlib import socket diff --git a/wikibot3rd/version.py b/wikibot3rd/version.py index f35ab9f..0e930f9 100644 --- a/wikibot3rd/version.py +++ b/wikibot3rd/version.py @@ -3,6 +3,7 @@ @author: wf """ + import wikibot3rd diff --git a/wikibot3rd/wikiaction.py b/wikibot3rd/wikiaction.py index eaf4611..792effa 100644 --- a/wikibot3rd/wikiaction.py +++ b/wikibot3rd/wikiaction.py @@ -3,6 +3,7 @@ @author: wf """ + from lodstorage.query import Query from wikibot3rd.lambda_action import Code, LambdaAction diff --git a/wikibot3rd/wikibackup.py b/wikibot3rd/wikibackup.py index 3f17677..7bcd9af 100644 --- a/wikibot3rd/wikibackup.py +++ b/wikibot3rd/wikibackup.py @@ -3,6 +3,7 @@ @author: wf """ + import sys import wikibot3rd.wikipush diff --git a/wikibot3rd/wikibot.py b/wikibot3rd/wikibot.py index 5bf0634..9786214 100644 --- a/wikibot3rd/wikibot.py +++ b/wikibot3rd/wikibot.py @@ -3,6 +3,7 @@ @author: wf """ + import re import sys from os.path import isfile diff --git a/wikibot3rd/wikiedit.py b/wikibot3rd/wikiedit.py index cd61e72..13ac9c9 100644 --- a/wikibot3rd/wikiedit.py +++ b/wikibot3rd/wikiedit.py @@ -3,6 +3,7 @@ @author: wf """ + import sys import wikibot3rd.wikipush diff --git a/wikibot3rd/wikinuke.py b/wikibot3rd/wikinuke.py index 3c59864..e44c085 100644 --- a/wikibot3rd/wikinuke.py +++ b/wikibot3rd/wikinuke.py @@ -3,6 +3,7 @@ @author: wf """ + import sys import wikibot3rd.wikipush diff --git a/wikibot3rd/wikipush.py b/wikibot3rd/wikipush.py index 4fa1553..865fc71 100644 --- a/wikibot3rd/wikipush.py +++ b/wikibot3rd/wikipush.py @@ -4,6 +4,7 @@ @copyright: Wolfgang Fahl. All rights reserved. """ + import datetime # from difflib import Differ @@ -424,7 +425,7 @@ def upload(self, files, force=False): self.uploadImage(file, filename, description, force) self.log("✅") except Exception as ex: - self.show_exception(ex) + self.show_exception(ex) def backup(self, pageTitles, backupPath=None, git=False, withImages=False): """ @@ -626,7 +627,7 @@ def pushImages(self, imageList, delim="", ignore=False): print(image.imageinfo) except Exception as ex: self.handleException(ex, ignore) - + def show_exception(self, ex: Exception): """ Show the given exception and, if debug mode is on, show the traceback. @@ -635,7 +636,7 @@ def show_exception(self, ex: Exception): if self.debug: # Append the formatted traceback to the message msg += "\n" + traceback.format_exc() - + self.log(msg) def handleException(self, ex, ignoreExists=False): @@ -803,6 +804,7 @@ def restore(self, pageTitles=None, backupPath=None, listFile=None, stdIn=False): except Exception as ex: self.show_exception(ex) + __version__ = Version.version __date__ = Version.date __updated__ = Version.updated diff --git a/wikibot3rd/wikiquery.py b/wikibot3rd/wikiquery.py index 3135d2d..bc2ddcc 100644 --- a/wikibot3rd/wikiquery.py +++ b/wikibot3rd/wikiquery.py @@ -3,6 +3,7 @@ @author: wf """ + import sys import wikibot3rd.wikipush diff --git a/wikibot3rd/wikirestore.py b/wikibot3rd/wikirestore.py index 0e5ce3f..ceb6faf 100644 --- a/wikibot3rd/wikirestore.py +++ b/wikibot3rd/wikirestore.py @@ -3,6 +3,7 @@ @author: wf """ + import sys import wikibot3rd.wikipush diff --git a/wikibot3rd/wikitext.py b/wikibot3rd/wikitext.py index 285ee53..081e88a 100644 --- a/wikibot3rd/wikitext.py +++ b/wikibot3rd/wikitext.py @@ -2,6 +2,7 @@ Created on 2023-02-24 @author: tholzheim """ + import typing import warnings diff --git a/wikibot3rd/wikiupload.py b/wikibot3rd/wikiupload.py index 6d41c37..b774164 100644 --- a/wikibot3rd/wikiupload.py +++ b/wikibot3rd/wikiupload.py @@ -3,6 +3,7 @@ @author: wf """ + import sys import wikibot3rd.wikipush