Ejemplo n.º 1
0
def test_load_dictionary_includes_word_from_mini_dictionary(module_with_word):
    module, _, __ = module_with_word
    module.skills[0] = Skill(
        **{
            **module.skills[0]._asdict(), "dictionary": [("foo", ("bar",
                                                                  "baz"),
                                                          False)]
        })
    assert DictionaryItem("foo", "bar\nbaz",
                          False) in _load_dictionary([module_with_word[0]])
Ejemplo n.º 2
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
Ejemplo n.º 3
0
def _load_skill(path, course):
    try:
        data = _load_yaml(path)
        introduction = _load_introduction(str(path).replace(".yaml", ".md"))
        skill = data["Skill"]
        words = data["New words"]
        phrases = data["Phrases"]
    except TypeError:
        raise RuntimeError(
            'Skill file "{}" is empty or does not exist'.format(path))
    except KeyError as error:
        raise RuntimeError('Skill file "{}" needs to have a "{}" key'.format(
            path, error.args[0]))

    try:
        name = skill["Name"]
    except Exception:
        raise RuntimeError(
            'Skill file "{}" needs to have skill name'.format(path))

    try:
        skill_id = skill["Id"]
    except Exception:
        raise RuntimeError(
            'Skill file "{}" needs to have skill id'.format(path))

    try:
        phrases = _convert_phrases(phrases)
    except TypeError:
        raise RuntimeError(
            'Skill file "{}" has an invalid phrase'.format(path))

    try:
        words = _convert_words(words)
    except TypeError:
        raise RuntimeError('Skill file "{}" has an invalid word'.format(path))

    return Skill(
        name=name,
        id=skill_id,
        words=words,
        phrases=phrases,
        image_set=skill["Thumbnails"] if "Thumbnails" in skill else [],
        dictionary=list(
            _convert_mini_dictionary(data["Mini-dictionary"], course))
        if "Mini-dictionary" in data else [],
        introduction=introduction,
    )
Ejemplo n.º 4
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]], [], [], None)
    ])
    assert len(_load_dictionary([module_with_word[0], new_module])) == 2
Ejemplo n.º 5
0
def test_load_dictionary_handles_multiple_modules(module_with_word):
    new_module = Module("",
                        [Skill("", "", [get_fake_word()[0]], [], [], None)])
    assert len(_load_dictionary([module_with_word[0], new_module])) == 4
Ejemplo n.º 6
0
def test_load_dictionary_handles_multiple_skills_per_module(module_with_word):
    module_with_word[0].skills.append(
        Skill("", "", [get_fake_word()[0]], [], [], None))
    assert len(_load_dictionary([module_with_word[0]])) == 4
Ejemplo n.º 7
0
def module_with_word():
    word, in_source_language, in_target_language = get_fake_word()
    my_module = Module("", skills=[Skill("", "", [word], [], [], None)])

    return my_module, in_source_language, in_target_language
Ejemplo n.º 8
0
def test_load_course_output_matches_value(fs):
    fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures',
                                "fake_course")
    fs.add_real_directory(fixture_path)
    result = load_course(fixture_path)
    assert result.target_language == Language(name="French", code="fr")
    assert result.source_language == Language(name="English", code="en")
    assert result.license == License(name='CC BY 3.0',
                                     full_name='CC BY 3.0',
                                     link='https://www.example.com/license')
    assert set(result.dictionary) == set([
        DictionaryItem("the man", "l'homme", False),
        DictionaryItem("l'homme", "the man", True),
        DictionaryItem("the woman", "la femme", False),
        DictionaryItem("la femme", "the woman", True),
        DictionaryItem("dit", "says", True),
        DictionaryItem("bonjour", "hello\nhi", True),
        DictionaryItem("L'homme", "the man", True),
        DictionaryItem("says", "dit", False),
        DictionaryItem("hello", "bonjour\nsalut", False),
        DictionaryItem(word='woman',
                       definition='femme',
                       is_in_target_language=False),
        DictionaryItem(word='man',
                       definition='homme',
                       is_in_target_language=False),
        DictionaryItem(word='The',
                       definition='la\nle',
                       is_in_target_language=False),
        DictionaryItem(word='femme',
                       definition='woman',
                       is_in_target_language=True),
        DictionaryItem(word='the',
                       definition='la\nle',
                       is_in_target_language=False),
        DictionaryItem(word='La', definition='the',
                       is_in_target_language=True),
    ])
    assert len(result.modules) == 1
    assert result.modules[0].title == "Basics"
    assert len(result.modules[0].skills) == 1
    assert result.modules[0].skills[0] == Skill(
        name="Hello",
        id=4,
        image_set=["people1", "woman1", "man1"],
        phrases=result.modules[0].skills[0].phrases,
        words=result.modules[0].skills[0].words,
        dictionary=result.modules[0].skills[0].dictionary,
    )
    assert result.modules[0].skills[0].phrases == [
        Phrase(
            in_target_language=['La femme dit bonjour', 'la femme dit salut'],
            in_source_language=['The woman says hello', 'The woman says hi']),
        Phrase(in_target_language=["L'homme dit bonjour", "true"],
               in_source_language=['The man says hello', 'The man says hi'])
    ]

    assert result.modules[0].skills[0].words == [
        Word(in_target_language=["l'homme"],
             in_source_language=['the man'],
             pictures=['man1', 'man2', 'man3']),
        Word(in_target_language=['la femme', 'la dame'],
             in_source_language=['the woman', 'the female'],
             pictures=None)
    ]
    assert result.special_characters == [
        'Ç', 'é', 'â', 'ê', 'î', 'ô', 'û', 'à', 'è', 'ù', 'ë', 'ï', 'ü'
    ]
Ejemplo n.º 9
0
             pictures=['foo', 'bar', 'baz'])

license1 = License(name="foo", full_name="foo bar license", link=None)

license2 = License(name="lorem",
                   full_name="ipsum lorem license",
                   link="https://example.com/lipsum_license")

word2 = Word(in_target_language=["apfel"],
             in_source_language=["apple"],
             pictures=['1', '2', '3'])

emptySkill = Skill(
    name="Neuter",
    id=3,
    words=[],
    phrases=[],
    image_set=["foo1", "bar1", "bar2"],
    dictionary=fake_dictionary,
)

skillWithPhrase = Skill(
    name="Masculine",
    id=3,
    phrases=[phrase2],
    words=[],
    image_set=["man1", "man2", "boy1"],
    dictionary=fake_dictionary,
)

skillWithWord = Skill(
    name="Masculine",