jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1358294?usp=email )
Change subject: lexeme: Preserve fields during data normalization
......................................................................
lexeme: Preserve fields during data normalization
Bind normalization to the concrete entity class so Lexeme lemmas and
form representations and claims are retained. Read language and lexical
category from the input before converting ItemPage values to IDs.
Bug: T189321
Change-Id: Ieada4986315a0b6c1f439531d8c15a334de0365b
---
M pywikibot/page/_wikibase.py
M tests/wikibase_tests.py
2 files changed, 48 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py
index dc82294..adb9daa 100644
--- a/pywikibot/page/_wikibase.py
+++ b/pywikibot/page/_wikibase.py
@@ -2410,9 +2410,9 @@
:param data: The dict to normalize
:return: The altered dict from parameter data.
"""
- new_data = WikibasePage._normalizeData(data)
+ new_data = super()._normalizeData(data)
for prop in ('language', 'lexicalCategory'):
- value = new_data.get(prop)
+ value = data.get(prop)
if value:
if isinstance(value, ItemPage):
new_data[prop] = value.getID()
@@ -2585,7 +2585,7 @@
@classmethod
def _normalizeData(cls, data):
- new_data = LexemeSubEntity._normalizeData(data)
+ new_data = super()._normalizeData(data)
if 'grammaticalFeatures' in data:
value = []
for feat in data['grammaticalFeatures']:
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index 7e1e0ed..f363068 100755
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -25,6 +25,8 @@
from pywikibot.page import (
Claim,
ItemPage,
+ LexemeForm,
+ LexemePage,
MediaInfo,
PropertyPage,
WikibasePage,
@@ -1155,6 +1157,49 @@
ItemPage._normalizeData(data)
+class TestLexemeNormalizeData(WikidataTestCase):
+
+ """Test normalization of Lexeme and form fields."""
+
+ dry = True
+
+ def test_lexeme_fields(self) -> None:
+ """Preserve lemmas and claims and normalize item-valued fields."""
+ data = {
+ 'lemmas': {'en': 'colour'},
+ 'claims': [],
+ 'language': ItemPage(self.get_repo(), 'Q1860'),
+ 'lexicalCategory': 'Q1084',
+ }
+ original = copy.deepcopy(data)
+ expected = {
+ 'lemmas': {'en': {'language': 'en', 'value': 'colour'}},
+ 'claims': [],
+ 'language': 'Q1860',
+ 'lexicalCategory': 'Q1084',
+ }
+ self.assertEqual(LexemePage._normalizeData(data), expected)
+ self.assertEqual(data, original)
+ self.assertEqual(LexemePage._normalizeData(expected), expected)
+
+ def test_form_fields(self) -> None:
+ """Preserve representations and claims alongside features."""
+ data = {
+ 'representations': {'en': 'colours'},
+ 'claims': [],
+ 'grammaticalFeatures': [ItemPage(self.get_repo(), 'Q146786')],
+ }
+ original = copy.deepcopy(data)
+ expected = {
+ 'representations': {'en': {'language': 'en', 'value': 'colours'}},
+ 'claims': [],
+ 'grammaticalFeatures': ['Q146786'],
+ }
+ self.assertEqual(LexemeForm._normalizeData(data), expected)
+ self.assertEqual(data, original)
+ self.assertEqual(LexemeForm._normalizeData(expected), expected)
+
+
class TestMediaInfoNormalizeData(TestCase):
"""Test cases for MediaInfo._normalizeData and MediaInfo.toJSON."""
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1358294?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: Ieada4986315a0b6c1f439531d8c15a334de0365b
Gerrit-Change-Number: 1358294
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]