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

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

[tests] Provide unittests for states_redirect.py

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

Bug: T211660
Change-Id: I43ebd9408715bed55ff715785fb48bec3fc08687
---
M scripts/states_redirect.py
M tests/script_tests.py
2 files changed, 18 insertions(+), 8 deletions(-)

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



diff --git a/scripts/states_redirect.py b/scripts/states_redirect.py
index 81f78c8..10802b7 100755
--- a/scripts/states_redirect.py
+++ b/scripts/states_redirect.py
@@ -22,19 +22,16 @@
 from __future__ import absolute_import, division, unicode_literals

 import re
-import sys

 import pywikibot

+from pywikibot.bot import suggest_help
 from pywikibot import i18n

 try:
     import pycountry
-except ImportError:
-    pywikibot.error('This script requires the python-pycountry module')
-    pywikibot.error('See: https://pypi.org/project/pycountry')
-    pywikibot.exception()
-    sys.exit(1)
+except ImportError as e:
+    pycountry = e


 class StatesRedirectBot(pywikibot.Bot):
@@ -121,6 +118,7 @@
     local_args = pywikibot.handle_args(args)
     start = None
     force = False
+    unknown_parameters = []

     # Parse command line arguments
     for arg in local_args:
@@ -129,8 +127,19 @@
         elif arg == '-force':
             force = True
         else:
-            pywikibot.warning(
-                'argument "{0}" not understood; ignoring.'.format(arg))
+            unknown_parameters.append(arg)
+
+    if isinstance(pycountry, Exception):
+        additional_text = ('This script requires the python-pycountry module\n'
+                           'See: https://pypi.org/project/pycountry')
+        exception = pycountry
+    else:
+        additional_text = exception = None
+
+    if additional_text or exception or unknown_parameters:
+        suggest_help(unknown_parameters=unknown_parameters,
+                     exception=exception, additional_text=additional_text)
+        return

     bot = StatesRedirectBot(start, force)
     bot.run()
diff --git a/tests/script_tests.py b/tests/script_tests.py
index 18c750c..0c52f09 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -380,6 +380,7 @@
     _expected_failures.discard('imageharvest')
     _expected_failures.discard('isbn')
     _expected_failures.discard('patrol')
+    _expected_failures.discard('states_redirect')
     _expected_failures.discard('weblinkchecker')
     _allowed_failures = []


--
To view, visit https://gerrit.wikimedia.org/r/478876
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: I43ebd9408715bed55ff715785fb48bec3fc08687
Gerrit-Change-Number: 478876
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: jenkins-bot (75)
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to