Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI Build & Test: Show doctest failures, warnings as annotations in the 'Files changed' tab #36938

Merged
merged 23 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
48cde67
src/sage/doctest/forker.py: Show '# [failed in baseline]' earlier
mkoeppe Dec 20, 2023
d52858c
Refactor through new function DocTestController.source_baseline
mkoeppe Dec 20, 2023
8aca1ad
sage -t: Add option '--format github'
mkoeppe Dec 21, 2023
72ac0ec
.github/workflows/build.yml: Use sage -t --format github
mkoeppe Dec 21, 2023
7a121e6
src/sage/doctest/control.py: Fix doctest
mkoeppe Dec 21, 2023
0bd0077
src/sage/doctest/control.py: Log 'Using --baseline-stats-path=...'
mkoeppe Dec 21, 2023
8c8f2dc
Merge branch 'doctester-baselinestats-improvement' into doctester-git…
mkoeppe Dec 21, 2023
24779a9
src/sage/doctest/forker.py: Rewrite without 'match'
mkoeppe Dec 21, 2023
5fc07c7
src/bin/sage-runtests: Generalize argparse hack
mkoeppe Dec 21, 2023
c05bdba
DocTestReporter.report_head: Move all printing of 'failed in baseline…
mkoeppe Dec 21, 2023
5d5f6c1
Merge branch 'doctester-baselinestats-improvement' into doctester-git…
mkoeppe Dec 21, 2023
4b0f525
.github/workflows/build.yml: Fix up path to coverage files
mkoeppe Dec 23, 2023
0bfd2c9
src/sage/doctest/reporting.py: Make 'AlarmInterrupt in doctesting fra…
mkoeppe Dec 23, 2023
f2d8abf
Merge branch 'doctester-baselinestats-improvement' into doctester-git…
mkoeppe Dec 23, 2023
ce3b849
.github/workflows/build.yml: Do not create GitHub Annotations for the…
mkoeppe Dec 28, 2023
b83dcf3
src/sage/doctest/forker.py: Use urllib.parse.quote for github annotat…
mkoeppe Dec 29, 2023
96e0431
src/sage/doctest/forker.py: Don't use urllib.parse.quote, only quote …
mkoeppe Dec 29, 2023
1d69f07
.github/workflows/build.yml: Fix "Couldn't combine from non-existent …
mkoeppe Dec 29, 2023
2cfcbe3
Merge remote-tracking branch 'upstream/develop' into doctester-github…
mkoeppe Jan 4, 2024
173bc41
.github/workflows/build.yml: Pass --rcfile to coverage
mkoeppe Jan 5, 2024
4ecf7ca
src/tox.ini (coverage:report): Ignore errors, ignore empty
mkoeppe Jan 5, 2024
6aa76c0
Merge remote-tracking branch 'upstream/develop' into doctester-github…
mkoeppe Jan 14, 2024
0c52169
.github/workflows/build.yml: Revert change to the conditional 'Pytest…
mkoeppe Jan 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ jobs:
- name: Test all files (sage -t --all --long)
if: (success() || failure()) && steps.build.outcome == 'success'
run: |
../sage -python -m pip install coverage
../sage -python -m coverage run ./bin/sage-runtests --all --long -p2 --random-seed=286735480429121101562228604801325644303
working-directory: ./worktree-image/src
./sage -python -m pip install coverage
./sage -python -m coverage run --rcfile=src/tox.ini src/bin/sage-runtests --all --long -p2 --format github --random-seed=286735480429121101562228604801325644303
working-directory: ./worktree-image
mkoeppe marked this conversation as resolved.
Show resolved Hide resolved

- name: Prepare coverage results
if: (success() || failure()) && steps.build.outcome == 'success'
run: |
./venv/bin/python3 -m coverage combine src/.coverage/
./venv/bin/python3 -m coverage xml
./sage -python -m coverage combine --rcfile=src/tox.ini
./sage -python -m coverage xml --rcfile=src/tox.ini
mkdir -p coverage-report
mv coverage.xml coverage-report/
working-directory: ./worktree-image
Expand Down
2 changes: 2 additions & 0 deletions src/bin/sage-runtests
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ if __name__ == "__main__":
what.add_argument("--installed", action="store_true", default=False, help="test all installed modules of the Sage library")
parser.add_argument("--logfile", type=argparse.FileType('a'), metavar="FILE", help="log all output to FILE")

