From 10e06ce30ba8817cc130fc22730c65c57fe5e45b Mon Sep 17 00:00:00 2001 From: Irtaza Akram Date: Mon, 2 Mar 2026 12:06:13 +0500 Subject: [PATCH] fix: quality & doc tests --- xblocks_contrib/problem/capa/apps.py | 5 +- xblocks_contrib/problem/capa/capa_problem.py | 48 ++- xblocks_contrib/problem/capa/checker.py | 7 +- xblocks_contrib/problem/capa/customrender.py | 12 +- xblocks_contrib/problem/capa/inputtypes.py | 286 ++++++++++-------- xblocks_contrib/problem/capa/responsetypes.py | 192 ++++++------ .../problem/capa/safe_exec/lazymod.py | 2 +- .../problem/capa/safe_exec/remote_exec.py | 5 +- .../problem/capa/safe_exec/safe_exec.py | 11 +- .../capa/safe_exec/tests/test_lazymod.py | 2 +- .../capa/safe_exec/tests/test_safe_exec.py | 10 +- xblocks_contrib/problem/capa/tests/helpers.py | 2 +- .../capa/tests/response_xml_factory.py | 36 +-- .../problem/capa/tests/test_inputtypes.py | 18 +- .../problem/capa/tests/test_responsetypes.py | 15 +- .../problem/capa/tests/test_shuffle.py | 2 +- xblocks_contrib/problem/capa/util.py | 3 +- .../problem/capa/xqueue_interface.py | 12 +- xblocks_contrib/problem/capa_block.py | 58 ++-- xblocks_contrib/problem/stringify.py | 3 + .../problem/tests/test_capa_block.py | 20 +- 21 files changed, 411 insertions(+), 338 deletions(-) diff --git a/xblocks_contrib/problem/capa/apps.py b/xblocks_contrib/problem/capa/apps.py index 11a253d6..e3373de2 100644 --- a/xblocks_contrib/problem/capa/apps.py +++ b/xblocks_contrib/problem/capa/apps.py @@ -10,7 +10,7 @@ class CapaAppConfig(AppConfig): Configuration for the CAPA problem XBlock Django application. Why are we registering this as a Django App? - ------------------------------------------- + -------------------------------------------- By default, Django's template engine (specifically the `app_directories` loader) only discovers `templates/` folders that belong to an app listed in `INSTALLED_APPS`. @@ -28,10 +28,13 @@ class CapaAppConfig(AppConfig): without manual intervention. References: + - Open edX Plugin App Framework: https://docs.openedx.org/projects/edx-django-utils/en/latest/plugins/how_tos/how_to_create_a_plugin_app.html + - Django App Directories Loader: https://docs.djangoproject.com/en/stable/ref/templates/api/#django.template.loaders.app_directories.Loader + """ name = "xblocks_contrib.problem.capa" diff --git a/xblocks_contrib/problem/capa/capa_problem.py b/xblocks_contrib/problem/capa/capa_problem.py index 7f7c1216..1329a747 100644 --- a/xblocks_contrib/problem/capa/capa_problem.py +++ b/xblocks_contrib/problem/capa/capa_problem.py @@ -81,7 +81,7 @@ # main class for this module -class LoncapaSystem: # pylint: disable=too-few-public-methods,too-many-instance-attributes +class LoncapaSystem: """ An encapsulation of resources needed from the outside. @@ -127,7 +127,7 @@ def __init__( # pylint: disable=too-many-positional-arguments,too-many-argument self.matlab_api_key = matlab_api_key -class LoncapaProblem: # pylint: disable=too-many-public-methods,too-many-instance-attributes +class LoncapaProblem: """ Main class for capa Problems. """ @@ -239,7 +239,7 @@ def __init__( # pylint: disable=too-many-positional-arguments,too-many-argument # Run response late_transforms last (see MultipleChoiceResponse) # Sort the responses to be in *_1 *_2 ... order. responses = list(self.responders.values()) - responses = sorted(responses, key=lambda resp: int(resp.id[resp.id.rindex("_") + 1 :])) + responses = sorted(responses, key=lambda resp: int(resp.id[resp.id.rindex("_") + 1:])) for response in responses: if hasattr(response, "late_transforms"): response.late_transforms(self) @@ -251,21 +251,35 @@ def make_xml_compatible(self, tree): """ Adjust tree xml in-place for compatibility before creating a problem from it. + The idea here is to provide a central point for XML translation, for example, supporting an old XML format. At present, there just two translations. 1. compatibility translation: - old: ANSWER - convert to - new: OPTIONAL-HINT + + old:: + + ANSWER + + convert to + + new:: + + OPTIONAL-HINT 2. compatibility translation: - optioninput works like this internally: - - With extended hints there is a new - This translation takes in the new format and synthesizes the old option= attribute - so all downstream logic works unchanged with the new