jenkins-bot submitted this change.

View Change

Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
[tests] Remove WindowsTerminalTests

WindowsTerminalTest class uses pywin32 but the current implementation
does not provide the requestes modules win32api, win32clipboard and
pywinauto still requires win32api and fails with ImportError.

Conclusion: These tests aren't functional anymore and these tests
can never be runned on Appveyor CI. They can be removed and must
be rewritten.

Bug: T282964
Change-Id: I5a367c3d526ccf53ddc668d625b8d4b7f3fe03e1
---
M .appveyor.yml
M dev-requirements.txt
M setup.py
D tests/ui_tests.bat
M tests/ui_tests.py
5 files changed, 0 insertions(+), 305 deletions(-)

diff --git a/.appveyor.yml b/.appveyor.yml
index ac13e9c..f8a57d6 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -9,7 +9,6 @@
PYWIKIBOT_PASSWD_FILE: "%appdata%\\Pywikibot\\passwordfile"

PYSETUP_TEST_EXTRAS: "1"
- PYSETUP_TEST_NO_UI: "1"
PYWIKIBOT_NO_L10N_TESTS: "1"
PYWIKIBOT_TESTS_RUNNING: "1"

diff --git a/dev-requirements.txt b/dev-requirements.txt
index e7ea1a0..d34ae34 100644
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -20,9 +20,3 @@
flake8-mock>=0.3
codecov
coverage
-
-# pywin32 & pywinauto>=0.4.0 are Win32 UI test dependencies that have been
-# excluded from this file as they are quite expensive to install, and they
-# are not useful on the Appveyor Win32 builds since the relevant UI tests
-# also require accessing the menu of the console window, which doesn't exist
-# in the Appveyor environment.
diff --git a/setup.py b/setup.py
index 384b03e..4a647fc 100644
--- a/setup.py
+++ b/setup.py
@@ -116,17 +116,6 @@

# ------- setup tests_require ------- #
test_deps = ['mock']
-# Some of the ui_tests depend on accessing the console window's menu
-# to set the console font and copy and paste, achieved using pywinauto
-# which depends on pywin32.
-# These tests may be disabled because pywin32 depends on VC++, is time
-# consuming to build, and the console window can't be accessed during AppVeyor
-# builds.
-if os.name == 'nt' and os.environ.get('PYSETUP_TEST_NO_UI', '0') != '1':
- test_deps += [
- 'pywinauto>0.6.4',
- 'pywin32>=225',
- ]

# Add all dependencies as test dependencies,
# so all scripts can be compiled for script_tests, etc.
diff --git a/tests/ui_tests.bat b/tests/ui_tests.bat
deleted file mode 100644
index e850506..0000000
--- a/tests/ui_tests.bat
+++ /dev/null
@@ -1,4 +0,0 @@
-@echo off
-set PYTHONPATH=%~dp0..
-set PYWIKIBOT_DIR=%~dp0..
-"%~dp0ui_tests.py"
diff --git a/tests/ui_tests.py b/tests/ui_tests.py
index 0bfe4d8..4f5e610 100644
--- a/tests/ui_tests.py
+++ b/tests/ui_tests.py
@@ -4,31 +4,10 @@
#
# Distributed under the terms of the MIT license.
#
-# NOTE FOR RUNNING WINDOWS UI TESTS
-#
-# Windows UI tests have to be run using the tests\ui_tests.bat helper script.
-# This will set PYTHONPATH and PYWIKIBOT_DIR, and then run the tests. Do not
-# touch mouse or keyboard while the tests are running, as this might disturb
-# the interaction tests.
-#
-# The Windows tests were developed on a Dutch Windows 7 OS. You might need to
-# adapt the helper functions in TestWindowsTerminalUnicode for other versions.
-#
-# For the Windows-based tests, you need the following packages installed:
-# - pywin32, for clipboard access, which can be installed using:
-# pip install -U pywin32
-#
-# - pywinauto, to send keys to the terminal, which can be installed using:
-# pip install -U pywinauto
-#
-#
-import inspect
import io
import logging
import os
-import subprocess
import sys
-import time
from contextlib import suppress

import pywikibot
@@ -52,26 +31,6 @@
from tests.utils import FakeModule, unittest


-if os.name == 'nt':
- import threading
- from multiprocessing.managers import BaseManager
-
- try:
- import win32api
- except ImportError:
- win32api = None
-
- try:
- import pywinauto
- except ImportError:
- pywinauto = None
-
- try:
- import win32clipboard
- except ImportError:
- win32clipboard = None
-
-
class Stream:

