Page MenuHomePhabricator

script_tests fails for editarticle in windows environment
Closed, ResolvedPublic

Description

======================================================================
FAIL: test_editarticle (__main__.TestScriptSimulate)
Test running editarticle -simulate.
----------------------------------------------------------------------
Traceback (most recent call last):
  File ".\tests\script_tests.py", line 287, in testScript
    self.assertIn(error, result['stderr'])
AssertionError: u'Nothing changed' not found in u'Page to edit: Traceback (most
recent call last):\r\n  File "C:\\pwb\\GIT\\core\\pwb.py", line 256, in <module>
\r\n    if not main():\r\n  File "C:\\pwb\\GIT\\core\\pwb.py", line 250, in main
\r\n    run_python_file(filename, [filename] + args, argvu, file_package)\r\n  F
ile "C:\\pwb\\GIT\\core\\pwb.py", line 121, in run_python_file\r\n    main_mod._
_dict__)\r\n  File ".\\scripts\\editarticle.py", line 136, in <module>\r\n    ma
in()\r\n  File ".\\scripts\\editarticle.py", line 132, in main\r\n    app.run()\
r\n  File ".\\scripts\\editarticle.py", line 107, in run\r\n    new = textEditor
.edit(old)\r\n  File "C:\\pwb\\GIT\\core\\pywikibot\\editor.py", line 106, in ed
it\r\n    subprocess.call(self._command(tempFilename, text, jumpIndex))\r\n  Fil
e "C:\\Python27\\lib\\subprocess.py", line 522, in call\r\n    return Popen(*pop
enargs, **kwargs).wait()\r\n  File "C:\\Python27\\lib\\subprocess.py", line 710,
 in __init__\r\n    errread, errwrite)\r\n  File "C:\\Python27\\lib\\subprocess.
py", line 958, in _execute_child\r\n    startupinfo)\r\nWindowsError: [Error 2]
Das System kann die angegebene Datei nicht finden\r\nCRITICAL: Closing network s
ession.\r\n'


======================================================================

Looks like a windows problem, maybe it has to do with subprocess.call(). I remember we had sth like this in compat version of version.py

Event Timeline

Xqt triaged this task as Low priority.Mar 1 2016, 11:37 AM
Xqt added a subscriber: DrTrigon.
jayvdb renamed this task from script_tests failes for editarticle in windows environment to script_tests fails for editarticle in windows environment.Mar 6 2016, 1:18 AM

I had it again. I guess there is a problem with the temporary file because it was failing with the self._command(tempFilename, text, jumpIndex) call

This comment was removed by Dvorapa.
Dvorapa raised the priority of this task from Low to High.Apr 5 2020, 4:58 PM
Page to edit: Traceback (most recent call last):
  File "C:\\projects\\pywikibot-g4xqx\\pwb.py", line 390, in <module>
    if not main():
  File "C:\\projects\\pywikibot-g4xqx\\pwb.py", line 385, in main
    file_package)
  File "C:\\projects\\pywikibot-g4xqx\\pwb.py", line 101, in run_python_file
    main_mod.__dict__)
  File ".\\scripts\\editarticle.py", line 129, in <module>
    main()
  File ".\\scripts\\editarticle.py", line 125, in main
    app.run()
  File ".\\scripts\\editarticle.py", line 100, in run
    new = text_editor.edit(old)
  File "C:\\projects\\pywikibot-g4xqx\\pywikibot\\editor.py", line 104, in edit
    subprocess.call(self._command(tempFilename, text, jumpIndex))
  File "c:\\python27\\Lib\\subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "c:\\python27\\Lib\\subprocess.py", line 394, in __init__
    errread, errwrite)
  File "c:\\python27\\Lib\\subprocess.py", line 644, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
CRITICAL: Exiting due to uncaught exception <type \'exceptions.WindowsError\'>

Seems the temp file is removed after closing. But keeping them open leads to a "Permission error: the file is already used by another process" or sth like that.

Can't we disable Python's automatic removal and let Pywikibot remove it once not needed?

Probably it has to do with https://bugs.python.org/issue22107
A solution might be to use

try:
    subprocess.call(cmd)
except FileNotFoundError:
    pywikibot.exception()

within pywikibot.editor lines 104++ because for the -simulate test the edit/editor does not care. We also could have a return statement at the first line of Editor.edit() method to have the test passing.

Change 587708 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [tests] Ignore FileNotFoundError for Windows within editor.edit()

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

Change 587841 had a related patch set uploaded (by Dvorapa; owner: Dvorapa):
[pywikibot/core@master] [bugfix] Fix WindowsError caused by internal command-line command

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

Change 587708 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] Fix FileNotFoundError within editor.edit()

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

Change 587841 abandoned by Dvorapa:
[bugfix] Fix WindowsError caused by internal command-line command

Reason:
In favor of https://gerrit.wikimedia.org/r/#/c/pywikibot/core/ /587708/

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

Xqt claimed this task.