|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MetaCurriculumTest(MetaCurriculum): |
|
|
|
"""This class allows us to test MetaCurriculum objects without calling MetaCurriculum's |
|
|
|
__init__ function. |
|
|
|
"""This class allows us to test MetaCurriculum objects without calling |
|
|
|
MetaCurriculum's __init__ function. |
|
|
|
""" |
|
|
|
def __init__(self, brains_to_curriculums): |
|
|
|
self._brains_to_curriculums = brains_to_curriculums |
|
|
|
|
|
|
|
|
|
|
@pytest.fixture |
|
|
|
def progresses(): |
|
|
|
return {'TestBrain1' : 0.2, 'TestBrain2' : 0.3} |
|
|
|
return {'Brain1' : 0.2, 'Brain2' : 0.3} |
|
|
|
@patch('os.listdir', return_value=['TestBrain1.json', 'TestBrain2.json']) |
|
|
|
def test_init_meta_curriculum_happy_path(listdir, mock_curriculum_init, default_reset_parameters): |
|
|
|
meta_curriculum = MetaCurriculum('test-meta-curriculum/', default_reset_parameters) |
|
|
|
@patch('os.listdir', return_value=['Brain1.json', 'Brain2.json']) |
|
|
|
def test_init_meta_curriculum_happy_path(listdir, mock_curriculum_init, |
|
|
|
default_reset_parameters): |
|
|
|
meta_curriculum = MetaCurriculum('test/', default_reset_parameters) |
|
|
|
assert 'TestBrain1' in meta_curriculum.brains_to_curriculums |
|
|
|
assert 'TestBrain2' in meta_curriculum.brains_to_curriculums |
|
|
|
assert 'Brain1' in meta_curriculum.brains_to_curriculums |
|
|
|
assert 'Brain2' in meta_curriculum.brains_to_curriculums |
|
|
|
calls = [call('test-meta-curriculum/TestBrain1.json', default_reset_parameters), call('test-meta-curriculum/TestBrain2.json', default_reset_parameters)] |
|
|
|
calls = [call('test/Brain1.json', default_reset_parameters), |
|
|
|
call('test/Brain2.json', default_reset_parameters)] |
|
|
|
|
|
|
|
mock_curriculum_init.assert_has_calls(calls) |
|
|
|
|
|
|
|
|
|
|
def test_set_lesson_nums(test_brain_1_curriculum, test_brain_2_curriculum): |
|
|
|
meta_curriculum = MetaCurriculumTest({'TestBrain1' : test_brain_1_curriculum, 'TestBrain2' : test_brain_2_curriculum}) |
|
|
|
def test_set_lesson_nums(curriculum_a, curriculum_b): |
|
|
|
meta_curriculum = MetaCurriculumTest({'Brain1' : curriculum_a, |
|
|
|
'Brain2' : curriculum_b}) |
|
|
|
meta_curriculum.lesson_nums = {'TestBrain1' : 1, 'TestBrain2' : 3} |
|
|
|
meta_curriculum.lesson_nums = {'Brain1' : 1, 'Brain2' : 3} |
|
|
|
assert test_brain_1_curriculum.lesson_num == 1 |
|
|
|
assert test_brain_2_curriculum.lesson_num == 3 |
|
|
|
assert curriculum_a.lesson_num == 1 |
|
|
|
assert curriculum_b.lesson_num == 3 |
|
|
|
def test_increment_lessons(test_brain_1_curriculum, test_brain_2_curriculum, progresses): |
|
|
|
meta_curriculum = MetaCurriculumTest({'TestBrain1' : test_brain_1_curriculum, 'TestBrain2' : test_brain_2_curriculum}) |
|
|
|
def test_increment_lessons(curriculum_a, curriculum_b, progresses): |
|
|
|
meta_curriculum = MetaCurriculumTest({'Brain1' : curriculum_a, |
|
|
|
'Brain2' : curriculum_b}) |
|
|
|
test_brain_1_curriculum.increment_lesson.assert_called_with(0.2) |
|
|
|
test_brain_2_curriculum.increment_lesson.assert_called_with(0.3) |
|
|
|
curriculum_a.increment_lesson.assert_called_with(0.2) |
|
|
|
curriculum_b.increment_lesson.assert_called_with(0.3) |
|
|
|
def test_set_all_curriculums_to_lesson_num(test_brain_1_curriculum, test_brain_2_curriculum): |
|
|
|
meta_curriculum = MetaCurriculumTest({'TestBrain1' : test_brain_1_curriculum, 'TestBrain2' : test_brain_2_curriculum}) |
|
|
|
def test_set_all_curriculums_to_lesson_num(curriculum_a, curriculum_b): |
|
|
|
meta_curriculum = MetaCurriculumTest({'Brain1' : curriculum_a, |
|
|
|
'Brain2' : curriculum_b}) |
|
|
|
assert test_brain_1_curriculum.lesson_num == 2 |
|
|
|
assert test_brain_2_curriculum.lesson_num == 2 |
|
|
|
assert curriculum_a.lesson_num == 2 |
|
|
|
assert curriculum_b.lesson_num == 2 |
|
|
|
def test_get_config(test_brain_1_curriculum, test_brain_2_curriculum, default_reset_parameters, more_reset_parameters): |
|
|
|
test_brain_1_curriculum.get_config.return_value = default_reset_parameters |
|
|
|
test_brain_2_curriculum.get_config.return_value = default_reset_parameters |
|
|
|
meta_curriculum = MetaCurriculumTest({'TestBrain1' : test_brain_1_curriculum, 'TestBrain2' : test_brain_2_curriculum}) |
|
|
|
def test_get_config(curriculum_a, curriculum_b, default_reset_parameters, |
|
|
|
more_reset_parameters): |
|
|
|
curriculum_a.get_config.return_value = default_reset_parameters |
|
|
|
curriculum_b.get_config.return_value = default_reset_parameters |
|
|
|
meta_curriculum = MetaCurriculumTest({'Brain1' : curriculum_a, |
|
|
|
'Brain2' : curriculum_b}) |
|
|
|
test_brain_2_curriculum.get_config.return_value = more_reset_parameters |
|
|
|
curriculum_b.get_config.return_value = more_reset_parameters |
|
|
|
|
|
|
|
new_reset_parameters = dict(default_reset_parameters) |
|
|
|
new_reset_parameters.update(more_reset_parameters) |