1 # Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
3 from unittest import TestCase, main
5 from ..ansitowin32 import StreamWrapper, AnsiToWin32
6 from .utils import pycharm, replace_by, replace_original_by, StreamTTY, StreamNonTTY
10 return StreamWrapper(stream, None).isatty()
12 class IsattyTest(TestCase):
16 self.assertTrue(is_a_tty(tty))
18 self.assertTrue(is_a_tty(tty))
20 def test_nonTTY(self):
21 non_tty = StreamNonTTY()
22 self.assertFalse(is_a_tty(non_tty))
24 self.assertFalse(is_a_tty(non_tty))
26 def test_withPycharm(self):
28 self.assertTrue(is_a_tty(sys.stderr))
29 self.assertTrue(is_a_tty(sys.stdout))
31 def test_withPycharmTTYOverride(self):
33 with pycharm(), replace_by(tty):
34 self.assertTrue(is_a_tty(tty))
36 def test_withPycharmNonTTYOverride(self):
37 non_tty = StreamNonTTY()
38 with pycharm(), replace_by(non_tty):
39 self.assertFalse(is_a_tty(non_tty))
41 def test_withPycharmNoneOverride(self):
43 with replace_by(None), replace_original_by(None):
44 self.assertFalse(is_a_tty(None))
45 self.assertFalse(is_a_tty(StreamNonTTY()))
46 self.assertTrue(is_a_tty(StreamTTY()))
48 def test_withPycharmStreamWrapped(self):
50 self.assertTrue(AnsiToWin32(StreamTTY()).stream.isatty())
51 self.assertFalse(AnsiToWin32(StreamNonTTY()).stream.isatty())
52 self.assertTrue(AnsiToWin32(sys.stdout).stream.isatty())
53 self.assertTrue(AnsiToWin32(sys.stderr).stream.isatty())
56 if __name__ == '__main__':