Example #1
0
def test_load_dictionary_handles_multiple_modules(module_with_word):
    new_module = Module("", [
        Skill("", "", [
            get_fake_word()[0]
        ], [], [])
    ])
    assert len(load_dictionary([module_with_word[0], new_module])) == 4
Example #2
0
def test_load_dictionary_includes_duplicate_words_only_once(module_with_word):
    new_module = Module("", [
        Skill("", "", [
            module_with_word[0].skills[0].words[0]
        ], [], [])
    ])
    assert len(load_dictionary([module_with_word[0], new_module])) == 2
Example #3
0
def module_with_word():
    word, in_source_language, in_target_language = get_fake_word()
    my_module = Module("", skills=[
        Skill("", "", [
            word
        ], [], [])
    ])

    return my_module, in_source_language, in_target_language
Example #4
0
def load_module(path):
    """
    Load a YAML module
    """
    data = load_yaml(Path(path) / "module.yaml")
    module = data["Module"]
    skills = data["Skills"]

    return Module(title=module["Name"], skills=load_skills(path, skills))
Example #5
0
 def test_exports_all_skills(self, export_skill):
     _, fake_skill_1 = get_fake_skill()
     _, fake_skill_2 = get_fake_skill()
     _, fake_skill_3 = get_fake_skill()
     fake_module_1 = Module(title="", skills=[
         fake_skill_1,
         fake_skill_2,
     ])
     fake_module_2 = Module(title="", skills=[
         fake_skill_3,
     ])
     fake_course = fakes.customize(fakes.course1,
                                   modules=[fake_module_1, fake_module_2])
     export_course_skills(self.export_path, fake_course)
     export_skill.assert_has_calls([
         call(self.export_path, fake_skill_1, fake_course, None),
         call(self.export_path, fake_skill_2, fake_course, None),
         call(self.export_path, fake_skill_3, fake_course, None),
     ],
                                   any_order=True)
Example #6
0
def test_load_dictionary_includes_duplicate_words_includes_multiple_definitions(
        module_with_word):
    random_new_word = get_fake_word()[0]
    existing_word = module_with_word[0].skills[0].words[0]
    duplicate_word = Word(
        in_source_language=existing_word.in_source_language,
        in_target_language=random_new_word.in_target_language,
        pictures=[])
    new_module = Module("", [Skill("", "", [duplicate_word], [], [], None)])
    definition = load_dictionary([module_with_word[0],
                                  new_module])[0].definition
    assert random_new_word.in_target_language[0] in definition and \
        existing_word.in_target_language[0] in definition
Example #7
0
def load_module(path, course):
    """
    Load a YAML module
    """
    filepath = Path(path) / "module.yaml"
    data = load_yaml(filepath)
    try:
        module = data["Module"]
        skills = data["Skills"]
    except TypeError:
        raise RuntimeError(
            'Module file "{}" is empty or does not exist'.format(filepath))
    except KeyError as error:
        raise RuntimeError('Module file "{}" needs to have a "{}" key'.format(
            filepath, error.args[0]))

    try:
        title = module["Name"]
    except Exception:
        raise RuntimeError(
            'Module file "{}" needs to have module name'.format(filepath))

    return Module(title=title, skills=load_skills(path, skills, course))
Example #8
0
courseEmpty = Course(target_language=language_1,
                     source_language=language_2,
                     special_characters=["ä", "ß"],
                     license=license1,
                     modules=[],
                     dictionary=[])

course1 = Course(target_language=language_1,
                 source_language=language_2,
                 special_characters=["ä", "ß"],
                 license=license1,
                 modules=[
                     Module(title="Basics",
                            skills=[
                                skills[0],
                                skills[1],
                                skills[2],
                            ]),
                     Module(title="Phrases", skills=[]),
                 ],
                 dictionary=[])

course2 = Course(target_language=language_2,
                 source_language=language_1,
                 special_characters=["ç", "ş"],
                 license=license2,
                 modules=[
                     Module(title="Animals", skills=[skills[3]]),
                 ],
                 dictionary=[])