jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/775922 )

Change subject: [fix] Don't raise NoPageError with file_is_shared
......................................................................

[fix] Don't raise NoPageError with file_is_shared

Instead raising NoPageError, FilePage.file_is_shared returns False
if a file neither exists locally nor on shared image repository
(commons)

Bug: T305182
Change-Id: I4d20bbc599619c74285232db31f3e1f4d05aa78e
---
M pywikibot/page/_pages.py
M tests/file_tests.py
2 files changed, 15 insertions(+), 8 deletions(-)

Approvals:
  Matěj Suchánek: Looks good to me, but someone else must approve
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/page/_pages.py b/pywikibot/page/_pages.py
index f095424..e9476f9 100644
--- a/pywikibot/page/_pages.py
+++ b/pywikibot/page/_pages.py
@@ -2446,17 +2446,27 @@
         return self.latest_file_info.thumburl

     def file_is_shared(self) -> bool:
-        """Check if the file is stored on any known shared repository."""
+        """Check if the file is stored on any known shared repository.
+
+        .. versionchanged:: 7.0
+           return False if file does not exist on shared image repository
+           instead raising NoPageError.
+        """
         # as of now, the only known repositories are commons and wikitravel
         # TODO: put the URLs to family file
         if not self.site.has_image_repository:
             return False

+        try:
+            info = self.latest_file_info
+        except NoPageError:
+            return False
+
         if 'wikitravel_shared' in self.site.shared_image_repository():
-            return self.latest_file_info.url.startswith(
-                'https://wikitravel.org/upload/shared/')
+            return info.url.startswith('https://wikitravel.org/upload/shared/')
+
         # default to commons
-        return self.latest_file_info.url.startswith(
+        return info.url.startswith(
             'https://upload.wikimedia.org/wikipedia/commons/')

     def getFileVersionHistoryTable(self):
diff --git a/tests/file_tests.py b/tests/file_tests.py
index ef81ba4..8aed05a 100755
--- a/tests/file_tests.py
+++ b/tests/file_tests.py
@@ -91,13 +91,10 @@
         self.assertFalse(commons_file.exists())

         self.assertFalse(enwp_file.file_is_shared())
+        self.assertFalse(commons_file.file_is_shared())

         page_doesnt_exist_exc_regex = re.escape(
             "Page [[commons:{}]] doesn't exist.".format(title))
-        with self.assertRaisesRegex(
-                NoPageError,
-                page_doesnt_exist_exc_regex):
-            commons_file.file_is_shared()

         with self.assertRaisesRegex(
                 NoPageError,

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/775922
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I4d20bbc599619c74285232db31f3e1f4d05aa78e
Gerrit-Change-Number: 775922
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: Multichill <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to