示例#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]])
示例#2
0
 def test_skips_empty_definition(self):
     word = str(fakes.fake_value())
     my_course = fakes.customize(fakes.course1, dictionary=[
         DictionaryItem(
             word=word,
             definition="",
             is_in_target_language=False
         ),
     ])
     with pytest.raises(ValueError):
         _define_word(my_course, word, is_in_target_language=False)
示例#3
0
 def test_skips_non_matching_definitions(self):
     word = str(fakes.fake_value())
     meaning = str(fakes.fake_value())
     is_in_target_language = fakes.fake_value()
     my_course = fakes.customize(fakes.course1, dictionary=[
         DictionaryItem(
             word="random shit",
             definition="random shit",
             is_in_target_language="random shit"
         ),
         DictionaryItem(
             word=word,
             definition=meaning,
             is_in_target_language=is_in_target_language
         ),
     ])
     assert _define_word(my_course, word, is_in_target_language=is_in_target_language) == {
         "word": word,
         "definition": meaning
     }
示例#4
0
 def test_doesnt_include_definition_with_different_is_in_target_language(self):
     word = str(fakes.fake_value())
     meaning = str(fakes.fake_value())
     is_in_target_language = fakes.fake_value()
     my_course = fakes.customize(fakes.course1, dictionary=[
         DictionaryItem(
             word=word,
             definition=meaning,
             is_in_target_language=False
         ),
     ])
     with pytest.raises(ValueError):
         _define_word(my_course, word,
                      is_in_target_language=is_in_target_language)
示例#5
0
def _load_dictionary(modules):
    """
    Generates a dictionary using every skill in every module that is
    passed in the argument
    """
    items = []
    for key, definition in _get_merged_dictionary_items(modules):
        word, is_in_target_language = key
        items.append(DictionaryItem(
            word=word,
            definition="\n".join(sorted(definition)),
            is_in_target_language=is_in_target_language,
        ))
    return items
示例#6
0
 def test_matches_definitions_in_a_case_insensitive_way(self):
     my_course = Course(
         **{
             **(fakes.course1._asdict()),
             "dictionary": [
                 DictionaryItem(
                     word="Easier",
                     definition="by a lot",
                     is_in_target_language=True
                 ),
             ]
         },
     )
     assert _define_word(my_course, "easier", is_in_target_language=True) == {
         "word": "easier",
         "definition": "by a lot"
     }
示例#7
0
 def test_doesnt_include_definition_with_different_word(self):
     word = str(fakes.fake_value())
     meaning = str(fakes.fake_value())
     is_in_target_language = fakes.fake_value()
     my_course = Course(
         **{
             **(fakes.course1._asdict()),
             "dictionary": [
                 DictionaryItem(
                     word=word,
                     definition=meaning,
                     is_in_target_language=is_in_target_language
                 ),
             ]
         },
     )
     with pytest.raises(ValueError):
         _define_word(my_course, "asd",
                      is_in_target_language=is_in_target_language)
示例#8
0
 def test_normalizes_words(self):
     word = str(fakes.fake_value())
     meaning = str(fakes.fake_value())
     is_in_target_language = fakes.fake_value()
     my_course = Course(
         **{
             **(fakes.course1._asdict()),
             "dictionary": [
                 DictionaryItem(
                     word=word,
                     definition=meaning,
                     is_in_target_language=is_in_target_language
                 ),
             ]
         },
     )
     assert _define_word(my_course, word + ",", is_in_target_language=is_in_target_language) == {
         "word": word + ",",
         "definition": meaning
     }
示例#9
0
def test_load_dictionary_includes_reverse_word_from_new_word(module_with_word):
    _, in_source_language, in_target_language = module_with_word
    dict_item = DictionaryItem(word=in_target_language[0],
                               definition=in_source_language[0],
                               is_in_target_language=True)
    assert dict_item in _load_dictionary([module_with_word[0]])
示例#10
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 == [
        'Ç', 'é', 'â', 'ê', 'î', 'ô', 'û', 'à', 'è', 'ù', 'ë', 'ï', 'ü'
    ]
示例#11
0
from librelingo_types import Course
from librelingo_types import Module
from librelingo_types import Skill
from librelingo_types import Phrase
from librelingo_types import Word
from librelingo_types import License
from librelingo_types import Language
from librelingo_types import DictionaryItem

challenge1 = "challenge1"
challenge2 = "challenge2"
challenge3 = "challenge3"
challenge4 = "challenge4"

fake_dictionary = [
    DictionaryItem("foo", "barrus", False),
    DictionaryItem("bar", "furrrr", False),
    DictionaryItem("foous", "lipsum", True),
    DictionaryItem("barus", "aaa", True),
    DictionaryItem("apple", "red fruit", False),
    DictionaryItem("john", "red fruit", False),
    DictionaryItem("smith", "red fruit", False),
    DictionaryItem("lorem", "red fruit", True),
    DictionaryItem("ipsum", "red fruit", True),
]

phrase1 = Phrase(
    in_target_language=["foous barus"],
    in_source_language=["foo bar"],
)