jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1324307?usp=email )

Change subject: uploadbot: Count successful uploads once
......................................................................

uploadbot: Count successful uploads once

UploadRobot already increments the upload counter when an upload
succeeds. Incrementing it again in run() reports twice the number of
completed uploads.

Keep the counter update next to the successful upload and add a dry
regression test for the complete run path.

Change-Id: I761b9f896d034ec8163c0af52b13553e1cc88363
---
M pywikibot/specialbots/_upload.py
M tests/uploadbot_tests.py
2 files changed, 26 insertions(+), 2 deletions(-)

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




diff --git a/pywikibot/specialbots/_upload.py b/pywikibot/specialbots/_upload.py
index 589f336..e0d0ef1 100644
--- a/pywikibot/specialbots/_upload.py
+++ b/pywikibot/specialbots/_upload.py
@@ -484,8 +484,6 @@
             for file_url in self.url:
                 filename = self.upload_file(file_url)
                 self.counter['read'] += 1
-                if filename:
-                    self.counter['upload'] += 1
                 if callable(self.post_processor):
                     self.post_processor(file_url, filename)
         except QuitKeyboardInterrupt:
diff --git a/tests/uploadbot_tests.py b/tests/uploadbot_tests.py
index 81ad148..1c84614 100755
--- a/tests/uploadbot_tests.py
+++ b/tests/uploadbot_tests.py
@@ -13,6 +13,7 @@
 import os
 import unittest
 from contextlib import suppress
+from unittest import mock

 from pywikibot.specialbots import UploadRobot
 from tests import join_images_path
@@ -84,6 +85,31 @@
         self.assertIsNone(bot.post_processor)


+class TestUploadbotCounter(TestCase):
+
+    """Dry tests for UploadRobot counters."""
+
+    net = False
+
+    def test_upload_counter(self) -> None:
+        """Test that a successful upload is counted once."""
+        bot = UploadRobot(
+            url=['test.png'], target_site=mock.Mock(), always=False)
+
+        with (
+            mock.patch.object(bot, 'skip_run', return_value=False),
+            mock.patch.object(bot, 'process_filename',
+                              return_value='test.png'),
+            mock.patch.object(bot, 'exit'),
+            mock.patch('pywikibot.FilePage') as file_page,
+        ):
+            file_page.return_value.upload.return_value = True
+            bot.run()
+
+        self.assertEqual(bot.counter['read'], 1)
+        self.assertEqual(bot.counter['upload'], 1)
+
+
 if __name__ == '__main__':
     with suppress(SystemExit):
         unittest.main()

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1324307?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: I761b9f896d034ec8163c0af52b13553e1cc88363
Gerrit-Change-Number: 1324307
Gerrit-PatchSet: 3
Gerrit-Owner: Mahveotm <[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