jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1324214?usp=email )
Change subject: wbtypes: Reuse data page title
......................................................................
wbtypes: Reuse data page title
Retrieve the page title once after general data-page validation.
Reuse it for the namespace prefix and file-ending checks.
Change-Id: I3e4fbd528cc555d0e04794232531aac60af7795d
---
M pywikibot/_wbtypes.py
M tests/wbtypes_tests.py
2 files changed, 24 insertions(+), 2 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/_wbtypes.py b/pywikibot/_wbtypes.py
index a58b133..5eeee87 100644
--- a/pywikibot/_wbtypes.py
+++ b/pywikibot/_wbtypes.py
@@ -1197,8 +1197,8 @@
# pcre regexp: '/^Data:[^\\[\\]#\\\:{|}]+\.tab$/u' for tabular-data
# As we have already checked for existence the following simplified
# check should be enough.
- if not page.title().startswith('Data:') \
- or not page.title().endswith(ending):
+ title = page.title()
+ if not title.startswith('Data:') or not title.endswith(ending):
raise ValueError(f"Page must be in 'Data:' namespace and end in "
f"'{ending}' for {label}.")
diff --git a/tests/wbtypes_tests.py b/tests/wbtypes_tests.py
index 9e161aa..992a824 100755
--- a/tests/wbtypes_tests.py
+++ b/tests/wbtypes_tests.py
@@ -12,6 +12,7 @@
import unittest
from contextlib import suppress
from decimal import Decimal
+from unittest import mock
import pywikibot
from pywikibot.page import ItemPage, Page
@@ -850,6 +851,27 @@
pywikibot.WbMonolingualText(text=None, language='sv')
+class TestWbDataPage(WbRepresentationTestCase):
+
+ """Test the common Wikibase data-page behavior."""
+
+ dry = True
+
+ def test_validate_reuses_title(self) -> None:
+ """Test that title validation retrieves the title once."""
+ site = self.get_site()
+ page = Page(site, 'Data:Example.map')
+
+ with (
+ mock.patch.object(page, 'exists', return_value=True),
+ mock.patch.object(page, 'title', wraps=page.title) as title,
+ ):
+ pywikibot.WbGeoShape._validate(
+ page, site, '.map', 'geo-shape')
+
+ title.assert_called_once_with()
+
+
class TestWbGeoShapeNonDry(WbRepresentationTestCase):
"""Test Wikibase WbGeoShape data type (non-dry).
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1324214?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: I3e4fbd528cc555d0e04794232531aac60af7795d
Gerrit-Change-Number: 1324214
Gerrit-PatchSet: 2
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]