diff --git a/test/test_kiwipiepy.py b/test/test_kiwipiepy.py index 47033a6..be7f35e 100644 --- a/test/test_kiwipiepy.py +++ b/test/test_kiwipiepy.py @@ -1,6 +1,7 @@ import os import sys import re +import tempfile from kiwipiepy import Kiwi, TypoTransformer, basic_typos, MorphemeSet, sw_tokenizer, PretokenizedToken from kiwipiepy.utils import Stopwords @@ -38,6 +39,28 @@ def test_morpheme_set(): print(repr(ms)) assert len(ms) == 3 +def test_load_user_dictionary(): + kiwi = Kiwi() + try: + raised = False + kiwi.load_user_dictionary('non-existing-file.txt') + except OSError as e: + raised = True + print(e) + finally: + assert raised + + with tempfile.NamedTemporaryFile(mode='w', encoding='utf-8', delete=False) as f: + f.write('잘못된 포맷의 파일입니다\n') + try: + raised = False + kiwi.load_user_dictionary(f.name) + except ValueError as e: + raised = True + print(e) + finally: + assert raised + def test_blocklist(): kiwi = Kiwi() tokens = kiwi.tokenize("고마움을")