コード例 #1
0
ファイル: main.py プロジェクト: bunyk/console_cramming
def cram(count):
    words_ids = q.select_most_hard_words_ids(count)
    for word_id in words_ids:
        variant_ids = q.get_translation_variants(word_id, 4)
        word, t = q.get_word_and_translation(word_id)
        variants = [q.get_word_and_translation(id)[1] for id in variant_ids]
        answer = choice_question(word, variants)
        answer_id = variant_ids[answer]
        q.record_answer(word_id, variant_ids[answer])
        if answer_id == word_id:
            print(_("Correct!"))
        else:
            print(_('Wrong! "{word}" is correctly translated as "{translation}"').format(word=word, translation=t))
コード例 #2
0
ファイル: test.py プロジェクト: bunyk/console_cramming
    def test_unicode_decode_in_main_py(self):
        '''
 File "main.py", line 51, in cram
    print(_('Wrong! "{word}" is correctly translated as "{translation}"').format(word=word, translation=t))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)
        '''
        a, = insert_words('я')
        word, t = q.get_word_and_translation(a)
        x  = _('Wrong! {word} is {translation}').format(word=word, translation=t)
        self.assertEqual(x, 'Wrong! я is я') 
コード例 #3
0
ファイル: test.py プロジェクト: bunyk/console_cramming
 def test_get_word_and_translation(self):
     for id in insert_words(*'abcd'):
         w, t = q.get_word_and_translation(id)
         self.assertEqual(w, t) # insert words works this way
         self.assertEqual(q.get_word_id(w), id)