parser.add_argument("--format", choices=["sage", "github"], default="sage",
help="set format of error messages and warnings")
parser.add_argument("-l", "--long", action="store_true", default=False, help="include lines with the phrase 'long time'")
parser.add_argument("-s", "--short", dest="target_walltime", nargs='?',
type=int, default=-1, const=300, metavar="SECONDS",
Expand Down
1 change: 1 addition & 0 deletions src/sage/doctest/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def __init__(self, **kwds):
self.show_skipped = False
self.target_walltime = -1
self.baseline_stats_path = None
self.format = "sage"

# sage-runtests contains more optional tags. Technically, adding
# auto_optional_tags here is redundant, since that is added
Expand Down
60 changes: 52 additions & 8 deletions src/sage/doctest/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,16 +1235,57 @@
"""
out = [self.DIVIDER]
with OriginalSource(example):
if test.filename:
if test.lineno is not None and example.lineno is not None:
lineno = test.lineno + example.lineno + 1
if self.options.format == 'sage':
if test.filename:
if test.lineno is not None and example.lineno is not None:
lineno = test.lineno + example.lineno + 1
else:
lineno = '?'

Check warning on line 1243 in src/sage/doctest/forker.py

View check run for this annotation

Codecov / codecov/patch

src/sage/doctest/forker.py#L1243

Added line #L1243 was not covered by tests
out.append('File "%s", line %s, in %s' %
(test.filename, lineno, test.name))
else:
out.append('Line %s, in %s' % (example.lineno + 1, test.name))

Check warning on line 1247 in src/sage/doctest/forker.py

View check run for this annotation

Codecov / codecov/patch

src/sage/doctest/forker.py#L1247

Added line #L1247 was not covered by tests
out.append(message)
elif self.options.format == 'github':
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#using-workflow-commands-to-access-toolkit-functions
if message.startswith('Warning: '):
command = f'::warning title={message}'
message = message[len('Warning: '):]
elif self.baseline.get('failed', False):
command = f'::notice title={message}'
message += ' [failed in baseline]'

Check warning on line 1256 in src/sage/doctest/forker.py

View check run for this annotation

Codecov / codecov/patch

src/sage/doctest/forker.py#L1255-L1256

Added lines #L1255 - L1256 were not covered by tests
else:
lineno = '?'
out.append('File "%s", line %s, in %s' %
(test.filename, lineno, test.name))
command = f'::error title={message}'
if extra := getattr(example, 'extra', None):
message += f': {extra}'
if test.filename:
command += f',file={test.filename}'
if test.lineno is not None and example.lineno is not None:
lineno = test.lineno + example.lineno + 1
command += f',line={lineno}'
lineno = None
else:
command += f',line={example.lineno + 1}'

Check warning on line 1268 in src/sage/doctest/forker.py

View check run for this annotation

Codecov / codecov/patch

src/sage/doctest/forker.py#L1268

Added line #L1268 was not covered by tests
#
# Urlencoding trick for multi-line annotations
# https://github.com/actions/starter-workflows/issues/68#issuecomment-581479448
#
# This only affects the display in the workflow Summary, after clicking "Show more";
# the message needs to be long enough so that "Show more" becomes available.
# https://github.com/actions/toolkit/issues/193#issuecomment-1867084340
#
# Unfortunately, this trick does not make the annotations in the diff view multi-line.
#
if '\n' in message:
message = message.replace('\n', '%0A')
# The actual threshold for "Show more" to appear depends on the window size.
show_more_threshold = 500
if (pad := show_more_threshold - len(message)) > 0:
message += ' ' * pad

Check warning on line 1284 in src/sage/doctest/forker.py

View check run for this annotation

Codecov / codecov/patch

src/sage/doctest/forker.py#L1284

Added line #L1284 was not covered by tests
command += f'::{message}'
out.append(command)
else:
out.append('Line %s, in %s' % (example.lineno + 1, test.name))
out.append(message)
raise ValueError(f'unknown format option: {self.options.format}')

Check warning on line 1288 in src/sage/doctest/forker.py

View check run for this annotation

Codecov / codecov/patch

src/sage/doctest/forker.py#L1288

Added line #L1288 was not covered by tests
source = example.source
out.append(doctest._indent(source))
return '\n'.join(out)
Expand Down Expand Up @@ -1417,6 +1458,7 @@
"""
if not self.options.initial or self.no_failure_yet:
self.no_failure_yet = False
example.extra = f'Got: {got}'
returnval = doctest.DocTestRunner.report_failure(self, out, test, example, got)
if self.options.debug:
self._fakeout.stop_spoofing()
Expand Down Expand Up @@ -1567,6 +1609,8 @@
"""
if not self.options.initial or self.no_failure_yet:
self.no_failure_yet = False

example.extra = "Exception raised:\n" + "".join(traceback.format_exception(*exc_info))

Check warning on line 1613 in src/sage/doctest/forker.py

View check run for this annotation

Codecov / codecov/patch

src/sage/doctest/forker.py#L1612-L1613

Added lines #L1612 - L1613 were not covered by tests
returnval = doctest.DocTestRunner.report_unexpected_exception(self, out, test, example, exc_info)
if self.options.debug:
self._fakeout.stop_spoofing()
Expand Down
4 changes: 4 additions & 0 deletions src/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,7 @@ source = sage
concurrency = multiprocessing
data_file = .coverage/.coverage
disable_warnings = no-data-collected

[coverage:report]
ignore_errors = True
skip_empty = True
Loading