Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 4 | import subprocess |
| 5 | |
| 6 | class OETestCalledProcessError(subprocess.CalledProcessError): |
| 7 | def __str__(self): |
| 8 | def strify(o): |
| 9 | if isinstance(o, bytes): |
| 10 | return o.decode("utf-8", errors="replace") |
| 11 | else: |
| 12 | return o |
| 13 | |
| 14 | s = "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode) |
| 15 | if hasattr(self, "output") and self.output: |
| 16 | s = s + "\nStandard Output: " + strify(self.output) |
| 17 | if hasattr(self, "stderr") and self.stderr: |
| 18 | s = s + "\nStandard Error: " + strify(self.stderr) |
| 19 | return s |
| 20 | |
| 21 | def errors_have_output(): |
| 22 | subprocess.CalledProcessError = OETestCalledProcessError |