aboutsummaryrefslogtreecommitdiffstats
path: root/resources
diff options
context:
space:
mode:
authorGravatar Matteo Bertucci <[email protected]>2021-02-24 15:18:55 +0100
committerGravatar Matteo Bertucci <[email protected]>2021-02-24 15:18:55 +0100
commit80433234dba5c8504e79fc829d05f1ef68a82f9f (patch)
treee10cf6118d343513e747d90eec8f249306f30f21 /resources
parentDocument unittest code (diff)
Move most of the unittest template inside of the handler
Diffstat (limited to 'resources')
-rw-r--r--resources/unittest_template.py23
1 files changed, 11 insertions, 12 deletions
diff --git a/resources/unittest_template.py b/resources/unittest_template.py
index 4c9b0bb..7919b5c 100644
--- a/resources/unittest_template.py
+++ b/resources/unittest_template.py
@@ -18,17 +18,6 @@ class RunnerTestCase(unittest.TestCase):
### UNIT CODE
-# Fake file object not writing anything
-DEVNULL = SimpleNamespace(write=lambda *_: None, flush=lambda *_: None)
-
-RESULT = io.StringIO()
-ORIGINAL_STDOUT = sys.stdout
-
-# stdout/err is patched in order to control what is outputted by the runner
-sys.stdout = DEVNULL
-sys.stderr = DEVNULL
-
-
def _exit_sandbox(code: int) -> NoReturn:
"""
Exit the sandbox by printing the result to the actual stdout and exit with the provided code.
@@ -74,10 +63,20 @@ def _main() -> None:
try:
+ # Fake file object not writing anything
+ DEVNULL = SimpleNamespace(write=lambda *_: None, flush=lambda *_: None)
+
+ RESULT = io.StringIO()
+ ORIGINAL_STDOUT = sys.stdout
+
+ # stdout/err is patched in order to control what is outputted by the runner
+ sys.stdout = DEVNULL
+ sys.stderr = DEVNULL
+
# Load the user code as a global module variable
module = _load_user_module()
_main()
except Exception:
print("Uncaught exception:\n", file=RESULT)
traceback.print_exc(file=RESULT)
- _exit_sandbox(99)
+ _exit_sandbox(99) \ No newline at end of file