Beispiel #1
0
 def test_doesnt_include_chips_if_sentence_is_short(self):
     assert len(
         list(
             filter(
                 lambda x: x["type"] == "chips",
                 _get_phrase_challenges(
                     fakes.customize(
                         fakes.phrase1,
                         in_target_language=["foo"],
                         in_source_language=["bar"],
                     ), fakes.course1)))) == 0
Beispiel #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)
Beispiel #3
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)
Beispiel #4
0
 def test_assert_logs_correctly(self):
     with self.assertLogs("librelingo_json_export", level="INFO") as log:
         randomname1 = str(random.randint(0, 5000))
         randomname2 = str(random.randint(0, 5000))
         fake_course = fakes.customize(
             fakes.course1,
             target_language=Language(
                 name=randomname1,
                 code=""
             ),
             source_language=Language(
                 name=randomname2,
                 code=""
             )
         )
         _export_course_data(self.export_path, fake_course)
         assert log.output[0] == \
             "INFO:librelingo_json_export:Writing course '{}' for '{}' speakers".format(
                 randomname1, randomname2)
Beispiel #5
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
     }
Beispiel #6
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)
Beispiel #7
0
 def test_the_first_meaning_does_matter(self):
     x, y = "foo", "bar"
     z = str(fakes.fake_value())
     p1 = fakes.customize(fakes.phrase1, in_target_language=[x])
     p2 = fakes.customize(fakes.phrase1, in_target_language=[y])
     assert get_dumb_opaque_id(z, p1) != get_dumb_opaque_id(z, p2)
Beispiel #8
0
 def test_phrase_only_first_meaning_matters_2(self):
     x, y = "foo", "bar"
     z = str(fakes.fake_value())
     p1 = fakes.customize(fakes.phrase1, in_target_language=[x])
     p2 = fakes.customize(fakes.phrase1, in_target_language=[x, y])
     assert get_dumb_opaque_id(z, p1) == get_dumb_opaque_id(z, p2)
Beispiel #9
0
 def test_word_only_first_meaning_matters_1(self):
     x, y = "foo", "bar"
     z = str(fakes.fake_value())
     p1 = fakes.customize(fakes.word1, in_source_language=[x])
     p2 = fakes.customize(fakes.word1, in_source_language=[x, y])
     assert get_dumb_opaque_id(z, p1) == get_dumb_opaque_id(z, p2)
Beispiel #10
0
def get_fake_skill():
    randomname = str(random.randint(0, 5000))
    return randomname, fakes.customize(
        fakes.skillWithPhraseAndWord,
        name="Animals {}".format(randomname),
    )