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

Change subject: coordinate_import: Save coordinates through user_add_claim
......................................................................

coordinate_import: Save coordinates through user_add_claim

Direct claim saves bypass bot confirmation and write accounting.
Use user_add_claim while keeping saves synchronous to preserve success
reporting and unsupported-globe handling.

Change-Id: Id9847863b022591e60289f70e8cdd0db58d2cbe4
---
M scripts/coordinate_import.py
A tests/coordinate_import_tests.py
2 files changed, 66 insertions(+), 10 deletions(-)

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




diff --git a/scripts/coordinate_import.py b/scripts/coordinate_import.py
index 96a19f7..809a13b 100755
--- a/scripts/coordinate_import.py
+++ b/scripts/coordinate_import.py
@@ -132,21 +132,14 @@

         newclaim = pywikibot.Claim(self.repo, self.prop)
         newclaim.setTarget(coordinate)
-        source = self.getSource(page.site)
-        if source:
-            newclaim.addSource(source)
-        pywikibot.info(
-            f'Adding {coordinate.lat}, {coordinate.lon} to {item.title()}')
-
-        # TODO: handle exceptions using self.user_add_claim
         try:
-            item.addClaim(newclaim)
+            # Wait for the save result, including unsupported-globe errors.
+            return self.user_add_claim(item, newclaim, source=page.site,
+                                       asynchronous=False)
         except CoordinateGlobeUnknownError as e:
             pywikibot.info(f'Skipping unsupported globe: {e.args}')
             return False

-        return True
-

 def main(*args: str) -> None:
     """Process command line arguments and invoke bot.
diff --git a/tests/coordinate_import_tests.py b/tests/coordinate_import_tests.py
new file mode 100755
index 0000000..5483998
--- /dev/null
+++ b/tests/coordinate_import_tests.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python3
+#
+# (C) Pywikibot team, 2026
+#
+# Distributed under the terms of the MIT license.
+#
+"""Tests for the coordinate_import script."""
+from __future__ import annotations
+
+import unittest
+from collections import Counter
+from contextlib import suppress
+from types import SimpleNamespace
+from unittest.mock import Mock, patch
+
+from pywikibot.exceptions import CoordinateGlobeUnknownError
+from scripts.coordinate_import import CoordImportRobot
+from tests.aspects import TestCase
+
+
+class TestCoordinateImport(TestCase):
+
+    """Test coordinate saves through the standard bot helper."""
+
+    net = False
+
+    def test_save_result(self) -> None:
+        """Preserve sources, confirmation, and synchronous error handling."""
+        bot = object.__new__(CoordImportRobot)
+        bot.repo = Mock()
+        bot.prop = 'P625'
+        bot.opt = SimpleNamespace(always=True)
+        bot.counter = Counter()
+        page, item, claim, source = Mock(), Mock(), Mock(), Mock()
+        bot._current_page = item
+
+        with patch('scripts.coordinate_import.pywikibot.Claim',
+                   return_value=claim), \
+                patch.object(bot, 'getSource', return_value=source) as get_src:
+            self.assertTrue(bot.try_import_coordinates_from_page(page, item))
+            claim.setTarget.assert_called_once_with(
+                page.coordinates.return_value)
+            get_src.assert_called_once_with(page.site)
+            claim.addSource.assert_called_once_with(source)
+            item.addClaim.assert_called_once_with(
+                claim, bot=True, asynchronous=False)
+            self.assertEqual(bot.counter['write'], 1)
+
+            item.addClaim.reset_mock()
+            with patch.object(bot, 'user_confirm', return_value=False):
+                self.assertFalse(
+                    bot.try_import_coordinates_from_page(page, item))
+            item.addClaim.assert_not_called()
+            self.assertEqual(bot.counter['write'], 1)
+
+            item.addClaim.side_effect = CoordinateGlobeUnknownError('unknown')
+            self.assertFalse(bot.try_import_coordinates_from_page(page, item))
+            self.assertEqual(bot.counter['write'], 1)
+
+
+if __name__ == '__main__':
+    with suppress(SystemExit):
+        unittest.main()

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1358151?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: Id9847863b022591e60289f70e8cdd0db58d2cbe4
Gerrit-Change-Number: 1358151
Gerrit-PatchSet: 4
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