Skip to content

Commit

Permalink
DocTestReporter.report_head: Move all printing of 'failed in baseline…
Browse files Browse the repository at this point in the history
…' here
  • Loading branch information
Matthias Koeppe committed Dec 21, 2023
1 parent 5fc07c7 commit c05bdba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
4 changes: 0 additions & 4 deletions src/sage/doctest/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1725,8 +1725,6 @@ def serial_dispatch(self):
for source in self.controller.sources:
heading = self.controller.reporter.report_head(source)
baseline = self.controller.source_baseline(source)
if baseline.get('failed', False):
heading += " # [failed in baseline]"
if not self.controller.options.only_errors:
self.controller.log(heading)

Expand Down Expand Up @@ -1996,8 +1994,6 @@ def sel_exit():
worker_options.target_walltime = (target_endtime - now) / (max(1, pending_tests / opt.nthreads))
w = DocTestWorker(source, options=worker_options, funclist=[sel_exit], baseline=baseline)
heading = self.controller.reporter.report_head(w.source)
if baseline.get('failed', False):
heading += " # [failed in baseline]"
if not self.controller.options.only_errors:
w.messages = heading + "\n"
# Store length of heading to detect if the
Expand Down
37 changes: 21 additions & 16 deletions src/sage/doctest/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,16 @@ def were_doctests_with_optional_tag_run(self, tag):
return True
return False

def report_head(self, source):
def report_head(self, source, fail_msg=None):
"""
Return the "sage -t [options] file.py" line as string.
Return the ``sage -t [options] file.py`` line as string.
INPUT:
- ``source`` -- a source from :mod:`sage.doctest.sources`
- ``fail_msg`` -- ``None`` or a string
EXAMPLES::
sage: from sage.doctest.reporting import DocTestReporter
Expand All @@ -190,6 +192,8 @@ def report_head(self, source):
sage: DD.long = True
sage: print(DTR.report_head(FDS))
sage -t --long .../sage/doctest/reporting.py
sage: print(DTR.report_head(FDS, "Failed by self-sabotage"))
sage -t --long .../sage/doctest/reporting.py # Failed by self-sabotage
"""
cmd = "sage -t"
if self.controller.options.long:
Expand All @@ -206,6 +210,13 @@ def report_head(self, source):
if environment != "sage.repl.ipython_kernel.all_jupyter":
cmd += f" --environment={environment}"
cmd += " " + source.printpath
baseline = self.controller.source_baseline(source)
if fail_msg:
cmd += " # " + fail_msg
if baseline.get('failed', False):
if not fail_msg:
cmd += " #"
cmd += " [failed in baseline]"
return cmd

def report(self, source, timeout, return_code, results, output, pid=None):
Expand Down Expand Up @@ -420,12 +431,10 @@ def report(self, source, timeout, return_code, results, output, pid=None):
fail_msg += " (and interrupt failed)"
else:
fail_msg += " (with %s after interrupt)" % signal_name(sig)
if baseline.get('failed', False):
fail_msg += " [failed in baseline]"
log(" %s\n%s\nTests run before %s timed out:" % (fail_msg, "*"*70, process_name))
log(output)
log("*"*70)
postscript['lines'].append(cmd + " # %s" % fail_msg)
postscript['lines'].append(self.report_head(source, fail_msg))
stats[basename] = {"failed": True, "walltime": 1e6, "ntests": ntests}
if not baseline.get('failed', False):
self.error_status |= 4
Expand All @@ -436,12 +445,10 @@ def report(self, source, timeout, return_code, results, output, pid=None):
fail_msg = "Killed due to %s" % signal_name(-return_code)
if ntests > 0:
fail_msg += " after testing finished"
if baseline.get('failed', False):
fail_msg += " [failed in baseline]"
log(" %s\n%s\nTests run before %s failed:" % (fail_msg,"*"*70, process_name))
log(output)
log("*"*70)
postscript['lines'].append(cmd + " # %s" % fail_msg)
postscript['lines'].append(self.report_head(source, fail_msg))
stats[basename] = {"failed": True, "walltime": 1e6, "ntests": ntests}
if not baseline.get('failed', False):
self.error_status |= (8 if return_code > 0 else 16)
Expand All @@ -458,13 +465,13 @@ def report(self, source, timeout, return_code, results, output, pid=None):
log(" Error in doctesting framework (bad result returned)\n%s\nTests run before error:" % ("*"*70))
log(output)
log("*"*70)
postscript['lines'].append(cmd + " # Testing error: bad result")
postscript['lines'].append(self.report_head(source, "Testing error: bad result"))
self.error_status |= 64
elif result_dict.err == 'noresult':
log(" Error in doctesting framework (no result returned)\n%s\nTests run before error:" % ("*"*70))
log(output)
log("*"*70)
postscript['lines'].append(cmd + " # Testing error: no result")
postscript['lines'].append(self.report_head(source, "Testing error: no result"))
self.error_status |= 64
elif result_dict.err == 'tab':
if len(result_dict.tab_linenos) > 5:
Expand All @@ -473,11 +480,11 @@ def report(self, source, timeout, return_code, results, output, pid=None):
if len(result_dict.tab_linenos) > 1:
tabs = "s" + tabs
log(" Error: TAB character found at line%s" % (tabs))
postscript['lines'].append(cmd + " # Tab character found")
postscript['lines'].append(self.report_head(source, "Tab character found"))
self.error_status |= 32
elif result_dict.err == 'line_number':
log(" Error: Source line number found")
postscript['lines'].append(cmd + " # Source line number found")
postscript['lines'].append(self.report_head(source, "Source line number found"))
self.error_status |= 256
elif result_dict.err is not None:
# This case should not occur
Expand All @@ -494,7 +501,7 @@ def report(self, source, timeout, return_code, results, output, pid=None):
if output:
log("Tests run before doctest exception:\n" + output)
log("*"*70)
postscript['lines'].append(cmd + " # %s" % fail_msg)
postscript['lines'].append(self.report_head(source, fail_msg))
if hasattr(result_dict, 'tb'):
log(result_dict.tb)
if hasattr(result_dict, 'walltime'):
Expand All @@ -506,9 +513,7 @@ def report(self, source, timeout, return_code, results, output, pid=None):
f = result_dict.failures
if f:
fail_msg = "%s failed" % (count_noun(f, "doctest"))
if baseline.get('failed', False):
fail_msg += " [failed in baseline]"
postscript['lines'].append(cmd + " # %s" % fail_msg)
postscript['lines'].append(self.report_head(source, fail_msg))
if not baseline.get('failed', False):
self.error_status |= 1
if f or result_dict.err == 'tab':
Expand Down

0 comments on commit c05bdba

Please sign in to comment.