| 619 | return not bool(self.failed) |
| 620 | |
| 621 | def _get_differences(self, which, dispwhich=None): |
| 622 | ret = getattr(self, which) |
| 623 | exp = getattr(self.expected, which) |
| 624 | if dispwhich is None: |
| 625 | dispwhich = which |
| 626 | if isinstance(exp, bytes) or isinstance(ret, bytes): |
| 627 | return "Returned different binary data" |
| 628 | if ret and exp is None: |
| 629 | plr = "" if len(ret) == 1 else "s" |
| 630 | txt = f"Returned {len(ret)} line{plr} to {dispwhich} but none was expected" |
| 631 | elif not ret and exp: |
| 632 | plr = "" if len(exp) == 1 else "s" |
| 633 | txt = f"No {dispwhich} was returned but expected {len(exp)} line{plr}" |
| 634 | else: |
| 635 | diff = difflib.ndiff(exp, ret) |
| 636 | txt = f"Different {dispwhich} returned (+) than expected (-):\n" |
| 637 | txt += "".join(diff).rstrip() |
| 638 | return txt |
| 639 | |
| 640 | def describe_fail(self, file=sys.stderr): |
| 641 | """Describe (print) how test has failed.""" |