예제 #1
0
파일: test_run.py 프로젝트: nedbat/choosy
 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"])
예제 #2
0
파일: test_run.py 프로젝트: sembug/choosy
 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'])
예제 #3
0
파일: test_run.py 프로젝트: nedbat/choosy
 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:])
예제 #4
0
파일: test_run.py 프로젝트: nedbat/choosy
 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"])
예제 #5
0
파일: test_run.py 프로젝트: nedbat/choosy
 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"])
예제 #6
0
파일: test_run.py 프로젝트: sembug/choosy
 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:])
예제 #7
0
파일: test_run.py 프로젝트: sembug/choosy
 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'])
예제 #8
0
파일: test_run.py 프로젝트: sembug/choosy
 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'])
예제 #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")
예제 #10
0
파일: test_run.py 프로젝트: sembug/choosy
 def test_output(self):
     results = run_python("""print 'hello!'""", "")
     self.assertEqual(results['stdout'], "hello!\n")
예제 #11
0
파일: test_run.py 프로젝트: sembug/choosy
 def run_python_dedented(self, a, b):
     return run_python(textwrap.dedent(a), textwrap.dedent(b))
예제 #12
0
파일: test_run.py 프로젝트: nedbat/choosy
 def test_output(self):
     results = run_python("""print 'hello!'""", "")
     self.assertEqual(results["stdout"], "hello!\n")
예제 #13
0
파일: test_run.py 프로젝트: nedbat/choosy
 def run_python_dedented(self, a, b):
     return run_python(textwrap.dedent(a), textwrap.dedent(b))