"""Handler for a StringIO or BytesIO instance able to patch itself."""
@@ -99,57 +58,6 @@
self._stream.seek(0)


-if os.name == 'nt':
-
- class pywikibotWrapper:
-
- """pywikibot wrapper class."""
-
- @staticmethod
- def init():
- pywikibot.version._get_program_dir()
-
- @staticmethod
- def output(*args, **kwargs):
- return pywikibot.output(*args, **kwargs)
-
- def request_input(self, *args, **kwargs):
- self.input = None
-
- def threadedinput():
- self.input = pywikibot.input(*args, **kwargs)
- self.inputthread = threading.Thread(target=threadedinput)
- self.inputthread.start()
-
- def get_input(self):
- self.inputthread.join()
- return self.input
-
- @staticmethod
- def set_config(key, value):
- setattr(pywikibot.config, key, value)
-
- @staticmethod
- def set_ui(key, value):
- setattr(pywikibot.ui, key, value)
-
- @staticmethod
- def cls():
- subprocess.run('cls', shell=True)
-
- class pywikibotManager(BaseManager):
-
- """pywikibot manager class."""
-
- pywikibotManager.register('pywikibot', pywikibotWrapper)
- _manager = pywikibotManager(
- address=('127.0.0.1', 47228),
- authkey=b'4DJSchgwy5L5JxueZEWbxyeG')
- if len(sys.argv) > 1 and sys.argv[1] == '--run-as-slave-interpreter':
- s = _manager.get_server()
- s.serve_forever()
-
-
def patched_print(text, target_stream):
try:
stream = patched_streams[target_stream]
@@ -462,197 +370,6 @@
'\x1b[93mu\x1b[0m\x1b[93me\x1b[0m\x1b[93mo\x1b[0m\n')


