Skip to content

Commit

Permalink
Merge pull request #312 from exacaster/teat_empty_statements
Browse files Browse the repository at this point in the history
Do not error on empty statements, return empty instead
  • Loading branch information
pdambrauskas authored Jan 14, 2023
2 parents d08b24d + ae7ad20 commit b7ae02e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server/src/main/resources/shell_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ def _exec_then_eval(self, code):

def exec(self, request):
try:
code = request["code"]
self._exec_then_eval(code.rstrip())
code = request["code"].rstrip()
if code:
self._exec_then_eval(code)
return {"content": {"text/plain": str(sys.stdout.getvalue()).rstrip()}}

return {"content": {"text/plain": str(sys.stdout.getvalue()).rstrip()}}
return {"content": {"text/plain": ""}}
except Exception as e:
log.exception(e)
return self._error_response(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,18 @@ class PythonProcessorTest extends Specification {
result.message == "name 'x' is not defined"
result.traceback.size() > 0
}

def "returns nothing for empty statement"() {
when:
def result = processor.process("")
then:
result.content[TEXT_PLAIN] == ""
}

def "returns nothing for new line statement"() {
when:
def result = processor.process("\n")
then:
result.content[TEXT_PLAIN] == ""
}
}

0 comments on commit b7ae02e

Please sign in to comment.