def test_special_answer_is_correct(self):
     self.assertTrue(
         Exercise._is_correct_answer(answer=NoSolution,
                                     expected_answer=NoSolution))
     self.assertTrue(
         Exercise._is_correct_answer(answer=AnyNumber,
                                     expected_answer=AnyNumber))
 def test_special_answer_is_wrong(self):
     self.assertFalse(
         Exercise._is_correct_answer(answer=NoSolution,
                                     expected_answer=AnyNumber))
     self.assertFalse(
         Exercise._is_correct_answer(answer=AnyNumber,
                                     expected_answer=NoSolution))
     self.assertFalse(
         Exercise._is_correct_answer(answer=AnyNumber, expected_answer='4'))
     self.assertFalse(
         Exercise._is_correct_answer(answer='4', expected_answer=AnyNumber))
 def test_sympy_number_is_wrong(self):
     expected_a = '4'
     for a in [2, '2', '-4', '3.0', '4.008']:
         self.assertFalse(
             Exercise._is_correct_answer(answer=a,
                                         expected_answer=expected_a),
             msg='{} equal (or almost equal) to {}'.format(a, expected_a))
 def test_unsympifiable(self):
     for n in self.UNSYMPIFIABLE_EXPRESSIONS:
         self.assertFalse(
             Exercise._is_allowed_special_or_sympifiable_answer(
                 answer_val=n, allowed_answer_types=[NoSolution,
                                                     AnyNumber]),
             msg=n)
 def test_sympy_number_is_correct(self):
     expected_a = '4'
     for a in [4, '4', '+4', '4.0', '4.004']:
         self.assertTrue(Exercise._is_correct_answer(
             answer=a, expected_answer=expected_a),
                         msg='{} not equal (or almost equal) to {}'.format(
                             a, expected_a))
示例#6
0
async def test_get_result(runner):
    ex = Exercise('example_python')
    data = {'answer.py': 'get_max = lambda x: x[0]'}
    container_id = await runner.start_exercise_checking(ex, data)
    exit_code, stdout, stderr = await runner.get_results(container_id,
                                                         timeout=30)
    assert_that(exit_code, instance_of(int))
    assert_that(stdout, instance_of(bytes))
    assert_that(stderr, instance_of(bytes))
    containers = await runner.api.Container.list()
    assert_that(containers, not_(contains(has_properties(id=container_id))))
def test_list():
    exercises = Exercise.list()
    assert isinstance(exercises, list)
    names = [x.name for x in exercises]
    assert 'example_python' in names
    assert '__pycache__' not in names
 def test_NoSolution_invalid(self):
     self.assertFalse(
         Exercise._is_allowed_special_or_sympifiable_answer(
             answer_val=NoSolution, allowed_answer_types=[AnyNumber]))
 def test_NoSolution_valid(self):
     self.assertTrue(
         Exercise._is_allowed_special_or_sympifiable_answer(
             answer_val=NoSolution, allowed_answer_types=[NoSolution]))
 def test_AnyNumber_valid(self):
     self.assertTrue(
         Exercise._is_allowed_special_or_sympifiable_answer(
             answer_val=AnyNumber, allowed_answer_types=[AnyNumber]))
 def test_sympifiable(self):
     for n in self.SYMPIFIABLE_EXPRESSIONS:
         self.assertTrue(Exercise._is_allowed_special_or_sympifiable_answer(
             answer_val=n, allowed_answer_types=[sympy.Number]),
                         msg='{} type is: {}'.format(
                             n, _sympify_type(expr=n)))
def example_python():
    return Exercise('example_python')
def test_list():
    exercises = Exercise.list()
    assert isinstance(exercises, list)
    names = [x.name for x in exercises]
    assert 'example_python' in names
    assert '__pycache__' not in names
def example_sh():
    return Exercise('example_sh')
示例#15
0
async def test_start_exercise_checking(runner):
    ex = Exercise('example_python')
    data = {'answer.py': 'get_max = lambda x: x[0]'}
    container_id = await runner.start_exercise_checking(ex, data)
    assert container_id is not None