-@unittest.skipUnless(os.name == 'nt', 'requires Windows console')
-class WindowsTerminalTestCase(UITestCase):
-
- """MS Windows terminal tests."""
-
- @classmethod
- def setUpClass(cls):
- if os.name != 'nt':
- raise unittest.SkipTest('requires Windows console')
- if not win32api:
- raise unittest.SkipTest('requires Windows package pywin32')
- if not win32clipboard:
- raise unittest.SkipTest('requires Windows package win32clipboard')
- if not pywinauto:
- raise unittest.SkipTest('requires Windows package pywinauto')
- try:
- # pywinauto 0.5.0
- cls._app = pywinauto.Application()
- except AttributeError as e1:
- try:
- cls._app = pywinauto.application.Application()
- except AttributeError as e2:
- raise unittest.SkipTest('pywinauto Application failed: {}\n{}'
- .format(e1, e2))
- super().setUpClass()
-
- @classmethod
- def setUpProcess(cls, command):
- si = subprocess.STARTUPINFO()
- si.dwFlags = subprocess.STARTF_USESTDHANDLES
- cls._process = subprocess.Popen(
- command, creationflags=subprocess.CREATE_NEW_CONSOLE)
-
- cls._app.connect_(process=cls._process.pid)
-
- # set truetype font (Lucida Console, hopefully)
- try:
- window = cls._app.window_()
- except Exception as e:
- cls.tearDownProcess()
- raise unittest.SkipTest(
- 'Windows package pywinauto could not locate window: {!r}'
- .format(e))
-
- try:
- window.TypeKeys('% {UP}{ENTER}%L{HOME}L{ENTER}', with_spaces=True)
- except Exception as e:
- cls.tearDownProcess()
- raise unittest.SkipTest(
- 'Windows package pywinauto could not use window TypeKeys: {!r}'
- .format(e))
-
- @classmethod
- def tearDownProcess(cls):
- cls._process.kill()
-
- def setUp(self):
- super().setUp()
- self.setclip('')
-
- def waitForWindow(self):
- while not self._app.window_().IsEnabled():
- time.sleep(0.01)
-
- def getstdouterr(self):
- sentinel = '~~~~SENTINEL~~~~cedcfc9f-7eed-44e2-a176-d8c73136c185'
- # select all and copy to clipboard
- self._app.window_().SetFocus()
- self.waitForWindow()
- self._app.window_().TypeKeys(
- '% {UP}{UP}{UP}{RIGHT}{DOWN}{DOWN}{DOWN}{ENTER}{ENTER}',
- with_spaces=True)
-
- while True:
- data = self.getclip()
- if data != sentinel:
- return data
- time.sleep(0.01)
-
- @staticmethod
- def setclip(text):
- win32clipboard.OpenClipboard()
- win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT, text)
- win32clipboard.CloseClipboard()
-
- @staticmethod
- def getclip():
- win32clipboard.OpenClipboard()
- data = win32clipboard.GetClipboardData(win32clipboard.CF_UNICODETEXT)
- win32clipboard.CloseClipboard()
- data = data.split('\x00')[0]
- data = data.replace('\r\n', '\n')
- return data
-
- def sendstdin(self, text):
- self.setclip(text.replace('\n', '\r\n'))
- self._app.window_().SetFocus()
- self.waitForWindow()
- self._app.window_().TypeKeys(
- '% {UP}{UP}{UP}{RIGHT}{DOWN}{DOWN}{ENTER}',
- with_spaces=True)
-
-
-class TestWindowsTerminalUnicode(WindowsTerminalTestCase):
-
- """MS Windows terminal unicode tests."""
-
- @classmethod
- def setUpClass(cls):
- super().setUpClass()
- fn = inspect.getfile(inspect.currentframe())
- cls.setUpProcess(['python', 'pwb.py', fn,
- '--run-as-slave-interpreter'])
-
- _manager.connect()
- cls.pywikibot = _manager.pywikibot()
-
- @classmethod
- def tearDownClass(cls):
- del cls.pywikibot
- cls.tearDownProcess()
-
- def setUp(self):
- super().setUp()
-
- self.pywikibot.set_config('colorized_output', True)
- self.pywikibot.set_config('transliterate', False)
- self.pywikibot.set_config('console_encoding', 'utf-8')
- self.pywikibot.set_ui('transliteration_target', None)
- self.pywikibot.set_ui('encoding', 'utf-8')
-
- self.pywikibot.cls()
-
- def testOutputUnicodeText_no_transliterate(self):
- self.pywikibot.output('Заглавная_страница')
- self.assertEqual(self.getstdouterr(), 'Заглавная_страница\n')
-
- def testOutputUnicodeText_transliterate(self):
- self.pywikibot.set_config('transliterate', True)
- self.pywikibot.set_ui('transliteration_target', 'latin-1')
- self.pywikibot.output('Заглавная_страница')
- self.assertEqual(self.getstdouterr(), 'Zaglavnaya_stranica\n')
-
- def testInputUnicodeText(self):
- self.pywikibot.set_config('transliterate', True)
-
- self.pywikibot.request_input('Википедию? ')
- self.assertEqual(self.getstdouterr(), 'Википедию?')
- self.sendstdin('Заглавная_страница\n')
- returned = self.pywikibot.get_input()
-
- self.assertEqual(returned, 'Заглавная_страница')
-
-
-class TestWindowsTerminalUnicodeArguments(WindowsTerminalTestCase):
-
- """MS Windows terminal unicode argument tests."""
-
- @classmethod
- def setUpClass(cls):
- super().setUpClass()
- cls.setUpProcess(['cmd', '/k', 'echo off'])
-
- @classmethod
- def tearDownClass(cls):
- cls.tearDownProcess()
-
- def testOutputUnicodeText_no_transliterate(self):
- self.sendstdin(
- 'python -c \"'
- 'import subprocess, pywikibot; '
- "subprocess.run('cls', shell=True); "
- "pywikibot.output('\\n'.join(pywikibot.handle_args()))\" "
- 'Alpha Bετα Гамма دلتا\n')
- lines = []
-
- for _ in range(3):
- lines = self.getstdouterr().split('\n')
- if len(lines) >= 4 and 'Alpha' not in lines:
- # if len(lines) < 4, we assume not all lines had been output
- # yet, and retry. We check at least one of the lines contains
- # "Alpha" to prevent using older clipboard content. We limit
- # the number of retries to 3 so that the test will finish even
- # if neither of these requirements are met.
- break
- time.sleep(1)
-
- # empty line is the new command line
- self.assertEqual(lines, ['Alpha', 'Bετα', 'Гамма', 'دلتا', ''])
-
-
# TODO: add tests for background colors.
class FakeUITest(TestCase):


To view, visit change 691931. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I5a367c3d526ccf53ddc668d625b8d4b7f3fe03e1
Gerrit-Change-Number: 691931
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw@arctus.nl>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged