def test_get_words_two_sunny_words(self): manager = WordManager('(你好)我叫(保羅)', self.CEDICT_PATH); expected_words = [Word(0,1,['hello']), Word(4,5,['Paul'])]; words = manager.get_words(); self.assertEqual(2, len(words)); for i, word in enumerate(words): self.__assert_words_similar(expected_words[i], word);
def generate_infos(makemeahanzi_path, cedict_path, working_dir, characters): if (len(characters) == 0): raise GenException('No characters provided') manager = WordManager(characters, cedict_path) characters = manager.get_characters() words = manager.get_words() if len(characters) > MAX_INPUT_CHARACTERS: raise GenException('Maximum number of characters exceeded (' + \ str(len(characters)) + \ '/' + str(MAX_INPUT_CHARACTERS) + ')') generate_character_infos(working_dir, characters, makemeahanzi_path) generate_word_infos(working_dir, words)
def test_assure_valid_should_not_throw_no_parentheses(self): manager = WordManager('你好我叫保羅', self.CEDICT_PATH); manager.assure_valid();
def test_get_words_one_word_without_translation(self): manager = WordManager('(你好我叫保羅)', self.CEDICT_PATH); words = manager.get_words(); self.assertEqual(1, len(words)); self.assertEqual(0, len(words[0].definition));
def test_get_characters_with_parentheses(self): manager = WordManager('(你好)我叫(保羅)', self.CEDICT_PATH); self.assertEqual('你好我叫保羅', manager.get_characters());
def test_assure_valid_should_throw_word_too_long(self): manager = WordManager('(您那你好我叫保羅號號號)', self.CEDICT_PATH); with self.assertRaises(GenException): manager.assure_valid();
def test_assure_valid_should_throw_word_empty(self): manager = WordManager('(你)好我叫()', self.CEDICT_PATH); with self.assertRaises(GenException): manager.assure_valid();
def test_assure_valid_should_throw(self): manager = WordManager('(你(好)我叫(保羅)', self.CEDICT_PATH); with self.assertRaises(GenException): manager.assure_valid();
def test_assure_valid_should_not_throw(self): manager = WordManager('(你好)我叫(保羅)', self.CEDICT_PATH); manager.assure_valid();