jenkins-bot submitted this change.
[IMPR] Add file_is_used to determine whether a file is used on a site
Also add some tests.
Change-Id: I1b5f7d24b78fab453713d0ce559a8d5f219d81c4
---
M pywikibot/page/_pages.py
M tests/file_tests.py
2 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/pywikibot/page/_pages.py b/pywikibot/page/_pages.py
index 3d48204..781caae 100644
--- a/pywikibot/page/_pages.py
+++ b/pywikibot/page/_pages.py
@@ -2478,6 +2478,14 @@
"""
return self.site.imageusage(self, total=total, content=content)
+ @property
+ def file_is_used(self) -> bool:
+ """Check whether the file is used at this site.
+
+ .. versionadded:: 7.1
+ """
+ return bool(list(self.usingPages(total=1)))
+
def upload(self, source: str, **kwargs) -> bool:
"""
Upload this file to the wiki.
diff --git a/tests/file_tests.py b/tests/file_tests.py
index d01d93b..ef81ba4 100755
--- a/tests/file_tests.py
+++ b/tests/file_tests.py
@@ -61,7 +61,9 @@
self.assertTrue(commons_file.exists())
self.assertTrue(itwp_file.file_is_shared())
+ self.assertFalse(itwp_file.file_is_used)
self.assertTrue(commons_file.file_is_shared())
+ self.assertTrue(commons_file.file_is_used)
self.assertTrue(commons_file.get_file_url())
self.assertIn('/wikipedia/commons/', itwp_file.get_file_url())
@@ -124,7 +126,9 @@
self.assertTrue(commons_file.exists())
self.assertFalse(itwp_file.file_is_shared())
+ self.assertTrue(itwp_file.file_is_used)
self.assertTrue(commons_file.file_is_shared())
+ self.assertTrue(commons_file.file_is_used)
def testNonFileLocal(self):
"""Test file page, without local file, existing on the local wiki."""
To view, visit change 770509. To unsubscribe, or for help writing mail filters, visit settings.