jenkins-bot has submitted this change and it was merged.
Change subject: Use envvar EDITOR if it exists, with tests
......................................................................
Use envvar EDITOR if it exists, with tests
EDITOR is usually set on Unix platforms to be a basic editor.
Use this as the default editor, if set, even on Windows.
Set EDITOR in the script tests to be a noop (like /bin/true) so
the script continues.
Scripts 'editarticle' and 'upload' are now able to be tested.
Change-Id: I8a069960d0919c760441538c0ac0d11d1015bf01
---
M pywikibot/config2.py
M pywikibot/editor.py
M tests/script_tests.py
3 files changed, 12 insertions(+), 8 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index e24ebca..3cf1608 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -337,6 +337,7 @@
# ############# EXTERNAL EDITOR SETTINGS ##############
# The command for the editor you want to use. If set to None, a simple Tkinter
# editor will be used.
+editor = os.environ.get('EDITOR', None)
# On Windows systems, this script tries to determine the default text editor.
if sys.platform == 'win32':
try:
@@ -350,15 +351,13 @@
_key2 = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT,
'%s\shell\open\command' % _progID)
_cmd = _winreg.QueryValueEx(_key2, None)[0]
- editor = _cmd.replace('%1', '')
+ _cmd = _cmd.replace('%1', '')
# Notepad is even worse than our Tkinter editor.
- if editor.lower().endswith('notepad.exe'):
- editor = None
+ if not _cmd.lower().endswith('notepad.exe'):
+ editor = _cmd
except WindowsError:
# Catch any key lookup errors
- editor = None
-else:
- editor = None
+ pass
# Warning: DO NOT use an editor which doesn't support Unicode to edit pages!
# You will BREAK non-ASCII symbols!
diff --git a/pywikibot/editor.py b/pywikibot/editor.py
index 440dadc..0243717 100644
--- a/pywikibot/editor.py
+++ b/pywikibot/editor.py
@@ -54,7 +54,7 @@
command += " -n%i" % (line + 1) # seems not to support columns
command += ' %s' % tempFilename
- #print command
+ pywikibot.log(u'Running editor: %s' % command)
return command
def convertLinebreaks(self, text):
diff --git a/tests/script_tests.py b/tests/script_tests.py
index d575a66..e37cda9 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -55,7 +55,6 @@
unrunnable_script_list = [
'script_wui', # depends on lua compiling
- 'editarticle', # requires a X DISPLAY
]
deadlock_script_list = [
@@ -211,7 +210,13 @@
else:
return stream
env = os.environ.copy()
+ # sys.path may have been modified by the test runner to load dependencies.
env['PYTHONPATH'] = ":".join(sys.path)
+ # Set EDITOR to an executable that ignores all arguments and does nothing.
+ if sys.platform == 'win32':
+ env['EDITOR'] = 'call'
+ else:
+ env['EDITOR'] = 'true'
options = {
'stdout': subprocess.PIPE,
'stderr': subprocess.PIPE
--
To view, visit
https://gerrit.wikimedia.org/r/172202
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8a069960d0919c760441538c0ac0d11d1015bf01
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>