def test_execute_code_producing_std_error(self): runner = CodeRunner() err, out = runner.run(code_std_error) self.assertEqual(out, "i am gonna give error\n") self.assertEqual(err, 'Error! Come on!')
def test_execute_code_with_name_error(self): runner = CodeRunner() err, out = runner.run(code_name_error) self.assertEqual(out, "") self.assertEqual(err, """Traceback (most recent call last):\r File "main.py", line 3, in <module>\r grrr\r NameError: name \'grrr\' is not defined\r """)
def test_execute_code_with_compile_error(self): runner = CodeRunner() err, out = runner.run(code_compile_error) self.assertEqual(out, "") self.assertEqual(err, """ File "main.py", line 2\r b=5\r ^\r IndentationError: unexpected indent\r """)
def run_code(): if not 'code' in request.json: return jsonify({'error': 'Invalid code run call'}), 201 code = request.json['code'] print "code=", code try: err, out = CodeRunner().run(code) #CodeExecuter().execute(code) return jsonify({'result': True, 'error': err, 'output': out}), 201 except Exception, ex: import traceback print traceback.format_exc() return jsonify({'result': False, 'error': ex}), 201
def setUp(self): self.code_runner = CodeRunner('odanado/os-command-injection')
def test_execute_infinite_loop(self): runner = CodeRunner() err, out = runner.run(code_infinite_loop) self.assertEqual(out ,"") self.assertEqual(err, "timeout")
def test_execute_valid_code(self): runner = CodeRunner() err, out = runner.run(code_valid_output) self.assertEqual(err, '') self.assertEqual(out, "This is my output. 6\n")