Ejemplo n.º 1
0
 def test_error_in_check_code(self):
     results = run_python("""a = 17""", """b = 1/0""")
     self.assertEqual("", results["stdout"])
     checks = results["checks"]
     self.assertEqual(len(checks), 1)
     self.assertEqual(checks[0]["status"], "ERROR")
     self.assertEqual("ZeroDivisionError", checks[0]["exception"]["type"])
     self.assertEqual("b = 1/0", checks[0]["exception"]["traceback"][-1]["text"])
Ejemplo n.º 2
0
 def test_error_in_check_code(self):
     results = run_python("""a = 17""", """b = 1/0""")
     self.assertEqual("", results['stdout'])
     checks = results['checks']
     self.assertEqual(len(checks), 1)
     self.assertEqual(checks[0]['status'], "ERROR")
     self.assertEqual("ZeroDivisionError", checks[0]['exception']['type'])
     self.assertEqual("b = 1/0",
                      checks[0]['exception']['traceback'][-1]['text'])
Ejemplo n.º 3
0
 def test_syntaxerror_in_check_code(self):
     results = run_python("""a = 17""", """1'hello'""")
     self.assertEqual("", results["stdout"])
     checks = results["checks"]
     self.assertEqual(len(checks), 1)
     self.assertEqual(checks[0]["status"], "ERROR")
     self.assertEqual("SyntaxError", checks[0]["exception"]["type"])
     self.assertEqual("invalid syntax", checks[0]["exception"]["args"][0])
     self.assertEqual((1, 8, "1'hello'\n"), checks[0]["exception"]["args"][1][1:])
Ejemplo n.º 4
0
 def test_indentation_error_in_user_code(self):
     results = run_python("""a = 1\n  b = 2""", "")
     self.assertEqual("", results["stdout"])
     checks = results["checks"]
     self.assertEqual(len(checks), 1)
     self.assertEqual(checks[0]["status"], "EXCEPTION")
     self.assertEqual("IndentationError", checks[0]["exception"]["type"])
     self.assertEqual("b = 2", checks[0]["exception"]["traceback"][-1]["text"])
     self.assertEqual(2, checks[0]["exception"]["traceback"][-1]["offset"])
Ejemplo n.º 5
0
 def test_syntax_error_in_user_code(self):
     results = run_python("""a = 1'hello'""", "")
     self.assertEqual("", results["stdout"])
     checks = results["checks"]
     self.assertEqual(len(checks), 1)
     self.assertEqual(checks[0]["status"], "EXCEPTION")
     self.assertEqual("SyntaxError", checks[0]["exception"]["type"])
     self.assertEqual("a = 1'hello'", checks[0]["exception"]["traceback"][-1]["text"])
     self.assertEqual(12, checks[0]["exception"]["traceback"][-1]["offset"])
Ejemplo n.º 6
0
 def test_syntaxerror_in_check_code(self):
     results = run_python("""a = 17""", """1'hello'""")
     self.assertEqual("", results['stdout'])
     checks = results['checks']
     self.assertEqual(len(checks), 1)
     self.assertEqual(checks[0]['status'], "ERROR")
     self.assertEqual("SyntaxError", checks[0]['exception']['type'])
     self.assertEqual('invalid syntax', checks[0]['exception']['args'][0])
     self.assertEqual((1, 8, "1'hello'\n"),
                      checks[0]['exception']['args'][1][1:])
Ejemplo n.º 7
0
 def test_indentation_error_in_user_code(self):
     results = run_python("""a = 1\n  b = 2""", "")
     self.assertEqual("", results['stdout'])
     checks = results['checks']
     self.assertEqual(len(checks), 1)
     self.assertEqual(checks[0]['status'], "EXCEPTION")
     self.assertEqual("IndentationError", checks[0]['exception']['type'])
     self.assertEqual("b = 2",
                      checks[0]['exception']['traceback'][-1]['text'])
     self.assertEqual(2, checks[0]['exception']['traceback'][-1]['offset'])
Ejemplo n.º 8
0
 def test_syntax_error_in_user_code(self):
     results = run_python("""a = 1'hello'""", "")
     self.assertEqual("", results['stdout'])
     checks = results['checks']
     self.assertEqual(len(checks), 1)
     self.assertEqual(checks[0]['status'], "EXCEPTION")
     self.assertEqual("SyntaxError", checks[0]['exception']['type'])
     self.assertEqual("a = 1'hello'",
                      checks[0]['exception']['traceback'][-1]['text'])
     self.assertEqual(12, checks[0]['exception']['traceback'][-1]['offset'])
Ejemplo n.º 9
0
def run(request, exid=None):
    the_code = request.POST.get('code')
    if exid:
        ex = get_object_or_404(Exercise, pk=exid)
        check_code = ex.check
    else:
        check_code = request.POST.get('check', '')
    if not check_code:
        return HttpResponse("No check code to run", status=400)
    results = run_python(the_code, check_code)
    results['status'] = 'ok'
    return HttpResponse(json.dumps(results), mimetype="application/json")
Ejemplo n.º 10
0
 def test_output(self):
     results = run_python("""print 'hello!'""", "")
     self.assertEqual(results['stdout'], "hello!\n")
Ejemplo n.º 11
0
 def run_python_dedented(self, a, b):
     return run_python(textwrap.dedent(a), textwrap.dedent(b))
Ejemplo n.º 12
0
 def test_output(self):
     results = run_python("""print 'hello!'""", "")
     self.assertEqual(results["stdout"], "hello!\n")
Ejemplo n.º 13
0
 def run_python_dedented(self, a, b):
     return run_python(textwrap.dedent(a), textwrap.dedent(b))