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_calls_get_chips_with_correct_value(self, get_chips): fake_phrase = Phrase( in_target_language=[fakes.fake_value()], in_source_language=[""] ) get_chips_challenge(fake_phrase, fakes.course1) get_chips.assert_called_with(fake_phrase.in_target_language[0])
def convert_phrase(raw_phrase): """ Converts a YAML phrase definition into a Phrase() object """ return Phrase( in_target_language=solution_from_yaml(raw_phrase, "Phrase", "Alternative versions"), in_source_language=solution_from_yaml(raw_phrase, "Translation", "Alternative translations"), )
def convert_phrase(raw_phrase): """ Converts a YAML phrase definition into a Phrase() object """ try: return Phrase( in_target_language=solution_from_yaml(raw_phrase, "Phrase", "Alternative versions"), in_source_language=solution_from_yaml(raw_phrase, "Translation", "Alternative translations"), ) except KeyError: raise RuntimeError('Phrase "{}" needs to have a "Translation".'.format( raw_phrase["Phrase"]))
from collections import namedtuple from librelingo_tools.data_types import Course from librelingo_tools.data_types import Module from librelingo_tools.data_types import Skill from librelingo_tools.data_types import Phrase from librelingo_tools.data_types import Word from librelingo_tools.data_types import License from librelingo_tools.data_types import Language challenge1 = "challenge1" challenge2 = "challenge2" challenge3 = "challenge3" challenge4 = "challenge4" phrase1 = Phrase( in_target_language=["foous barus"], in_source_language=["foo bar"], ) phrase2 = Phrase( in_target_language=["lorem ipsum"], in_source_language=["john smith"], ) long_phrase = Phrase( in_target_language=["foous barus " * 5], in_source_language=["foo bar " * 6], ) phrase_with_alternatives = Phrase( in_target_language=["foous barus " * 2] + ["bar baz" * 2], in_source_language=["foo bar " * 2] + ["ad o" * 2],