jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] ui tests: deindent source code
......................................................................
[IMPROV] ui tests: deindent source code
With 03477f98e54ff2b91cc1938abb3742cee215fa59 the ui_tests now run
outside of __name__ == __main__'. To have the number of changes minimal
it didn't deindent the source code but just changed the if-condition to
be always True.
Change-Id: I2ab67f422a1d9df1da1ae0523f3f163577c416c1
---
M tests/ui_tests.py
1 file changed, 372 insertions(+), 359 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/ui_tests.py b/tests/ui_tests.py
index 365b329..9229769 100644
--- a/tests/ui_tests.py
+++ b/tests/ui_tests.py
@@ -129,476 +129,489 @@
return strin._stream.readline().strip()
-# TODO: This complete section doesn't depend on __name__ == '__main__' anymore
-if True:
- patched_streams = {}
- strout = Stream('out', patched_streams)
- strerr = Stream('err', patched_streams)
- strin = Stream('in', {})
+patched_streams = {}
+strout = Stream('out', patched_streams)
+strerr = Stream('err', patched_streams)
+strin = Stream('in', {})
- newstdout = strout._stream
- newstderr = strerr._stream
- newstdin = strin._stream
+newstdout = strout._stream
+newstderr = strerr._stream
+newstdin = strin._stream
- org_print = ui._print
- org_input = ui._raw_input
+org_print = ui._print
+org_input = ui._raw_input
- def patch():
- """Patch standard terminal files."""
- strout.reset()
- strerr.reset()
- strin.reset()
- ui._print = patched_print
- ui._raw_input = patched_input
- def unpatch():
- """un-patch standard terminal files."""
- ui._print = org_print
- ui._raw_input = org_input
+def patch():
+ """Patch standard terminal files."""
+ strout.reset()
+ strerr.reset()
+ strin.reset()
+ ui._print = patched_print
+ ui._raw_input = patched_input
- logger = logging.getLogger('pywiki')
- loggingcontext = {'caller_name': "ui_tests",
- 'caller_file': "ui_tests",
- 'caller_line': 0,
- 'newline': "\n"}
- class UITestCase(unittest.TestCase):
+def unpatch():
+ """un-patch standard terminal files."""
+ ui._print = org_print
+ ui._raw_input = org_input
- """UI tests."""
+logger = logging.getLogger('pywiki')
+loggingcontext = {'caller_name': "ui_tests",
+ 'caller_file': "ui_tests",
+ 'caller_line': 0,
+ 'newline': "\n"}
- net = False
- def setUp(self):
- patch()
+class UITestCase(unittest.TestCase):
- pywikibot.config.colorized_output = True
- pywikibot.config.transliterate = False
- pywikibot.ui.transliteration_target = None
- pywikibot.ui.encoding = 'utf-8'
+ """UI tests."""
- def tearDown(self):
- unpatch()
+ net = False
- def _encode(self, string, encoding='utf-8'):
- if sys.version_info[0] > 2:
- return string
- else:
- return string.encode(encoding)
+ def setUp(self):
+ patch()
- class TestTerminalOutput(UITestCase):
+ pywikibot.config.colorized_output = True
+ pywikibot.config.transliterate = False
+ pywikibot.ui.transliteration_target = None
+ pywikibot.ui.encoding = 'utf-8'
- """Terminal output tests."""
+ def tearDown(self):
+ unpatch()
- def testOutputLevels_logging_debug(self):
- logger.log(DEBUG, 'debug', extra=loggingcontext)
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(newstderr.getvalue(), "")
+ def _encode(self, string, encoding='utf-8'):
+ if sys.version_info[0] > 2:
+ return string
+ else:
+ return string.encode(encoding)
- def testOutputLevels_logging_verbose(self):
- logger.log(VERBOSE, 'verbose', extra=loggingcontext)
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(newstderr.getvalue(), "")
- def testOutputLevels_logging_info(self):
- logger.log(INFO, 'info', extra=loggingcontext)
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(newstderr.getvalue(), "info\n")
+class TestTerminalOutput(UITestCase):
- def testOutputLevels_logging_stdout(self):
- logger.log(STDOUT, 'stdout', extra=loggingcontext)
- self.assertEqual(newstdout.getvalue(), "stdout\n")
- self.assertEqual(newstderr.getvalue(), "")
+ """Terminal output tests."""
- def testOutputLevels_logging_input(self):
- logger.log(INPUT, 'input', extra=loggingcontext)
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(newstderr.getvalue(), "input\n")
+ def testOutputLevels_logging_debug(self):
+ logger.log(DEBUG, 'debug', extra=loggingcontext)
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(newstderr.getvalue(), "")
- def testOutputLevels_logging_WARNING(self):
- logger.log(WARNING, 'WARNING', extra=loggingcontext)
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(newstderr.getvalue(), "WARNING: WARNING\n")
+ def testOutputLevels_logging_verbose(self):
+ logger.log(VERBOSE, 'verbose', extra=loggingcontext)
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(newstderr.getvalue(), "")
- def testOutputLevels_logging_ERROR(self):
- logger.log(ERROR, 'ERROR', extra=loggingcontext)
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(newstderr.getvalue(), "ERROR: ERROR\n")
+ def testOutputLevels_logging_info(self):
+ logger.log(INFO, 'info', extra=loggingcontext)
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(newstderr.getvalue(), "info\n")
- def testOutputLevels_logging_CRITICAL(self):
- logger.log(CRITICAL, 'CRITICAL', extra=loggingcontext)
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(newstderr.getvalue(), "CRITICAL: CRITICAL\n")
+ def testOutputLevels_logging_stdout(self):
+ logger.log(STDOUT, 'stdout', extra=loggingcontext)
+ self.assertEqual(newstdout.getvalue(), "stdout\n")
+ self.assertEqual(newstderr.getvalue(), "")
- def test_output(self):
- pywikibot.output("output", toStdout=False)
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(newstderr.getvalue(), "output\n")
+ def testOutputLevels_logging_input(self):
+ logger.log(INPUT, 'input', extra=loggingcontext)
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(newstderr.getvalue(), "input\n")
- def test_output_stdout(self):
- pywikibot.output("output", toStdout=True)
- self.assertEqual(newstdout.getvalue(), "output\n")
- self.assertEqual(newstderr.getvalue(), "")
+ def testOutputLevels_logging_WARNING(self):
+ logger.log(WARNING, 'WARNING', extra=loggingcontext)
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(newstderr.getvalue(), "WARNING: WARNING\n")
- def test_warning(self):
- pywikibot.warning("warning")
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(newstderr.getvalue(), "WARNING: warning\n")
+ def testOutputLevels_logging_ERROR(self):
+ logger.log(ERROR, 'ERROR', extra=loggingcontext)
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(newstderr.getvalue(), "ERROR: ERROR\n")
- def test_error(self):
- pywikibot.error("error")
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(newstderr.getvalue(), "ERROR: error\n")
+ def testOutputLevels_logging_CRITICAL(self):
+ logger.log(CRITICAL, 'CRITICAL', extra=loggingcontext)
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(newstderr.getvalue(), "CRITICAL: CRITICAL\n")
- def test_log(self):
- pywikibot.log("log")
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(newstderr.getvalue(), "")
+ def test_output(self):
+ pywikibot.output("output", toStdout=False)
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(newstderr.getvalue(), "output\n")
- def test_critical(self):
- pywikibot.critical("critical")
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(newstderr.getvalue(), "CRITICAL: critical\n")
+ def test_output_stdout(self):
+ pywikibot.output("output", toStdout=True)
+ self.assertEqual(newstdout.getvalue(), "output\n")
+ self.assertEqual(newstderr.getvalue(), "")
- def test_debug(self):
- pywikibot.debug("debug", "test")
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(newstderr.getvalue(), "")
+ def test_warning(self):
+ pywikibot.warning("warning")
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(newstderr.getvalue(), "WARNING: warning\n")
- def test_exception(self):
- class TestException(Exception):
- pass
- try:
- raise TestException("Testing Exception")
- except TestException:
- pywikibot.exception("exception")
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(newstderr.getvalue(), "ERROR: TestException:
Testing Exception\n")
+ def test_error(self):
+ pywikibot.error("error")
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(newstderr.getvalue(), "ERROR: error\n")
- def test_exception_tb(self):
- class TestException(Exception):
- pass
- try:
- raise TestException("Testing Exception")
- except TestException:
- pywikibot.exception("exception", tb=True)
- self.assertEqual(newstdout.getvalue(), "")
- stderrlines = newstderr.getvalue().split("\n")
- self.assertEqual(stderrlines[0], "ERROR: TestException: Testing
Exception")
- self.assertEqual(stderrlines[1], "Traceback (most recent call
last):")
- self.assertEqual(stderrlines[3], """ raise
TestException("Testing Exception")""")
- self.assertTrue(stderrlines[4].endswith(': Testing Exception'))
+ def test_log(self):
+ pywikibot.log("log")
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(newstderr.getvalue(), "")
- self.assertNotEqual(stderrlines[-1], "\n")
+ def test_critical(self):
+ pywikibot.critical("critical")
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(newstderr.getvalue(), "CRITICAL: critical\n")
- class TestTerminalInput(UITestCase):
+ def test_debug(self):
+ pywikibot.debug("debug", "test")
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(newstderr.getvalue(), "")
- """Terminal input tests."""
+ def test_exception(self):
+ class TestException(Exception):
- input_choice_output = "question ([A]nswer 1, a[n]swer 2, an[s]wer 3) "
+ """Test Exception."""
- def testInput(self):
- newstdin.write("input to read\n")
- newstdin.seek(0)
+ try:
+ raise TestException("Testing Exception")
+ except TestException:
+ pywikibot.exception("exception")
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(newstderr.getvalue(), "ERROR: TestException: Testing
Exception\n")
- returned = pywikibot.input("question")
+ def test_exception_tb(self):
+ class TestException(Exception):
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(newstderr.getvalue(), "question ")
+ """Test Exception."""
- self.assertIsInstance(returned, unicode)
- self.assertEqual(returned, u"input to read")
+ try:
+ raise TestException("Testing Exception")
+ except TestException:
+ pywikibot.exception("exception", tb=True)
+ self.assertEqual(newstdout.getvalue(), "")
+ stderrlines = newstderr.getvalue().split("\n")
+ self.assertEqual(stderrlines[0], "ERROR: TestException: Testing
Exception")
+ self.assertEqual(stderrlines[1], "Traceback (most recent call last):")
+ self.assertEqual(stderrlines[3], """ raise TestException("Testing
Exception")""")
+ self.assertTrue(stderrlines[4].endswith(': Testing Exception'))
- def _call_input_choice(self):
- rv = pywikibot.input_choice(
- "question",
- (('answer 1', u'A'),
- ('answer 2', u'N'),
- ('answer 3', u'S')),
- u'A',
- automatic_quit=False)
+ self.assertNotEqual(stderrlines[-1], "\n")
- self.assertEqual(newstdout.getvalue(), "")
- self.assertIsInstance(rv, unicode)
+class TestTerminalInput(UITestCase):
- return rv
+ """Terminal input tests."""
- def testInputChoiceDefault(self):
- newstdin.write("\n")
- newstdin.seek(0)
+ input_choice_output = "question ([A]nswer 1, a[n]swer 2, an[s]wer 3) "
- returned = self._call_input_choice()
+ def testInput(self):
+ newstdin.write("input to read\n")
+ newstdin.seek(0)
- self.assertEqual(returned, "a")
+ returned = pywikibot.input("question")
- def testInputChoiceCapital(self):
- newstdin.write("N\n")
- newstdin.seek(0)
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(newstderr.getvalue(), "question ")
- returned = self._call_input_choice()
+ self.assertIsInstance(returned, unicode)
+ self.assertEqual(returned, u"input to read")
- self.assertEqual(newstderr.getvalue(), self.input_choice_output)
+ def _call_input_choice(self):
+ rv = pywikibot.input_choice(
+ "question",
+ (('answer 1', u'A'),
+ ('answer 2', u'N'),
+ ('answer 3', u'S')),
+ u'A',
+ automatic_quit=False)
- self.assertEqual(returned, "n")
+ self.assertEqual(newstdout.getvalue(), "")
- def testInputChoiceNonCapital(self):
- newstdin.write("n\n")
- newstdin.seek(0)
+ self.assertIsInstance(rv, unicode)
- returned = self._call_input_choice()
+ return rv
- self.assertEqual(newstderr.getvalue(), self.input_choice_output)
+ def testInputChoiceDefault(self):
+ newstdin.write("\n")
+ newstdin.seek(0)
- self.assertEqual(returned, "n")
+ returned = self._call_input_choice()
- def testInputChoiceIncorrectAnswer(self):
- newstdin.write("X\nN\n")
- newstdin.seek(0)
+ self.assertEqual(returned, "a")
- returned = self._call_input_choice()
+ def testInputChoiceCapital(self):
+ newstdin.write("N\n")
+ newstdin.seek(0)
- self.assertEqual(newstderr.getvalue(),
- self.input_choice_output * 2)
+ returned = self._call_input_choice()
+
+ self.assertEqual(newstderr.getvalue(), self.input_choice_output)
+
+ self.assertEqual(returned, "n")
+
+ def testInputChoiceNonCapital(self):
+ newstdin.write("n\n")
+ newstdin.seek(0)
+
+ returned = self._call_input_choice()
+
+ self.assertEqual(newstderr.getvalue(), self.input_choice_output)
+
+ self.assertEqual(returned, "n")
+
+ def testInputChoiceIncorrectAnswer(self):
+ newstdin.write("X\nN\n")
+ newstdin.seek(0)
+
+ returned = self._call_input_choice()
+
+ self.assertEqual(newstderr.getvalue(),
+ self.input_choice_output * 2)
+
+ self.assertEqual(returned, "n")
+
+
[email protected](os.name == "posix", "requires Unix console")
+class TestTerminalOutputColorUnix(UITestCase):
+
+ """Terminal output color tests."""
+
+ str1 = 'text \03{lightpurple}light purple text\03{default} text'
+
+ def testOutputColorizedText(self):
+ pywikibot.output(self.str1)
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(
+ newstderr.getvalue(),
+ 'text \x1b[95mlight purple text\x1b[0m text\n\x1b[0m')
- self.assertEqual(returned, "n")
+ def testOutputNoncolorizedText(self):
+ pywikibot.config.colorized_output = False
+ pywikibot.output(self.str1)
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(
+ newstderr.getvalue(),
+ 'text light purple text text ***\n')
- @unittest.skipUnless(os.name == "posix", "requires Unix console")
- class TestTerminalOutputColorUnix(UITestCase):
+ str2 = ('normal text \03{lightpurple} light purple ' +
+ '\03{lightblue} light blue \03{default} light purple ' +
+ '\03{default} normal text')
- """Terminal output color tests."""
+ @unittest.expectedFailure
+ def testOutputColorCascade(self):
+ pywikibot.output(self.str2)
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(
+ newstderr.getvalue(),
+ 'normal text \x1b[35;1m light purple ' +
+ '\x1b[94m light blue \x1b[35;1m light purple ' +
+ '\x1b[0m normal text\n\x1b[0m')
- str1 = 'text \03{lightpurple}light purple text\03{default} text'
+ def testOutputColorCascade_incorrect(self):
+ """ Test incorrect behavior of testOutputColorCascade. """
+ pywikibot.output(self.str2)
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(
+ newstderr.getvalue(),
+ 'normal text \x1b[95m light purple ' +
+ '\x1b[94m light blue \x1b[0m light purple ' +
+ '\x1b[0m normal text\n\x1b[0m')
- def testOutputColorizedText(self):
- pywikibot.output(self.str1)
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(
- newstderr.getvalue(),
- 'text \x1b[95mlight purple text\x1b[0m text\n\x1b[0m')
- def testOutputNoncolorizedText(self):
- pywikibot.config.colorized_output = False
- pywikibot.output(self.str1)
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(
- newstderr.getvalue(),
- 'text light purple text text ***\n')
[email protected](os.name == "posix", "requires Unix console")
+class TestTerminalUnicodeUnix(UITestCase):
- str2 = ('normal text \03{lightpurple} light purple ' +
- '\03{lightblue} light blue \03{default} light purple ' +
- '\03{default} normal text')
+ """Terminal output tests for unix."""
- @unittest.expectedFailure
- def testOutputColorCascade(self):
- pywikibot.output(self.str2)
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(
- newstderr.getvalue(),
- 'normal text \x1b[35;1m light purple ' +
- '\x1b[94m light blue \x1b[35;1m light purple ' +
- '\x1b[0m normal text\n\x1b[0m')
+ def testOutputUnicodeText(self):
+ pywikibot.output(u"Заглавная_страница")
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(
+ newstderr.getvalue(),
+ self._encode(u'Заглавная_страница\n', 'utf-8'))
- def testOutputColorCascade_incorrect(self):
- """ Test incorrect behavior of testOutputColorCascade. """
- pywikibot.output(self.str2)
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(
- newstderr.getvalue(),
- 'normal text \x1b[95m light purple ' +
- '\x1b[94m light blue \x1b[0m light purple ' +
- '\x1b[0m normal text\n\x1b[0m')
+ def testInputUnicodeText(self):
+ newstdin.write(self._encode(u'Заглавная_страница\n', 'utf-8'))
+ newstdin.seek(0)
- @unittest.skipUnless(os.name == "posix", "requires Unix console")
- class TestTerminalUnicodeUnix(UITestCase):
+ returned = pywikibot.input(u"Википедию? ")
- """Terminal output tests for unix."""
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(
+ newstderr.getvalue(),
+ self._encode(u'Википедию? ', 'utf-8'))
- def testOutputUnicodeText(self):
- pywikibot.output(u"Заглавная_страница")
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(
- newstderr.getvalue(),
- self._encode(u'Заглавная_страница\n', 'utf-8'))
+ self.assertIsInstance(returned, unicode)
+ self.assertEqual(returned, u"Заглавная_страница")
- def testInputUnicodeText(self):
- newstdin.write(self._encode(u'Заглавная_страница\n', 'utf-8'))
- newstdin.seek(0)
- returned = pywikibot.input(u"Википедию? ")
[email protected](os.name == "posix", "requires Unix console")
+class TestTransliterationUnix(UITestCase):
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(
- newstderr.getvalue(),
- self._encode(u'Википедию? ', 'utf-8'))
+ """Terminal output transliteration tests."""
- self.assertIsInstance(returned, unicode)
- self.assertEqual(returned, u"Заглавная_страница")
+ def testOutputTransliteratedUnicodeText(self):
+ pywikibot.ui.encoding = 'latin-1'
+ pywikibot.config.transliterate = True
+ pywikibot.output(u"abcd АБГД αβγδ あいうえお")
+ self.assertEqual(newstdout.getvalue(), "")
+ self.assertEqual(
+ newstderr.getvalue(),
+ 'abcd \x1b[93mA\x1b[0m\x1b[93mB\x1b[0m\x1b[93mG\x1b[0m'
+ '\x1b[93mD\x1b[0m \x1b[93ma\x1b[0m\x1b[93mb\x1b[0m\x1b[93mg'
+ '\x1b[0m\x1b[93md\x1b[0m \x1b[93ma\x1b[0m\x1b[93mi\x1b[0m'
+ '\x1b[93mu\x1b[0m\x1b[93me\x1b[0m\x1b[93mo\x1b[0m\n\x1b[0m')
- @unittest.skipUnless(os.name == "posix", "requires Unix console")
- class TestTransliterationUnix(UITestCase):
- """Terminal output transliteration tests."""
[email protected](os.name == "nt", "requires Windows console")
+class WindowsTerminalTestCase(UITestCase):
- def testOutputTransliteratedUnicodeText(self):
- pywikibot.ui.encoding = 'latin-1'
- pywikibot.config.transliterate = True
- pywikibot.output(u"abcd АБГД αβγδ あいうえお")
- self.assertEqual(newstdout.getvalue(), "")
- self.assertEqual(
- newstderr.getvalue(),
- 'abcd \x1b[93mA\x1b[0m\x1b[93mB\x1b[0m\x1b[93mG\x1b[0m'
- '\x1b[93mD\x1b[0m \x1b[93ma\x1b[0m\x1b[93mb\x1b[0m\x1b[93mg'
- '\x1b[0m\x1b[93md\x1b[0m \x1b[93ma\x1b[0m\x1b[93mi\x1b[0m'
- '\x1b[93mu\x1b[0m\x1b[93me\x1b[0m\x1b[93mo\x1b[0m\n\x1b[0m')
+ """MS Windows terminal tests."""
- @unittest.skipUnless(os.name == "nt", "requires Windows console")
- class WindowsTerminalTestCase(UITestCase):
+ @classmethod
+ def setUpClass(cls):
+ if os.name != 'nt':
+ raise unittest.SkipTest('requires Windows console')
+ super(WindowsTerminalTestCase, cls).setUpClass()
- """MS Windows terminal tests."""
+ @classmethod
+ def setUpProcess(cls, command):
+ import pywinauto
+ import subprocess
+ si = subprocess.STARTUPINFO()
+ si.dwFlags = subprocess.STARTF_USESTDHANDLES
+ cls._process = subprocess.Popen(command,
+
creationflags=subprocess.CREATE_NEW_CONSOLE)
- @classmethod
- def setUpClass(cls):
- if os.name != 'nt':
- raise unittest.SkipTest('requires Windows console')
- super(WindowsTerminalTestCase, cls).setUpClass()
+ cls._app = pywinauto.application.Application()
+ cls._app.connect_(process=cls._process.pid)
- @classmethod
- def setUpProcess(cls, command):
- import pywinauto
- import subprocess
- si = subprocess.STARTUPINFO()
- si.dwFlags = subprocess.STARTF_USESTDHANDLES
- cls._process = subprocess.Popen(command,
-
creationflags=subprocess.CREATE_NEW_CONSOLE)
+ # set truetype font (Lucida Console, hopefully)
+ cls._app.window_().TypeKeys("% {UP}{ENTER}^L{HOME}L{ENTER}",
with_spaces=True)
- cls._app = pywinauto.application.Application()
- cls._app.connect_(process=cls._process.pid)
+ @classmethod
+ def tearDownProcess(cls):
+ cls._process.kill()
- # set truetype font (Lucida Console, hopefully)
- cls._app.window_().TypeKeys("% {UP}{ENTER}^L{HOME}L{ENTER}",
with_spaces=True)
+ def setUp(self):
+ super(WindowsTerminalTestCase, self).setUp()
+ self.setclip(u'')
- @classmethod
- def tearDownProcess(cls):
- cls._process.kill()
+ def waitForWindow(self):
+ while not self._app.window_().IsEnabled():
+ time.sleep(0.01)
- def setUp(self):
- super(WindowsTerminalTestCase, self).setUp()
- self.setclip(u'')
+ 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)
- def waitForWindow(self):
- while not self._app.window_().IsEnabled():
- time.sleep(0.01)
+ while True:
+ data = self.getclip()
+ if data != sentinel:
+ return data
+ 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)
+ def setclip(self, text):
+ import win32clipboard
- while True:
- data = self.getclip()
- if data != sentinel:
- return data
- time.sleep(0.01)
+ win32clipboard.OpenClipboard()
+ win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT,
unicode(text))
+ win32clipboard.CloseClipboard()
- def setclip(self, text):
- import win32clipboard
+ def getclip(self):
+ import win32clipboard
- win32clipboard.OpenClipboard()
- win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT,
unicode(text))
- win32clipboard.CloseClipboard()
+ win32clipboard.OpenClipboard()
+ data = win32clipboard.GetClipboardData(win32clipboard.CF_UNICODETEXT)
+ win32clipboard.CloseClipboard()
+ data = data.split(u"\x00")[0]
+ data = data.replace(u"\r\n", u"\n")
+ return data
- def getclip(self):
- import win32clipboard
+ 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)
- win32clipboard.OpenClipboard()
- data =
win32clipboard.GetClipboardData(win32clipboard.CF_UNICODETEXT)
- win32clipboard.CloseClipboard()
- data = data.split(u"\x00")[0]
- data = data.replace(u"\r\n", u"\n")
- return data
- 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)
+class TestWindowsTerminalUnicode(WindowsTerminalTestCase):
- class TestWindowsTerminalUnicode(WindowsTerminalTestCase):
+ """MS Windows terminal unicode tests."""
- """MS Windows terminal unicode tests."""
+ @classmethod
+ def setUpClass(cls):
+ super(TestWindowsTerminalUnicode, cls).setUpClass()
+ import inspect
+ fn = inspect.getfile(inspect.currentframe())
+ cls.setUpProcess(["python", "pwb.py", fn,
"--run-as-slave-interpreter"])
- @classmethod
- def setUpClass(cls):
- super(TestWindowsTerminalUnicode, cls).setUpClass()
- import inspect
- fn = inspect.getfile(inspect.currentframe())
- cls.setUpProcess(["python", "pwb.py", fn,
"--run-as-slave-interpreter"])
+ _manager.connect()
+ cls.pywikibot = _manager.pywikibot()
- _manager.connect()
- cls.pywikibot = _manager.pywikibot()
+ @classmethod
+ def tearDownClass(cls):
+ del cls.pywikibot
+ cls.tearDownProcess()
- @classmethod
- def tearDownClass(cls):
- del cls.pywikibot
- cls.tearDownProcess()
+ def setUp(self):
+ super(TestWindowsTerminalUnicode, self).setUp()
- def setUp(self):
- super(TestWindowsTerminalUnicode, self).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.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()
- self.pywikibot.cls()
+ def testOutputUnicodeText_no_transliterate(self):
+ self.pywikibot.output(u"Заглавная_страница")
+ self.assertEqual(self.getstdouterr(), u"Заглавная_страница\n")
- def testOutputUnicodeText_no_transliterate(self):
- self.pywikibot.output(u"Заглавная_страница")
- self.assertEqual(self.getstdouterr(), u"Заглавная_страница\n")
+ def testOutputUnicodeText_transliterate(self):
+ self.pywikibot.set_config('transliterate', True)
+ self.pywikibot.set_ui('transliteration_target', 'latin-1')
+ self.pywikibot.output(u"Заглавная_страница")
+ self.assertEqual(self.getstdouterr(), "Zaglavnaya_stranica\n")
- def testOutputUnicodeText_transliterate(self):
- self.pywikibot.set_config('transliterate', True)
- self.pywikibot.set_ui('transliteration_target', 'latin-1')
- self.pywikibot.output(u"Заглавная_страница")
- self.assertEqual(self.getstdouterr(), "Zaglavnaya_stranica\n")
+ def testInputUnicodeText(self):
+ self.pywikibot.set_config('transliterate', True)
- def testInputUnicodeText(self):
- self.pywikibot.set_config('transliterate', True)
+ self.pywikibot.request_input(u"Википедию? ")
+ self.assertEqual(self.getstdouterr(), u"Википедию?")
+ self.sendstdin(u"Заглавная_страница\n")
+ returned = self.pywikibot.get_input()
- self.pywikibot.request_input(u"Википедию? ")
- self.assertEqual(self.getstdouterr(), u"Википедию?")
- self.sendstdin(u"Заглавная_страница\n")
- returned = self.pywikibot.get_input()
+ self.assertEqual(returned, u"Заглавная_страница")
- self.assertEqual(returned, u"Заглавная_страница")
- class TestWindowsTerminalUnicodeArguments(WindowsTerminalTestCase):
+class TestWindowsTerminalUnicodeArguments(WindowsTerminalTestCase):
- """MS Windows terminal unicode argument tests."""
+ """MS Windows terminal unicode argument tests."""
- @classmethod
- def setUpClass(cls):
- super(TestWindowsTerminalUnicodeArguments, cls).setUpClass()
- cls.setUpProcess(["cmd", "/k", "echo off"])
+ @classmethod
+ def setUpClass(cls):
+ super(TestWindowsTerminalUnicodeArguments, cls).setUpClass()
+ cls.setUpProcess(["cmd", "/k", "echo off"])
- @classmethod
- def tearDownClass(cls):
- cls.tearDownProcess()
- pass
+ @classmethod
+ def tearDownClass(cls):
+ cls.tearDownProcess()
+ pass
- def testOutputUnicodeText_no_transliterate(self):
- self.sendstdin(u"""python -c "import os, pywikibot;
os.system('cls'); pywikibot.output(u'\\n'.join(pywikibot.handleArgs()))" Alpha
Bετα Гамма دلتا\n""")
- while(True):
- lines = self.getstdouterr().split("\n")
- if len(lines) >= 4 and lines[0] == "Alpha":
- break
- time.sleep(1)
+ def testOutputUnicodeText_no_transliterate(self):
+ self.sendstdin(u"""python -c "import os, pywikibot; os.system('cls');
pywikibot.output(u'\\n'.join(pywikibot.handleArgs()))" Alpha Bετα Гамма
دلتا\n""")
+ while(True):
+ lines = self.getstdouterr().split("\n")
+ if len(lines) >= 4 and lines[0] == "Alpha":
+ break
+ time.sleep(1)
- # empty line is the new command line
- self.assertEqual(lines, [u"Alpha", u"Bετα", u"Гамма", u"دلتا",
u""])
+ # empty line is the new command line
+ self.assertEqual(lines, [u"Alpha", u"Bετα", u"Гамма", u"دلتا", u""])
if __name__ == "__main__":
--
To view, visit https://gerrit.wikimedia.org/r/186646
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2ab67f422a1d9df1da1ae0523f3f163577c416c1
Gerrit-PatchSet: 10
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits