Spaces:
Runtime error
Runtime error
File size: 966 Bytes
2b4b6d8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | from amo.evaluation import evaluate_python
TESTS = '''
import unittest
from solution import add
class TestAdd(unittest.TestCase):
def test_add(self):
self.assertEqual(add(2, 3), 5)
'''
def test_valid_code_passes():
result = evaluate_python("def add(a, b):\n return a + b\n", TESTS)
assert result.passed
assert 80 <= result.score <= 100
def test_wrong_code_fails_tests():
result = evaluate_python("def add(a, b):\n return a - b\n", TESTS)
assert not result.passed
def test_blocked_import_is_rejected():
result = evaluate_python("import os\ndef add(a, b):\n return a + b", TESTS)
assert not result.policy_ok
def test_empty_tests_dont_pass():
result = evaluate_python("def add(a, b): return a + b", "")
assert not result.passed
def test_unittest_mock_import_is_rejected():
result = evaluate_python("from unittest import mock\ndef add(a, b): return a + b", TESTS)
assert not result.policy_ok
|