jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/478723 )

Change subject: [tests] Provide unittests for match_images.py
......................................................................

[tests] Provide unittests for match_images.py

- enable script_tests.TestScriptHelp for match_images.py
- Don't raise an exception if PIL isn't installed but show
  a warning instead

Bug: T193975
Change-Id: I2423dab6ebdd5a184b1c2bda7dedcc7054a6e1af
---
M scripts/match_images.py
M tests/script_tests.py
2 files changed, 15 insertions(+), 7 deletions(-)

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



diff --git a/scripts/match_images.py b/scripts/match_images.py
index 1c15517..69607ed 100755
--- a/scripts/match_images.py
+++ b/scripts/match_images.py
@@ -24,7 +24,7 @@
 """
 #
 # (c) Multichill, 2009
-# (c) Pywikibot team, 2009-2017
+# (c) Pywikibot team, 2009-2018
 #
 # Distributed under the terms of the MIT license.
 #
@@ -32,12 +32,16 @@

 import io
 
-from PIL import Image
-
 import pywikibot

+from pywikibot.bot import suggest_help
 from pywikibot.comms import http

+try:
+    from PIL import Image
+except ImportError as e:
+    Image = e
+

 def match_image_pages(imagePageA, imagePageB):
     """The function expects two image page objects.
@@ -165,10 +169,13 @@
         else:
             images.append(arg)

-    if len(images) != 2:
-        pywikibot.bot.suggest_help(
-            additional_text='Unable to execute script because it '
-                            'requires two images to work on.')
+    additional_text = ('Unable to execute script because it '
+                       'requires two images to work on.'
+                       if len(images) != 2 else None)
+    exception = Image if isinstance(Image, Exception) else None
+
+    if additional_text or exception:
+        suggest_help(exception=exception, additional_text=additional_text)
         return False

     imagePageA = pywikibot.page.FilePage(pywikibot.Site(),
diff --git a/tests/script_tests.py b/tests/script_tests.py
index 0c52f09..edf66b4 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -379,6 +379,7 @@
     _expected_failures.discard('flickrripper')
     _expected_failures.discard('imageharvest')
     _expected_failures.discard('isbn')
+    _expected_failures.discard('match_images')
     _expected_failures.discard('patrol')
     _expected_failures.discard('states_redirect')
     _expected_failures.discard('weblinkchecker')

--
To view, visit https://gerrit.wikimedia.org/r/478723
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I2423dab6ebdd5a184b1c2bda7dedcc7054a6e1af
Gerrit-Change-Number: 478723
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: Dalba <[email protected]>
Gerrit-Reviewer: Framawiki <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Multichill <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to