def test_review_a_word(self): # TODO I don't know how to test it. # SO, smoke testing. with session_scope() as session: session.query(Word).filter_by(word_name=mock_info.word_info['word_name']).delete() word_id = word_store.create( mock_info.word_info['word_name'], mock_info.word_info['ph'], mock_info.word_info['tran_means'], mock_info.word_info['mp3_url'], '', ) review_hander.review_a_word(word_id, 2) for i in range(3): review_hander.review_a_word(word_id, 5) with session_scope() as session: assert session.query(ReviewList).filter_by(word_id=word_id).first() is None review_list_store.add_word_in_list(word_id) review_hander.review_a_word(word_id, 5) with session_scope() as session: session.query(Mp3).filter_by(word_id=word_id).delete() session.query(ReviewList).filter_by(word_id=word_id).delete() session.query(Word).filter_by(id=word_id).delete()
def test_reduce_repeat_count(self): mock_word_info = mock_info.word_info with session_scope() as session: session.query(Word).filter_by( word_name=mock_word_info['word_name']).delete() word_obj = Word( word_name=mock_word_info['word_name'], ph=mock_word_info['ph'], ) session.add(word_obj) session.flush() word_id = word_obj.id review_list_store.del_word_in_list(word_id) review_list_store.add_word_in_list(word_id, new=False, repeat_count=2) review_list_store.reduce_repeat_count(word_id) with session_scope() as session: assert session.query(ReviewList).filter_by( word_id=word_id).first().repeat_count == 1 review_list_store.reduce_repeat_count(word_id) with session_scope() as session: assert session.query(ReviewList).filter_by( word_id=word_id).first() is None session.query(Mp3).delete() session.query(ReviewList).delete() session.query(Word).delete() session.query(OptimumFactorMatrix).delete()
def init_review_list(self): """put today' words need review in review list""" # TODO unit test if sys_info_store.get_review_list_time() != datetime.datetime.now().strftime("%Y-%m-%d"): with session_scope() as session: word_ids = word_factor_store.get_today_word_ids(session=session) for word_id in word_ids: review_list_store.add_word_in_list(word_id, session=session) sys_info_store.set_review_list_time(session=session) console_hander.msg("已添加{}个单词到今日学习计划".format(len(word_ids)))
def review_a_word(self, word_id, score): """Review a word; Change Word Factors""" w_type = review_list_store.get_word_type(word_id) repeat_count = 5 - score if score < 3 else 0 if w_type is ReviewList.WordType.repeat: if not repeat_count: review_list_store.reduce_repeat_count(word_id) else: IF, EF, OF_matrix = self.get_factors(word_id, score) review_list_store.del_word_in_list(word_id) if repeat_count: # score < 3, need repeat some time to remember the word. review_list_store.add_word_in_list(word_id, repeat=True, repeat_count=repeat_count) # change EF, change OF_matrix, change next_review_day next_review_day = datetime.datetime.now() + datetime.timedelta(days=IF) word_factor_store.set_EF(word_id, EF) word_factor_store.set_OF_matrix(word_id, OF_matrix) word_factor_store.set_next_review_time(word_id, next_review_day) return 0, "success", {}
def test_get_word_type(self): mock_word_info = mock_info.word_info with session_scope() as session: session.query(Word).filter_by( word_name=mock_word_info['word_name']).delete() word_obj = Word( word_name=mock_word_info['word_name'], ph=mock_word_info['ph'], ) session.add(word_obj) session.flush() word_id = word_obj.id review_list_store.add_word_in_list(word_id) assert review_list_store.get_word_type( word_id) is ReviewList.WordType.review with session_scope() as session: session.query(Mp3).filter_by(word_id=word_id).delete() session.query(ReviewList).filter_by(word_id=word_id).delete() session.query(Word).filter_by(id=word_id).delete()
def test_add_word_in_list(self): mock_word_info = mock_info.word_info with session_scope() as session: session.query(Word).filter_by( word_name=mock_word_info['word_name']).delete() word_obj = Word( word_name=mock_word_info['word_name'], ph=mock_word_info['ph'], ) session.add(word_obj) session.flush() word_id = word_obj.id review_list_store.add_word_in_list(word_id, repeat_count=5) with session_scope() as session: assert session.query(ReviewList).filter_by( word_id=word_id).first().repeat_count == 5 with session_scope() as session: session.query(Mp3).filter_by(word_id=word_id).delete() session.query(ReviewList).filter_by(word_id=word_id).delete() session.query(Word).filter_by(id=word_id).delete()