jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/459777 )
Change subject: tests/pwb: Put the main body of the scripts in a `if __name__ == '__main__':` ......................................................................
tests/pwb: Put the main body of the scripts in a `if __name__ == '__main__':`
Bug: T204042 Change-Id: Ic4f5bd1d2be4a60598f8ea72b46e183d61491c36 --- M tests/pwb/print_env.py M tests/pwb/print_locals.py M tests/pwb/print_unicode.py 3 files changed, 43 insertions(+), 34 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/pwb/print_env.py b/tests/pwb/print_env.py index 72ffd90..1377c14 100644 --- a/tests/pwb/print_env.py +++ b/tests/pwb/print_env.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- """Script that forms part of pwb_tests.""" # -# (C) Pywikibot team, 2015 +# (C) Pywikibot team, 2015-2018 # # Distributed under the terms of the MIT license. # @@ -13,26 +13,33 @@
from pywikibot.tools import first_upper
-_pwb_dir = os.path.abspath(os.path.join( - os.path.split(__file__)[0], '..', '..')) -_pwb_dir = first_upper(_pwb_dir)
-print('os.environ:') -for k, v in sorted(os.environ.items()): - # Don't leak the password into logs - if k == 'USER_PASSWORD': - continue - # This only appears in subprocesses - if k == 'PYWIKIBOT_DIR_PWB': - continue - print("%r: %r" % (k, v)) +def main(): + """Print environment variables.""" + _pwb_dir = os.path.abspath(os.path.join( + os.path.split(__file__)[0], '..', '..')) + _pwb_dir = first_upper(_pwb_dir)
-print('sys.path:') -for path in sys.path: - if path == '' or path.startswith('.'): - continue - # Normalise DOS drive letter - path = first_upper(path) - if path.startswith(_pwb_dir): - continue - print(path) + print('os.environ:') + for k, v in sorted(os.environ.items()): + # Don't leak the password into logs + if k == 'USER_PASSWORD': + continue + # This only appears in subprocesses + if k == 'PYWIKIBOT_DIR_PWB': + continue + print('{}: {}'.format(k, v)) + + print('sys.path:') + for path in sys.path: + if path == '' or path.startswith('.'): + continue + # Normalise DOS drive letter + path = first_upper(path) + if path.startswith(_pwb_dir): + continue + print(path) + + +if __name__ == '__main__': + main() diff --git a/tests/pwb/print_locals.py b/tests/pwb/print_locals.py index 57951f8..e9d08d4 100644 --- a/tests/pwb/print_locals.py +++ b/tests/pwb/print_locals.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- """Script that forms part of pwb_tests.""" # -# (C) Pywikibot team, 2013-2017 +# (C) Pywikibot team, 2013-2018 # # Distributed under the terms of the MIT license. # @@ -10,11 +10,12 @@
import os.path
-for k, v in sorted(locals().copy().items()): - # Skip a few items that Python 3 adds and are not emulated in pwb. - if k in ['__cached__', '__loader__', '__spec__', '__annotations__']: - continue - if k == '__file__': - print("__file__: %r" % os.path.join('.', os.path.relpath(__file__))) - else: - print("%r: %r" % (k, v)) +if __name__ == '__main__': + for k, v in sorted(locals().copy().items()): + # Skip a few items that Python 3 adds and are not emulated in pwb. + if k in ['__cached__', '__loader__', '__spec__', '__annotations__']: + continue + if k == '__file__': + print('__file__: ' + os.path.join('.', os.path.relpath(__file__))) + else: + print('{}: {}'.format(k, v)) diff --git a/tests/pwb/print_unicode.py b/tests/pwb/print_unicode.py index b8505cd..c02f028 100644 --- a/tests/pwb/print_unicode.py +++ b/tests/pwb/print_unicode.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- """Script that forms part of pwb_tests.""" # -# (C) Pywikibot team, 2015 +# (C) Pywikibot team, 2018 # # Distributed under the terms of the MIT license. # @@ -10,5 +10,6 @@
import pywikibot
-pywikibot.output('Häuser') -print('Häuser') +if __name__ == '__main__': + pywikibot.output('Häuser') + print('Häuser')