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

Merge updates for bugfix v5.2.3 to master #761

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- master
- beta
- release
- temp
workflow_dispatch:

jobs:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* Updated Otter Assign to throw a `ValueError` when invalid Python code is encountered in test cells per [#756](https://github.com/ucbds-infra/otter-grader/issues/756)
* Fixed an error causing intercell seeding code to be added to cells using cell magic commands which caused syntax errors per [#754](https://github.com/ucbds-infra/otter-grader/issues/754)

**v5.2.3:**

* Fixed the no PDF acknowledgement feature to handle when PDF exports throw an error instead of failing silently

**v5.2.2:**

* Fixed an `AttributeError` when using `Notebook.check_all` per [#746](https://github.com/ucbds-infra/otter-grader/issues/746)
Expand Down
11 changes: 7 additions & 4 deletions otter/check/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,11 @@
zf = zipfile.ZipFile(zip_path, mode="w")
zf.write(nb_path)

pdf_created = True
pdf_path, pdf_created, pdf_error = None, True, None
if pdf:
pdf_path = export_notebook(nb_path, filtering=filtering, pagebreaks=pagebreaks)
if os.path.isfile(pdf_path):
try: pdf_path = export_notebook(nb_path, filtering=filtering, pagebreaks=pagebreaks)
except Exception as e: pdf_error = e

Check warning on line 463 in otter/check/notebook.py

View check run for this annotation

Codecov / codecov/patch

otter/check/notebook.py#L463

Added line #L463 was not covered by tests
if pdf_path and os.path.isfile(pdf_path):
pdf_created = True
zf.write(pdf_path)
self._logger.debug(f"Wrote PDF to zip file: {pdf_path}")
Expand Down Expand Up @@ -520,10 +521,12 @@
display(HTML(out_html))

if pdf_created or not self._nbmeta_config.require_no_pdf_confirmation:
if pdf_error is not None:
raise pdf_error

Check warning on line 525 in otter/check/notebook.py

View check run for this annotation

Codecov / codecov/patch

otter/check/notebook.py#L525

Added line #L525 was not covered by tests
continue_export()
else:
display_pdf_confirmation_widget(
self._nbmeta_config.export_pdf_failure_message, continue_export)
self._nbmeta_config.export_pdf_failure_message, pdf_error, continue_export)

@grading_mode_disabled
@logs_event(EventType.END_CHECK_ALL)
Expand Down
10 changes: 7 additions & 3 deletions otter/check/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from ..nbmeta_config import NBMetadataConfig
from ..test_files import GradingResults
from ..utils import import_or_raise
from ..utils import format_exception, import_or_raise


T = TypeVar("T")
Expand Down Expand Up @@ -332,7 +332,7 @@
return test_path, test_name


def display_pdf_confirmation_widget(message: Optional[str], callback: Callable) -> None:
def display_pdf_confirmation_widget(message: Optional[str], pdf_error: Optional[Exception], callback: Callable) -> None:
"""
Display a widget to the user to acknowledge that a PDF will not be included in their submission
zip.
Expand All @@ -349,7 +349,11 @@
message = "Your notebook could not be exported as a PDF. To continue exporting your " \
"submission, please click the button below."

t = HTML(f"""<p style="margin: 0">{message}</p>""")
message_html = f"""<p style="margin: 0">{message}</p>"""
if pdf_error is not None:
message_html += f"""<pre>{format_exception(pdf_error)}</pre>"""

Check warning on line 354 in otter/check/utils.py

View check run for this annotation

Codecov / codecov/patch

otter/check/utils.py#L354

Added line #L354 was not covered by tests

t = HTML(message_html)
b = Button(description="Continue export", button_style="warning")
b.on_click(wrapped_callback)
m = HTML("""<div style="height: 10px; width: 100%"></div>""")
Expand Down
9 changes: 2 additions & 7 deletions otter/test_files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import nbformat as nbf
import os
import pickle
import traceback

from typing import Any, Dict, List, Optional

Expand All @@ -16,7 +15,7 @@
from .ottr_test import OttrTestFile

from ..nbmeta_config import NBMetadataConfig, OK_FORMAT_VARNAME
from ..utils import QuestionNotInLogException
from ..utils import format_exception, QuestionNotInLogException


__all__ = [
Expand Down Expand Up @@ -414,11 +413,7 @@ def to_gradescope_dict(self, ag_config):
"output": "The autograder failed to produce any results. Please alert your instructor to this failure for assistance in debugging it.",
"status": "failed",
})
tb = "".join(traceback.format_exception(
type(self._catastrophic_error),
self._catastrophic_error,
self._catastrophic_error.__traceback__,
))
tb = format_exception(self._catastrophic_error)
output["tests"].append({
"name": "Autograder Exception",
"visibility": "hidden",
Expand Down
14 changes: 14 additions & 0 deletions otter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import string
import shutil
import tempfile
import traceback
import yaml

from contextlib import contextmanager
Expand Down Expand Up @@ -398,3 +399,16 @@ class QuestionNotInLogException(Exception):
"""
Exception that indicates that a specific question was not found in any entry in the log
"""


def format_exception(e: Exception) -> str:
"""
Formats an exception for display with its traceback using the ``traceback`` module.

Args:
e (``Exception``): the exception to format

Returns:
``str``: the formatted exception
"""
return "".join(traceback.format_exception(type(e), e, e.__traceback__))
Loading