(self)
| 70 | curses.setupterm(fd=stdout_fd) |
| 71 | |
| 72 | def setUp(self): |
| 73 | self.isatty = True |
| 74 | self.output = sys.__stdout__ |
| 75 | stdout_fd = sys.__stdout__.fileno() |
| 76 | if not sys.__stdout__.isatty(): |
| 77 | # initstr() unconditionally uses C stdout. |
| 78 | # If it is redirected to file or pipe, try to attach it |
| 79 | # to terminal. |
| 80 | # First, save a copy of the file descriptor of stdout, so it |
| 81 | # can be restored after finishing the test. |
| 82 | dup_fd = os.dup(stdout_fd) |
| 83 | self.addCleanup(os.close, dup_fd) |
| 84 | self.addCleanup(os.dup2, dup_fd, stdout_fd) |
| 85 | |
| 86 | if sys.__stderr__.isatty(): |
| 87 | # If stderr is connected to terminal, use it. |
| 88 | tmp = sys.__stderr__ |
| 89 | self.output = sys.__stderr__ |
| 90 | else: |
| 91 | try: |
| 92 | # Try to open the terminal device. |
| 93 | tmp = open('/dev/tty', 'wb', buffering=0) |
| 94 | except OSError: |
| 95 | # As a fallback, use regular file to write control codes. |
| 96 | # Some functions (like savetty) will not work, but at |
| 97 | # least the garbage control sequences will not be mixed |
| 98 | # with the testing report. |
| 99 | tmp = tempfile.TemporaryFile(mode='wb', buffering=0) |
| 100 | self.isatty = False |
| 101 | self.addCleanup(tmp.close) |
| 102 | self.output = None |
| 103 | os.dup2(tmp.fileno(), stdout_fd) |
| 104 | |
| 105 | self.save_signals = SaveSignals() |
| 106 | self.save_signals.save() |
| 107 | self.addCleanup(self.save_signals.restore) |
| 108 | if verbose and self.output is not None: |
| 109 | # just to make the test output a little more readable |
| 110 | sys.stderr.flush() |
| 111 | sys.stdout.flush() |
| 112 | print(file=self.output, flush=True) |
| 113 | self.stdscr = curses.initscr() |
| 114 | if self.isatty: |
| 115 | curses.savetty() |
| 116 | self.addCleanup(curses.endwin) |
| 117 | self.addCleanup(curses.resetty) |
| 118 | self.stdscr.erase() |
| 119 | |
| 120 | @requires_curses_func('filter') |
| 121 | def test_filter(self): |
nothing calls this directly
no test coverage detected