jenkins-bot has submitted this change and it was merged.
Change subject: nose related script tests updates ......................................................................
nose related script tests updates
In order for the script tests to run under nose, they must not unexpectedly pass. A few scripts have been fixed recently, and their status not updated in script_tests.py
Allow exit codes 1 and 2, as exit code 2 is used by argparse to indicate a problem with the command line options, such as too few options as occurs with replicate_wiki, and exit code 1 is used by sys.exit called with a string as occurs in lonelypages.
Also some script fixes: casechecker: dont use stdout to report script completion states_redirect and flickripper: set exit code to 1 if deps fail watchlist: Use APISite.login instead of deprecated forceLogin nowcommons: use SHA1 instead of MD5
Change-Id: I7eda163b63151ea5fc90bbf7ba1e4adf4b7181c5 --- M scripts/casechecker.py M scripts/flickrripper.py M scripts/nowcommons.py M scripts/states_redirect.py M scripts/watchlist.py M tests/script_tests.py 6 files changed, 12 insertions(+), 15 deletions(-)
Approvals: John Vandenberg: Looks good to me, but someone else must approve XZise: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/casechecker.py b/scripts/casechecker.py index 89347ca..cc9350a 100644 --- a/scripts/casechecker.py +++ b/scripts/casechecker.py @@ -341,7 +341,6 @@ batchStart:batchStart + batchSize] for data in self.RunQuery(self.queryParams): self.ProcessDataBlock(data) - print("*" * 29 + " Done") except: pywikibot.output(u'Exception at Title = %s, Next = %s' % (self.currentTitle, self.apfrom)) diff --git a/scripts/flickrripper.py b/scripts/flickrripper.py index f1bdf28..cad7b1d 100644 --- a/scripts/flickrripper.py +++ b/scripts/flickrripper.py @@ -71,7 +71,7 @@ 'This script requires ImageTk from the Python Imaging Library (PIL).\n' 'See: https://www.mediawiki.org/wiki/Manual:Pywikibot/flickrripper.py') print(e) - sys.exit() + sys.exit(1)
try: import flickrapi # see: http://stuvel.eu/projects/flickrapi @@ -79,7 +79,7 @@ print('This script requires the python flickrapi module. \n' 'See: http://stuvel.eu/projects/flickrapi') print(e) - sys.exit() + sys.exit(1)
import pywikibot
diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py index 7d27c71..a016b3d 100644 --- a/scripts/nowcommons.py +++ b/scripts/nowcommons.py @@ -8,7 +8,7 @@
Files are downloaded and compared. If the files match, it can be deleted on the source wiki. If multiple versions of the file exist, the script will not -delete. If the MD5 comparison is not equal, the script will not delete. +delete. If the SHA1 comparison is not equal, the script will not delete.
A sysop account on the local wiki is required if you want all features of this script to work properly. @@ -325,7 +325,7 @@ if localImagePage.fileIsShared(): pywikibot.output(u'File is already on Commons.') continue - md5 = localImagePage.getFileMd5Sum() + sha1 = localImagePage.getFileSHA1Sum() if self.getOption('use_hash'): filenameOnCommons = images_list[1] else: @@ -395,7 +395,7 @@ % localImagePage.title(withNamespace=False)) commonsText = commonsImagePage.get() if self.getOption('replaceonly') is False: - if md5 == commonsImagePage.getFileMd5Sum(): + if sha1 == commonsImagePage.getFileSHA1Sum(): pywikibot.output( u'The image is identical to the one on Commons.') if len(localImagePage.getFileVersionHistory()) > 1 and not self.getOption('use_hash'): diff --git a/scripts/states_redirect.py b/scripts/states_redirect.py index 1bf5d5c..2ec6898 100644 --- a/scripts/states_redirect.py +++ b/scripts/states_redirect.py @@ -34,7 +34,7 @@ pywikibot.error('This script requires the python-pycountry module') pywikibot.error('See: https://pypi.python.org/pypi/pycountry') pywikibot.exception() - sys.exit() + sys.exit(1)
msg = { 'en': 'Creating state abbreviation redirect', diff --git a/scripts/watchlist.py b/scripts/watchlist.py index ffa7803..31d1dcf 100755 --- a/scripts/watchlist.py +++ b/scripts/watchlist.py @@ -56,7 +56,7 @@ def refresh(site, sysop=False): """Fetch the watchlist.""" if not site.logged_in(sysop=sysop): - site.forceLogin(sysop=sysop) + site.login(sysop=sysop)
params = { 'action': 'query', diff --git a/tests/script_tests.py b/tests/script_tests.py index a276593..06f3df7 100644 --- a/tests/script_tests.py +++ b/tests/script_tests.py @@ -303,7 +303,7 @@ if error: self.assertIn(error, result['stderr'])
- self.assertIn(result['exit_code'], [0, -9]) + self.assertIn(result['exit_code'], [0, 1, 2, -9]) else: if stderr_other == ['']: stderr_other = None @@ -335,7 +335,8 @@ # Specifically look for deprecated self.assertNotIn('deprecated', result['stdout'].lower()) # But also complain if there is any stdout - if result['stdout'] == '': + # but ignore shell.py emiting a prompt + if result['stdout'] in ['', '>>> ']: result['stdout'] = None self.assertIsNone(result['stdout'])
@@ -356,7 +357,6 @@ dct[test_name] = test_execution(script_name, ['-help']) if script_name in ['version', 'data_ingestion', # bug 68611 - 'replicate_wiki', # bug 68664 'script_wui', # Failing on travis-ci ] + failed_dep_script_list: dct[test_name] = unittest.expectedFailure(dct[test_name]) @@ -383,13 +383,11 @@ 'checkimages', # bug 68613 'data_ingestion', # bug 68611 'flickrripper', # Requires a flickr api key - 'lonelypages', # custom return codes - 'nowcommons', # deprecation warning - 'replicate_wiki', # custom return codes + 'lonelypages', # uses exit code 1 'script_wui', # Error on any user except DrTrigonBot 'upload', # raises custom ValueError ] + failed_dep_script_list or ( - ((config.family != 'wikipedia' or config.mylang != 'en') and script_name == 'cfd') or + (config.family != 'wikipedia' and script_name == 'lonelypages') or (config.family == 'wikipedia' and script_name == 'disambredir') or (config.family == 'wikipedia' and config.mylang != 'en' and script_name == 'misspelling')): dct[test_name] = unittest.expectedFailure(dct[test_name])