Exemplo n.º 1
0
def test_game_iter_bad_index():
    bulk_update_dict = {}
    new_index, result = game_service.__game_iter__(1, -2, [Word(word="bad")],
                                                   bulk_update_dict)
    assert new_index == 1
    assert len(bulk_update_dict) == 0
    assert result == "You are trying to go beyond the index."
def parse_oxford_response_data(response, word_from_request) -> []:
    result = {}
    if response is None:
        return result.values()
    json_results = response['results'][0]['lexicalEntries']
    for word_definition in json_results:
        try:
            definition = [word_definition['entries'][0]['senses'][0]['definitions'][0]]
            word_type = word_definition['lexicalCategory']
            word = Word(word_from_request, definition, word_type)
            if word.word in result.keys():
                result.get(word.word).append_definition(definition)
            else:
                result[word.word] = word
        except KeyError:
            print('parse error for: ', word_from_request)
    parsed_result = []
    for value in result.values():
        parsed_result.append(value.prepare_for_quizlet())
    return parsed_result
Exemplo n.º 3
0
def test_game_iter_correct():
    bulk_update_dict = {}
    new_index, result = game_service.__game_iter__(1, -1, [Word(word="bad")],
                                                   bulk_update_dict)
    assert new_index == 0
    assert len(bulk_update_dict) == 1
Exemplo n.º 4
0
from updatewords.update import UpdateWord
from model.word import Word
word = Word()
word.setWord(input("请输入单词:\n"))
word.setTrans(input("请输入中文释义:\n"))
word.setExample(input("请输入例句:\n"))
ud = UpdateWord()
print(ud.updateAWord(word))