Merlijn van Deen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/86384
Change subject: Improve Windows Terminal UI tests
......................................................................
Improve Windows Terminal UI tests
- Refactored generic terminal testcase out of the Windows I/O testcase
- Getstdinout is now triggered by a sentinel being overwritten by the
copy operation
- Wait for the window to be ready before sending keys
Change-Id: Id132afbd51999a7db3974c0fddd5016c35c7a335
---
M tests/ui_tests.py
1 file changed, 48 insertions(+), 12 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/84/86384/1
diff --git a/tests/ui_tests.py b/tests/ui_tests.py
index d4ba066..343e3fc 100644
--- a/tests/ui_tests.py
+++ b/tests/ui_tests.py
@@ -7,6 +7,17 @@
#
# 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 PYWIKIBOT2_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.
+#
__version__ = '$Id$'
import unittest
@@ -15,6 +26,7 @@
import logging
import os
import sys
+import time
if os.name == "nt":
from multiprocessing.managers import BaseManager
@@ -328,19 +340,15 @@
self.assertEqual(newstderr.getvalue(), "abcd
\x1b[33;1mA\x1b[0m\x1b[33;1mB\x1b[0m\x1b[33;1mG\x1b[0m\x1b[33;1mD\x1b[0m
\x1b[33;1ma\x1b[0m\x1b[33;1mb\x1b[0m\x1b[33;1mg\x1b[0m\x1b[33;1md\x1b[0m
\x1b[33;1ma\x1b[0m\x1b[33;1mi\x1b[0m\x1b[33;1mu\x1b[0m\x1b[33;1me\x1b[0m\x1b[33;1mo\x1b[0m\n\x1b[0m")
# noqa
@unittest.skipUnless(os.name == "nt", "requires Windows console")
- class TestWindowsTerminalUnicode(UITestCase):
+ class WindowsTerminalTestCase(UITestCase):
@classmethod
- def setUpClass(cls):
- import inspect
+ def setUpProcess(cls, command):
import pywinauto
import subprocess
si = subprocess.STARTUPINFO()
si.dwFlags = subprocess.STARTF_USESTDHANDLES
- fn = inspect.getfile(inspect.currentframe())
- cls._process = subprocess.Popen(["python", "pwb.py", fn,
"--run-as-slave-interpreter"],
+ cls._process = subprocess.Popen(command,
creationflags=subprocess.CREATE_NEW_CONSOLE)
- _manager.connect()
- cls.pywikibot = _manager.pywikibot()
cls._app = pywinauto.application.Application()
cls._app.connect_(process=cls._process.pid)
@@ -349,15 +357,29 @@
cls._app.window_().TypeKeys("% {UP}{ENTER}^L{HOME}L{ENTER}",
with_spaces=True)
@classmethod
- def tearDownClass(cls):
- del cls.pywikibot
+ def tearDownProcess(cls):
cls._process.kill()
+ def setUp(self):
+ super(WindowsTerminalTestCase, self).setUp()
+ self.setclip(u'')
+
+ def waitForWindow(self):
+ while not self._app.window_().IsEnabled():
+ time.sleep(0.01)
+
def getstdouterr(self):
+ sentinel = u'~~~~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)
- return self.getclip()
+
+ while True:
+ data = self.getclip()
+ if data != sentinel:
+ return data
+ time.sleep(0.01)
def setclip(self, text):
win32clipboard.OpenClipboard()
@@ -375,8 +397,23 @@
def sendstdin(self, text):
self.setclip(text.replace(u"\n", u"\r\n"))
self._app.window_().SetFocus()
+ self.waitForWindow()
self._app.window_().TypeKeys('%
{UP}{UP}{UP}{RIGHT}{DOWN}{DOWN}{ENTER}', with_spaces=True)
- self.setclip(u'')
+
+ class TestWindowsTerminalUnicode(WindowsTerminalTestCase):
+ @classmethod
+ def setUpClass(cls):
+ import inspect
+ 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(TestWindowsTerminalUnicode, self).setUp()
@@ -388,7 +425,6 @@
self.pywikibot.set_ui('encoding', 'utf-8')
self.pywikibot.cls()
- self.setclip(u'')
def testOutputUnicodeText_no_transliterate(self):
self.pywikibot.output(u"Заглавная_страница")
--
To view, visit https://gerrit.wikimedia.org/r/86384
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id132afbd51999a7db3974c0fddd5016c35c7a335
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits