From 161ad7178c52a5ea81a04f0f834738beae0d14c5 Mon Sep 17 00:00:00 2001 From: aurorakiitaja Date: Sat, 31 Aug 2024 23:40:08 +0300 Subject: [PATCH] Add title function to MediaInfo. Added missing title function to MediaInfo so it is consistent with other entity types. Bug: T366424 Change-Id: I9ca83d8854e04e1651bc959cf020ce9799a7fefc --- pywikibot/page/_wikibase.py | 8 ++++++++ tests/file_tests.py | 3 +++ 2 files changed, 11 insertions(+) diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py index b3458f666e..5ebe25dd6c 100644 --- a/pywikibot/page/_wikibase.py +++ b/pywikibot/page/_wikibase.py @@ -521,6 +521,14 @@ def getID(self, numeric: bool = False): self._assert_has_id() return super().getID(numeric=numeric) + def title(self): + """ + Return ID as title of the MediaInfo. + + :return: str: the entity identifier + """ + return self.getID() + def editLabels(self, labels: LANGUAGE_TYPE, **kwargs) -> None: """Edit MediaInfo labels (eg. captions). diff --git a/tests/file_tests.py b/tests/file_tests.py index dc710ad8cd..63b693b0c7 100755 --- a/tests/file_tests.py +++ b/tests/file_tests.py @@ -362,6 +362,7 @@ def test_data_item(self): self.assertEqual('-1', item.id) item.get() self.assertEqual('M14634781', item.id) + self.assertEqual('M14634781', item.title()) self.assertIsInstance( item.labels, pywikibot.page._collections.LanguageDict) self.assertIsInstance( @@ -400,6 +401,8 @@ def test_data_item_when_no_file_or_data_item(self): with self.assertRaises(NoWikibaseEntityError): item.get() + with self.assertRaises(NoWikibaseEntityError): + item.title() with self.assertRaises(NoWikibaseEntityError): item.labels