A Popen that passes flags that allow triggering KeyboardInterrupt.
| 23 | |
| 24 | |
| 25 | class _WaitForStringPopen(subprocess.Popen): |
| 26 | """ |
| 27 | A Popen that passes flags that allow triggering KeyboardInterrupt. |
| 28 | """ |
| 29 | |
| 30 | def __init__(self, *args, **kwargs): |
| 31 | if sys.platform == 'win32': |
| 32 | kwargs['creationflags'] = subprocess.CREATE_NEW_CONSOLE |
| 33 | super().__init__( |
| 34 | *args, **kwargs, |
| 35 | # Force Agg so that each test can switch to its desired backend. |
| 36 | env={**os.environ, "MPLBACKEND": "Agg", "SOURCE_DATE_EPOCH": "0"}, |
| 37 | stdout=subprocess.PIPE, universal_newlines=True) |
| 38 | |
| 39 | def wait_for(self, terminator): |
| 40 | """Read until the terminator is reached.""" |
| 41 | buf = '' |
| 42 | while True: |
| 43 | c = self.stdout.read(1) |
| 44 | if not c: |
| 45 | raise RuntimeError( |
| 46 | f'Subprocess died before emitting expected {terminator!r}') |
| 47 | buf += c |
| 48 | if buf.endswith(terminator): |
| 49 | return buf |
| 50 | |
| 51 | |
| 52 | # Minimal smoke-testing of the backends for which the dependencies are |
no outgoing calls
searching dependent graphs…