Xqt has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1323516?usp=email )

Change subject: upload: Avoid unnecessary Site creation in UploadRobot
......................................................................

upload: Avoid unnecessary Site creation in UploadRobot

Also skip QuitKeyboardInterrupt from coverage.

Change-Id: I6de092957bf155e75371a95ae227000a983b4a29
---
M pyproject.toml
M pywikibot/specialbots/_upload.py
M tests/uploadbot_tests.py
3 files changed, 14 insertions(+), 15 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/pyproject.toml b/pyproject.toml
index 4bfd324..9957037 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -137,7 +137,7 @@
     "@unittest\\.skip",
     "class .+\\bProtocol\\):",
     "except (ImportError|ModuleNotFoundError)",
-    "except KeyboardInterrupt",
+    "except (Quit)?KeyboardInterrupt",
     "except OSError",
     "except SyntaxError",
     "except \\w*ServerError",
diff --git a/pywikibot/specialbots/_upload.py b/pywikibot/specialbots/_upload.py
index ea0574d..589f336 100644
--- a/pywikibot/specialbots/_upload.py
+++ b/pywikibot/specialbots/_upload.py
@@ -131,11 +131,12 @@
         self.filename_prefix = filename_prefix
         self.force_if_shared = force_if_shared

-        if config.upload_to_commons:
-            default_site = pywikibot.Site('commons')
+        if target_site:
+            self.target_site = target_site
+        elif config.upload_to_commons:
+            self.target_site = pywikibot.Site('commons')
         else:
-            default_site = pywikibot.Site()
-        self.target_site = target_site or default_site
+            self.target_site = pywikibot.Site()

     def read_file_content(self, file_url: str):
         """Return name of temp file in which remote file is saved."""
diff --git a/tests/uploadbot_tests.py b/tests/uploadbot_tests.py
index f1c4795..81ad148 100755
--- a/tests/uploadbot_tests.py
+++ b/tests/uploadbot_tests.py
@@ -68,18 +68,16 @@

     net = False

-    params = dict(  # noqa: C408
-        description='pywikibot upload.py script test',
-        keep_filename=True,
-        aborts=set(),
-        ignore_warning=True,
-    )
-
     def test_png_file(self) -> None:
         """Test UploadRobot attributes and methods."""
-        bot = UploadRobot(url=['test.png'], target_site=self.site,
-                          **self.params)
-        self.assertEqual(bot.description, self.params['description'])
+        params = {
+            'description': 'pywikibot upload.py script test',
+            'keep_filename': True,
+            'aborts': set(),
+            'ignore_warning': True,
+        }
+        bot = UploadRobot(url=['test.png'], target_site=self.site, **params)
+        self.assertEqual(bot.description, params['description'])
         self.assertTrue(bot._handle_warning('any warning'))  # ignore_warning
         self.assertTrue(bot.ignore_on_warn('any warning'))  # ignore_warning
         self.assertFalse(bot.abort_on_warn('any warning'))  # aborts

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1323516?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I6de092957bf155e75371a95ae227000a983b4a29
Gerrit-Change-Number: 1323516
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to