def _marking_enabled(self, markers, stdout): auto = utils.isatty(stdout) return { 'AUTO': auto, 'ON': True, 'OFF': False }.get(markers.upper(), auto)
def test_with_detached_io_buffer(self): with io.StringIO() as stream: wrapper = io.TextIOWrapper(stream, 'UTF-8') wrapper.detach() exc_type = ValueError if PYTHON else AttributeError assert_raises(exc_type, wrapper.isatty) assert_false(isatty(wrapper))
def _get_highlighter(self, stream, colors): auto = Highlighter if utils.isatty(stream) else NoHighlighting highlighter = {'AUTO': auto, 'ON': Highlighter, 'FORCE': Highlighter, # compatibility with 2.5.5 and earlier 'OFF': NoHighlighting, 'ANSI': AnsiHighlighter}.get(colors.upper(), auto) return highlighter(stream)
def _marking_enabled(self, markers, highlighter): options = {'AUTO': isatty(highlighter.stream), 'ON': True, 'OFF': False} try: return options[markers.upper()] except KeyError: raise DataError("Invalid console marker value '%s'. Available " "'AUTO', 'ON' and 'OFF'." % markers)
def _get_highlighter(self, stream, colors): options = {'AUTO': Highlighter if isatty(stream) else NoHighlighting, 'ON': Highlighter, 'OFF': NoHighlighting, 'ANSI': AnsiHighlighter} try: highlighter = options[colors.upper()] except KeyError: raise DataError("Invalid console color value '%s'. Available " "'AUTO', 'ON', 'OFF' and 'ANSI'." % colors) return highlighter(stream)
def test_with_stdout_and_stderr(self): # file class based in PY2, io module based in PY3 assert_equals(isatty(sys.__stdout__), sys.__stdout__.isatty()) assert_equals(isatty(sys.__stderr__), sys.__stderr__.isatty())
def test_with_io(self): with io.StringIO() as stream: assert_false(isatty(stream)) wrapper = io.TextIOWrapper(stream, 'UTF-8') assert_false(isatty(wrapper))
def test_with_stdout_and_stderr(self): # file class based in PY2, io module based in PY3 assert_equal(isatty(sys.__stdout__), sys.__stdout__.isatty()) assert_equal(isatty(sys.__stderr__), sys.__stderr__.isatty())
def _marking_enabled(self, markers, stdout): auto = utils.isatty(stdout) return {'AUTO': auto, 'ON': True, 'OFF': False}.get(markers.upper(), auto)
def test_open_and_closed_file(self): with open(__file__) as file: assert_false(isatty(file)) assert_false(isatty(file))
def test_with_detached_io_buffer(self): with io.StringIO() as stream: wrapper = io.TextIOWrapper(stream, 'UTF-8') wrapper.detach() assert_raises((ValueError, AttributeError), wrapper.isatty) assert_false(isatty(wrapper))
def test_with_stdout_and_stderr(self): assert_equal(isatty(sys.__stdout__), sys.__stdout__.isatty()) assert_equal(isatty(sys.__stderr__), sys.__stderr__.isatty())
def _marking_enabled(self, markers, highlighter): auto = isatty(highlighter.stream) return {'AUTO': auto, 'ON': True, 'OFF': False}.get(markers.upper(), auto)