Skip to content

Commit

Permalink
[pep8] Keep lines of script_tests.py beneath 80 chars
Browse files Browse the repository at this point in the history
Change-Id: I34b5710d761dd75ef101c441845c7d0cd57dbe25
  • Loading branch information
xqt committed May 7, 2017
1 parent b54b6d5 commit 9085b71
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions tests/script_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
)

from tests import join_root_path
from tests.aspects import unittest, DefaultSiteTestCase, MetaTestCaseClass, PwbTestCase
from tests.aspects import (unittest, DefaultSiteTestCase, MetaTestCaseClass,
PwbTestCase)
from tests.utils import allowed_failure, execute_pwb, add_metaclass

scripts_path = join_root_path('scripts')
Expand Down Expand Up @@ -101,15 +102,19 @@ def list_scripts(path, exclude=None):
'catall': 'q\n', # q for quit
'editarticle': 'Test page\n',
'imageuncat': 'q\n',
'imageharvest': 'https://upload.wikimedia.org/wikipedia/commons/8/80/Wikipedia-logo-v2.svg\n\n',
'imageharvest':
'https://upload.wikimedia.org/wikipedia/commons/'
'8/80/Wikipedia-logo-v2.svg\n\n',
'interwiki': 'Test page that should not exist\n',
'misspelling': 'q\n',
'pagefromfile': 'q\n',
'replace': 'foo\nbar\n\n\n', # match, replacement,
# Enter to begin, Enter for default summary.
'shell': '\n', # exits on end of stdin
'solve_disambiguation': 'Test page\nq\n',
'upload': 'https://upload.wikimedia.org/wikipedia/commons/8/80/Wikipedia-logo-v2.svg\n\n\n',
'upload':
'https://upload.wikimedia.org/wikipedia/commons/'
'8/80/Wikipedia-logo-v2.svg\n\n\n',
}

auto_run_script_list = [
Expand Down Expand Up @@ -149,7 +154,8 @@ def list_scripts(path, exclude=None):
'featured': '0 pages written.',
'freebasemappingupload': 'Cannot find ',
'harvest_template': 'ERROR: Please specify',
'imageuncat': 'WARNING: This script is primarily written for Wikimedia Commons',
'imageuncat':
'WARNING: This script is primarily written for Wikimedia Commons',
# script_input['interwiki'] above lists a title that should not exist
'interwiki': 'does not exist. Skipping.',
'imageharvest': 'From what URL should I get the images',
Expand Down Expand Up @@ -237,14 +243,18 @@ class TestScriptMeta(MetaTestCaseClass):
def __new__(cls, name, bases, dct):
"""Create the new class."""
def test_execution(script_name, args=[]):
is_autorun = '-help' not in args and script_name in auto_run_script_list
is_autorun = ('-help' not in args and
script_name in auto_run_script_list)

def test_skip_script(self):
raise unittest.SkipTest(
'Skipping execution of auto-run scripts (set '
'PYWIKIBOT2_TEST_AUTORUN=1 to enable) "{0}"'.format(script_name))
'PYWIKIBOT2_TEST_AUTORUN=1 to enable) "{0}"'
.format(script_name))

def testScript(self):
GLOBAL_ARGS = 'Global arguments available for all'

cmd = [script_name]

if args:
Expand All @@ -270,8 +280,8 @@ def testScript(self):
if not hasattr(self, 'net') or not self.net:
test_overrides['pywikibot.Site'] = 'None'

result = execute_pwb(cmd, data_in, timeout=timeout, error=error,
overrides=test_overrides)
result = execute_pwb(cmd, data_in, timeout=timeout,
error=error, overrides=test_overrides)

stderr = result['stderr'].splitlines()
stderr_sleep = [l for l in stderr
Expand All @@ -296,8 +306,7 @@ def testScript(self):
stderr_other)
self.assertNotIn('-help', args)
else:
self.assertIn('Global arguments available for all',
result['stdout'])
self.assertIn(GLOBAL_ARGS, result['stdout'])

exit_codes = [0]
else:
Expand All @@ -319,7 +328,7 @@ def testScript(self):
self.assertNotIn('deprecated', result['stderr'].lower())

# If stdout doesnt include global help..
if 'Global arguments available for all' not in result['stdout']:
if GLOBAL_ARGS not in result['stdout']:
# Specifically look for deprecated
self.assertNotIn('deprecated', result['stdout'].lower())
if result['stdout'] == '':
Expand Down

0 comments on commit 9085b71

Please sign in to comment.