diff options
author | 2022-06-24 05:06:35 +0400 | |
---|---|---|
committer | 2022-06-24 05:06:35 +0400 | |
commit | 28b6d4c8b8f7bc6c6230b42c2e2db376be559562 (patch) | |
tree | 5309cfa3e5c2f748fdb02e1ded508c2085fbf33e /backend/routes/forms/unittesting.py | |
parent | Merge pull request #173 from adriangb/asgi-middleware (diff) |
Allow Setup For Unittests
Adds the setup method as a special method for unittest question types.
Additionally, a couple QoL fixes are included. I changed `unit` to
`self` to clarify what it actually is, and I changed an `lstrip` to a
`removeprefix` to avoid removing unintentional portions of the name
(for instance `something` -> `omething`)
Signed-off-by: Hassan Abouelela <[email protected]>
Diffstat (limited to 'backend/routes/forms/unittesting.py')
-rw-r--r-- | backend/routes/forms/unittesting.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/backend/routes/forms/unittesting.py b/backend/routes/forms/unittesting.py index a830775..c093718 100644 --- a/backend/routes/forms/unittesting.py +++ b/backend/routes/forms/unittesting.py @@ -36,8 +36,10 @@ def _make_unit_code(units: dict[str, str]) -> str: result = "" for unit_name, unit_code in units.items(): + test_prefix = "test_" if unit_name != "setUp" else "" + result += ( - f"\ndef test_{unit_name.lstrip('#')}(unit):" # Function definition + f"\ndef {test_prefix}{unit_name.removeprefix('#')}(self):" # Function definition f"\n{indent(unit_code, ' ')}" # Unit code ) @@ -83,7 +85,7 @@ async def execute_unittest(form_response: FormResponse, form: Form) -> list[Unit # Tests starting with an hashtag should have censored names. hidden_test_counter = count(1) hidden_tests = { - test.lstrip("#").lstrip("test_"): next(hidden_test_counter) + test.removeprefix("#").removeprefix("test_"): next(hidden_test_counter) for test in question.data["unittests"]["tests"].keys() if test.startswith("#") } |