1 # Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
3 from unittest
import TestCase
, main
, skipUnless
6 from unittest
.mock
import Mock
, patch
8 from mock
import Mock
, patch
10 from ..winterm
import WinColor
, WinStyle
, WinTerm
13 class WinTermTest(TestCase
):
15 @patch('colorama.winterm.win32')
16 def testInit(self
, mockWin32
):
18 mockAttr
.wAttributes
= 7 + 6 * 16 + 8
19 mockWin32
.GetConsoleScreenBufferInfo
.return_value
= mockAttr
21 self
.assertEqual(term
._fore
, 7)
22 self
.assertEqual(term
._back
, 6)
23 self
.assertEqual(term
._style
, 8)
25 @skipUnless(sys
.platform
.startswith("win"), "requires Windows")
26 def testGetAttrs(self
):
32 self
.assertEqual(term
.get_attrs(), 0)
34 term
._fore
= WinColor
.YELLOW
35 self
.assertEqual(term
.get_attrs(), WinColor
.YELLOW
)
37 term
._back
= WinColor
.MAGENTA
40 WinColor
.YELLOW
+ WinColor
.MAGENTA
* 16)
42 term
._style
= WinStyle
.BRIGHT
45 WinColor
.YELLOW
+ WinColor
.MAGENTA
* 16 + WinStyle
.BRIGHT
)
47 @patch('colorama.winterm.win32')
48 def testResetAll(self
, mockWin32
):
50 mockAttr
.wAttributes
= 1 + 2 * 16 + 8
51 mockWin32
.GetConsoleScreenBufferInfo
.return_value
= mockAttr
54 term
.set_console
= Mock()
61 self
.assertEqual(term
._fore
, 1)
62 self
.assertEqual(term
._back
, 2)
63 self
.assertEqual(term
._style
, 8)
64 self
.assertEqual(term
.set_console
.called
, True)
66 @skipUnless(sys
.platform
.startswith("win"), "requires Windows")
69 term
.set_console
= Mock()
74 self
.assertEqual(term
._fore
, 5)
75 self
.assertEqual(term
.set_console
.called
, True)
77 @skipUnless(sys
.platform
.startswith("win"), "requires Windows")
80 term
.set_console
= Mock()
85 self
.assertEqual(term
._back
, 5)
86 self
.assertEqual(term
.set_console
.called
, True)
88 @skipUnless(sys
.platform
.startswith("win"), "requires Windows")
91 term
.set_console
= Mock()
96 self
.assertEqual(term
._style
, 22)
97 self
.assertEqual(term
.set_console
.called
, True)
99 @patch('colorama.winterm.win32')
100 def testSetConsole(self
, mockWin32
):
102 mockAttr
.wAttributes
= 0
103 mockWin32
.GetConsoleScreenBufferInfo
.return_value
= mockAttr
110 mockWin32
.SetConsoleTextAttribute
.call_args
,
111 ((mockWin32
.STDOUT
, term
.get_attrs()), {})
114 @patch('colorama.winterm.win32')
115 def testSetConsoleOnStderr(self
, mockWin32
):
117 mockAttr
.wAttributes
= 0
118 mockWin32
.GetConsoleScreenBufferInfo
.return_value
= mockAttr
122 term
.set_console(on_stderr
=True)
125 mockWin32
.SetConsoleTextAttribute
.call_args
,
126 ((mockWin32
.STDERR
, term
.get_attrs()), {})
130 if __name__
== '__main__':