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
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
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
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 result.dictionary == [ DictionaryItem("the man", ["l'homme"], False), DictionaryItem("l'homme", ["the man"], True), DictionaryItem("the woman", ["la femme"], False), DictionaryItem("la femme", ["the woman"], 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, ) 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", "L'homme dit salut"], 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 == [ 'Ç', 'é', 'â', 'ê', 'î', 'ô', 'û', 'à', 'è', 'ù', 'ë', 'ï', 'ü' ]
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]])
def load_skill(path): data = load_yaml(path) skill = data["Skill"] words = data["New words"] phrases = data["Phrases"] return Skill(name=skill["Name"], id=skill["Id"], words=convert_words(words), phrases=convert_phrases(phrases), image_set=skill["Thumbnails"])
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
def load_skill(path, course): try: data = load_yaml(path) 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 [], )
in_source_language=["foo"], 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"]) skillWithPhrase = Skill(name="Masculine", id=3, phrases=[phrase2], words=[], image_set=["man1", "man2", "boy1"]) skillWithWord = Skill(name="Masculine", id=3, phrases=[], words=[word1], image_set=["man1", "man2", "boy1"])
def test_load_dictionary_handles_multiple_skills_per_module(module_with_word): module_with_word[0].skills.append(Skill("", "", [ get_fake_word()[0] ], [], [])) assert len(load_dictionary([module_with_word[0]])) == 4