jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1201078?usp=email )

Change subject: tests: update file_tests.TestFilePageLatestFileInfo
......................................................................

tests: update file_tests.TestFilePageLatestFileInfo

The file width returned by FilePage.get_file_url may be greater than or
equal to the requested *url_width* due to :phab:`T360589`.
See the additional notes at
https://www.mediawiki.org/wiki/API:Imageinfo

- update tests accordingly
- add an "important" hint to FilePage.get_file_url documentation

Bug: T391761
Change-Id: Ia797468642a2d27f46b5c4b4da318150f86f896d
---
M pywikibot/page/_filepage.py
M tests/file_tests.py
2 files changed, 22 insertions(+), 14 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/pywikibot/page/_filepage.py b/pywikibot/page/_filepage.py
index 6416bd8..1489c6e 100644
--- a/pywikibot/page/_filepage.py
+++ b/pywikibot/page/_filepage.py
@@ -181,6 +181,14 @@

         .. note:: Parameters validation and error handling left to the
            API call.
+
+        .. important::
+           Starting with MediaWiki 1.45, the file width returned may be
+           greater than or equal to the requested *url_width* due to
+           :phab:`T360589`. If you need the exact width, you must access
+           the corresponding thumbnail URL directly. See the additional
+           notes at :api:`Imageinfo`.
+
         .. seealso::

            * :meth:`APISite.loadimageinfo()
diff --git a/tests/file_tests.py b/tests/file_tests.py
index 1d8ec7e..ad3655b 100755
--- a/tests/file_tests.py
+++ b/tests/file_tests.py
@@ -221,6 +221,10 @@
     code = 'commons'

     file_name = 'File:Albert Einstein Head.jpg'
+    pattern = (
+        r'https://upload.wikimedia.org/wikipedia/commons/thumb/'
+        r'd/d3/Albert_Einstein_Head.jpg/(\d{1,3})px-Albert_Einstein_Head.jpg'
+    )

     cached = True

@@ -249,39 +253,35 @@
             'https://upload.wikimedia.org/wikipedia/commons/'
             'd/d3/Albert_Einstein_Head.jpg')

-    @unittest.expectedFailure  # T391761
     def test_get_file_url_thumburl_from_width(self) -> None:
         """Get File thumburl from width."""
         self.assertTrue(self.image.exists())
         # url_param has no precedence over height/width.
-        self.assertEqual(
-            self.image.get_file_url(url_width=100, url_param='1000px'),
-            'https://upload.wikimedia.org/wikipedia/commons/thumb/'
-            'd/d3/Albert_Einstein_Head.jpg/100px-Albert_Einstein_Head.jpg')
+        url = self.image.get_file_url(url_width=100, url_param='1000px')
+        m = re.search(self.pattern, url)
+        self.assertIsNotNone(m)
+        self.assertGreaterEqual(int(m[1]), 100)
+        self.assertRegex(url, self.pattern)
         self.assertEqual(self.image.latest_file_info.thumbwidth, 100)
         self.assertEqual(self.image.latest_file_info.thumbheight, 133)

-    @unittest.expectedFailure  # T391761
     def test_get_file_url_thumburl_from_height(self) -> None:
         """Get File thumburl from height."""
         self.assertTrue(self.image.exists())
         # url_param has no precedence over height/width.
-        self.assertEqual(
+        self.assertRegex(
             self.image.get_file_url(url_height=100, url_param='1000px'),
-            'https://upload.wikimedia.org/wikipedia/commons/thumb/'
-            'd/d3/Albert_Einstein_Head.jpg/75px-Albert_Einstein_Head.jpg')
+            self.pattern
+        )
         self.assertEqual(self.image.latest_file_info.thumbwidth, 75)
         self.assertEqual(self.image.latest_file_info.thumbheight, 100)

-    @unittest.expectedFailure  # T391761
     def test_get_file_url_thumburl_from_url_param(self) -> None:
         """Get File thumburl from height."""
         self.assertTrue(self.image.exists())
         # url_param has no precedence over height/width.
-        self.assertEqual(
-            self.image.get_file_url(url_param='100px'),
-            'https://upload.wikimedia.org/wikipedia/commons/thumb/'
-            'd/d3/Albert_Einstein_Head.jpg/100px-Albert_Einstein_Head.jpg')
+        self.assertRegex(
+            self.image.get_file_url(url_param='100px'), self.pattern)
         self.assertEqual(self.image.latest_file_info.thumbwidth, 100)
         self.assertEqual(self.image.latest_file_info.thumbheight, 133)


--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1201078?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: Ia797468642a2d27f46b5c4b4da318150f86f896d
Gerrit-Change-Number: 1201078
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[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]

Reply via email to