Page MenuHomePhabricator

TestScriptHelp.test_imagecopy fails in python 3.6 with "TypeError: NoneType takes no arguments"
Closed, ResolvedPublic

Description

https://travis-ci.org/wikimedia/pywikibot-core/jobs/227140487#L4023

________________________ TestScriptHelp.test_imagecopy _________________________

self = <tests.script_tests.TestScriptHelp testMethod=test_imagecopy>

    def testScript(self):

        cmd = [script_name]

    

        if args:

            cmd += args

    

        data_in = script_input.get(script_name)

    

        timeout = 0

        if is_autorun:

            timeout = 5

    

        if self._results and script_name in self._results:

            error = self._results[script_name]

            if isinstance(error, StringTypes):

                stdout = None

            else:

                stdout, error = error

        else:

            stdout = None

            error = None

    

        test_overrides = {}

        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)

    

        stderr = result['stderr'].splitlines()

        stderr_sleep = [l for l in stderr

                        if l.startswith('Sleeping for ')]

        stderr_other = [l for l in stderr

                        if not l.startswith('Sleeping for ')]

        if stderr_sleep:

            print(u'\n'.join(stderr_sleep))

    

        if result['exit_code'] == -9:

            print(' killed', end='  ')

    

        if error:

            self.assertIn(error, result['stderr'])

    

            exit_codes = [0, 1, 2, -9]

        elif not is_autorun:

            if stderr_other == []:

                stderr_other = None

            if stderr_other is not None:

                self.assertIn('Use -help for further information.',

>                             stderr_other)

E               AssertionError: 'Use -help for further information.' not found in ['Traceback (most recent call last):', '  File "<string>", line 1, in <module>', '  File "/home/travis/build/wikimedia/pywikibot-core/pwb.py", line 257, in main', '    run_python_file(filename, [filename] + args, argvu, file_package)', '  File "/home/travis/build/wikimedia/pywikibot-core/pwb.py", line 121, in run_python_file', '    main_mod.__dict__)', '  File "./scripts/imagecopy.py", line 396, in <module>', '    class TkdialogIC(Tkdialog):', 'TypeError: NoneType takes no arguments', 'CRITICAL: Closing network session.']

tests/script_tests.py:295: AssertionError

Event Timeline

$ python pwb.py scripts/imagecopy.py
Traceback (most recent call last):
  File "pwb.py", line 264, in <module>
    if not main():
  File "pwb.py", line 257, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "pwb.py", line 121, in run_python_file
    main_mod.__dict__)
  File ".\scripts\imagecopy.py", line 396, in <module>
    class TkdialogIC(Tkdialog):
TypeError: NoneType takes no arguments
<class 'TypeError'>
CRITICAL: Closing network session.

The reason is the following import:

try:
    from pywikibot.userinterfaces.gui import Tkdialog
except ImportError as _tk_error:
    Tkdialog = None

pywikibot.userinterfaces.gui is broken in python 3.6 because it relies on idlelib which has had a major rewrite in this version.

Importing anything from pywikibot.userinterfaces.gui causes import error. Because of this, Tkdialog is None, therefore it cannot be subclassed. Hence the error: `TypeError: NoneType takes no arguments.
`
As a temporary workaround we can assign object to Tkdialog to pass class construction phase.

Change 351102 had a related patch set uploaded (by Dalba; owner: Dalba):
[pywikibot/core@master] Assign object to Tkdialog if it cannot be imported from gui module

https://gerrit.wikimedia.org/r/351102

Change 351102 merged by jenkins-bot:
[pywikibot/core@master] Assign object to Tkdialog if it cannot be imported from gui module

https://gerrit.wikimedia.org/r/351102

Change 491033 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [bugfix] Fix version comparison

https://gerrit.wikimedia.org/r/491033

Change 491033 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] Fix version comparison

https://gerrit.wikimedia.org/r/491033