diff options
author | 2019-06-15 18:32:32 -0700 | |
---|---|---|
committer | 2019-06-15 18:47:00 -0700 | |
commit | bc130a4d44f38824b6173c0babff4eefe18ac1db (patch) | |
tree | 2fc7883f0c4ef98b752bdd6557a81c194f93a92c | |
parent | Merge pull request #24 from python-discord/refactor/nsjail (diff) |
Merge stdout and stderr
Removes the need for redirecting stderr using contextlib in the input.
Furthermore, it captures errors which don't directly come from the
input, such as SyntaxErrors.
-rw-r--r-- | snekbox/api/resources/eval.py | 2 | ||||
-rw-r--r-- | snekbox/nsjail.py | 10 | ||||
-rw-r--r-- | tests/api/test_eval.py | 1 |
3 files changed, 8 insertions, 5 deletions
diff --git a/snekbox/api/resources/eval.py b/snekbox/api/resources/eval.py index 4779557..c4bd666 100644 --- a/snekbox/api/resources/eval.py +++ b/snekbox/api/resources/eval.py @@ -57,7 +57,6 @@ class EvalResource: >>> { ... "stdout": "2\\n", - ... "stderr": "", ... "returncode": 0 ... } @@ -80,6 +79,5 @@ class EvalResource: resp.media = { "stdout": result.stdout, - "stderr": result.stderr, "returncode": result.returncode } diff --git a/snekbox/nsjail.py b/snekbox/nsjail.py index ff12ec4..1675b3e 100644 --- a/snekbox/nsjail.py +++ b/snekbox/nsjail.py @@ -131,9 +131,15 @@ class NsJail: log.info(msg) try: - result = subprocess.run(args, capture_output=True, env=ENV, text=True) + result = subprocess.run( + args, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + env=ENV, + text=True + ) except ValueError: - return subprocess.CompletedProcess(args, None, "", "ValueError: embedded null byte") + return subprocess.CompletedProcess(args, None, "ValueError: embedded null byte", "") self._parse_log(nsj_log) diff --git a/tests/api/test_eval.py b/tests/api/test_eval.py index 03f0e39..3350763 100644 --- a/tests/api/test_eval.py +++ b/tests/api/test_eval.py @@ -10,7 +10,6 @@ class TestEvalResource(SnekAPITestCase): self.assertEqual(result.status_code, 200) self.assertEqual("output", result.json["stdout"]) - self.assertEqual("error", result.json["stderr"]) self.assertEqual(0, result.json["returncode"]) def test_post_invalid_schema_400(self): |