3from unittest
import TestCase, main, skipUnless
8 from mock
import patch, Mock
10from ..ansitowin32
import StreamWrapper
11from ..initialise
import init, just_fix_windows_console, _wipe_internal_state_for_tests
12from .utils
import osname, replace_by
20 @skipUnless(sys.stdout.isatty(),
"sys.stdout is not a tty")
26 _wipe_internal_state_for_tests()
31 self.assertIsNot(
sys.stdout, orig_stdout,
'stdout should be wrapped')
32 self.assertIsNot(
sys.stderr, orig_stderr,
'stderr should be wrapped')
39 self.assertIs(
sys.stdout, orig_stdout,
'stdout should not be wrapped')
40 self.assertIs(
sys.stderr, orig_stderr,
'stderr should not be wrapped')
42 @patch('colorama.initialise.reset_all')
43 @patch('colorama.ansitowin32.winapi_test', lambda *_: True)
44 @patch('colorama.ansitowin32.enable_vt_processing', lambda *_: False)
50 @patch('colorama.initialise.reset_all')
51 @patch('colorama.ansitowin32.winapi_test', lambda *_: False)
63 with replace_by(
None):
81 self.assertRaises(ValueError,
lambda: init(autoreset=
True, wrap=
False))
83 @patch('colorama.win32.SetConsoleTextAttribute')
84 @patch('colorama.initialise.AnsiToWin32')
92 @patch('colorama.initialise.AnsiToWin32')
110 @patch('colorama.initialise.atexit.register')
121 _wipe_internal_state_for_tests()
128 @patch("colorama.ansitowin32.winapi_test", lambda: True)
132 just_fix_windows_console()
151 for native_ansi
in [
False,
True]:
153 'colorama.ansitowin32.enable_vt_processing',
154 lambda *_: native_ansi
162 just_fix_windows_console()
172 just_fix_windows_console()
183 just_fix_windows_console()
188if __name__ ==
'__main__':
testAutoResetChangeable(self, mockATW32)
testInitWrapOffDoesntWrapOnWindows(self)
testAtexitRegisteredOnlyOnce(self, mockRegister)
testInitWrapOffIncompatibleWithAutoresetOn(self)
testInitAutoresetOnWrapsOnAllPlatforms(self)
testInitDoesntWrapOnEmulatedWindows(self, _)
testInitWrapsOnWindows(self, _)
testInitDoesntWrapIfNone(self)
testAutoResetPassedOn(self, mockATW32, _)
testInitDoesntWrapOnNonWindows(self)
testJustFixWindowsConsole(self)