jenkins-bot has submitted this change and it was merged.
Change subject: Detect patched win32 stream handle ......................................................................
Detect patched win32 stream handle
Change-Id: I62b6ca19d95d018c8b31b9dcb8add5c44ec3407a --- M pywikibot/userinterfaces/win32_unicode.py M tests/ui_tests.py 2 files changed, 13 insertions(+), 3 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/pywikibot/userinterfaces/win32_unicode.py b/pywikibot/userinterfaces/win32_unicode.py index 5f7da5f..ebb83a0 100755 --- a/pywikibot/userinterfaces/win32_unicode.py +++ b/pywikibot/userinterfaces/win32_unicode.py @@ -232,14 +232,14 @@ stdin = UnicodeInput(hStdin, name='<Unicode console stdin>')
if real_stdout: - stdout = UnicodeOutput(hStdout, None, STDOUT_FILENO, + stdout = UnicodeOutput(hStdout, sys.stdout, STDOUT_FILENO, '<Unicode console stdout>') else: stdout = UnicodeOutput(None, sys.stdout, old_stdout_fileno, '<Unicode redirected stdout>')
if real_stderr: - stderr = UnicodeOutput(hStderr, None, STDERR_FILENO, + stderr = UnicodeOutput(hStderr, sys.stderr, STDERR_FILENO, '<Unicode console stderr>') else: stderr = UnicodeOutput(None, sys.stderr, old_stderr_fileno, diff --git a/tests/ui_tests.py b/tests/ui_tests.py index 73a86e4..d44d19c 100644 --- a/tests/ui_tests.py +++ b/tests/ui_tests.py @@ -68,6 +68,10 @@ self._original = getattr(sys, self._name) patched_streams[self._original] = self._stream
+ def __repr__(self): + return '<patched %s %r wrapping %r>' % ( + self._name, self._stream, self._original) + def reset(self): """Reset own stream.""" self._stream.truncate(0) @@ -130,7 +134,13 @@
def patched_print(text, targetStream): - org_print(text, patched_streams[targetStream]) + try: + stream = patched_streams[targetStream] + except KeyError: + assert(isinstance(targetStream, pywikibot.userinterfaces.win32_unicode.UnicodeOutput)) + assert(targetStream._stream) + stream = patched_streams[targetStream._stream] + org_print(text, stream)
def patched_input():
pywikibot-commits@lists.wikimedia.org