@@ -59,6 +59,34 @@ def test_spellcheck_en_gb():
5959 tool .disable_spellchecking ()
6060 assert tool .correct (s ) == "Wat is wrong with the spll chker"
6161
62+ def test_session_only_new_spellings ():
63+ import os
64+ import hashlib
65+ import language_tool_python
66+ library_path = language_tool_python .utils .get_language_tool_directory ()
67+ spelling_file_path = os .path .join (library_path , "org/languagetool/resource/en/hunspell/spelling.txt" )
68+ with open (spelling_file_path , 'r' ) as spelling_file :
69+ initial_spelling_file_contents = spelling_file .read ()
70+ initial_checksum = hashlib .sha256 (initial_spelling_file_contents .encode ())
71+
72+ new_spellings = ["word1" , "word2" , "word3" ]
73+ with language_tool_python .LanguageTool ('en-US' , newSpellings = new_spellings ) as tool :
74+ tool .new_spellings_only_current_session = True
75+ tool .enabled_rules_only = True
76+ tool .enabled_rules = {'MORFOLOGIK_RULE_EN_US' }
77+ matches = tool .check (" " .join (new_spellings ))
78+
79+ with open (spelling_file_path , 'r' ) as spelling_file :
80+ subsequent_spelling_file_contents = spelling_file .read ()
81+ subsequent_checksum = hashlib .sha256 (subsequent_spelling_file_contents .encode ())
82+
83+ if initial_checksum != subsequent_checksum :
84+ with open (spelling_file_path , 'w' ) as spelling_file :
85+ spelling_file .write (initial_spelling_file_contents )
86+
87+ assert not matches
88+ assert initial_checksum .hexdigest () == subsequent_checksum .hexdigest ()
89+
6290def test_debug_mode ():
6391 from language_tool_python .server import DEBUG_MODE
6492 assert DEBUG_MODE is False
0 commit comments