Util to mock sys.stdout and sys.stderr, and store their output in a 's' var.
| 127 | |
| 128 | |
| 129 | class StringWriter(StringIO): |
| 130 | """Util to mock sys.stdout and sys.stderr, and |
| 131 | store their output in a 's' var.""" |
| 132 | def __init__(self, debug=None): |
| 133 | # type: (Optional[TextIO]) -> None |
| 134 | self.s = "" |
| 135 | self.debug = debug |
| 136 | super().__init__() |
| 137 | |
| 138 | def write(self, x): |
| 139 | # type: (str) -> int |
| 140 | # Object can be in the middle of being destroyed. |
| 141 | if getattr(self, "debug", None) and self.debug: |
| 142 | self.debug.write(x) |
| 143 | if getattr(self, "s", None) is not None: |
| 144 | self.s += x |
| 145 | return len(x) |
| 146 | |
| 147 | def flush(self): |
| 148 | # type: () -> None |
| 149 | if getattr(self, "debug", None) and self.debug: |
| 150 | self.debug.flush() |
| 151 | |
| 152 | |
| 153 | def autorun_get_interactive_session(cmds, **kargs): |
no outgoing calls
no test coverage detected
searching dependent graphs…