From 91b4fe5e249d804f340bed031339c79a79bbf9ab Mon Sep 17 00:00:00 2001 From: Mark McCormick Date: Wed, 10 Jul 2024 11:35:37 +0100 Subject: [PATCH] add additional tests Signed-off-by: Mark McCormick --- enchant2.yaml | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/enchant2.yaml b/enchant2.yaml index 9c366d5584c..b1655b43946 100644 --- a/enchant2.yaml +++ b/enchant2.yaml @@ -59,10 +59,39 @@ test: environment: contents: packages: - - python3 + - enchant2-dev + - hunspell-dev + - hunspell-dictionaries-all - py3-pip + - python3 pipeline: - runs: | - pip install pyenchant - # this fails without the enchant libraries installed - python -c "import enchant" + pip3 install spello pyenchant + - runs: | + python -c ' + import enchant + from spello.model import SpellCorrectionModel + + d = enchant.Dict("en_US") + + word = "recieve" + assert not d.check(word), f"{word} should be misspelled" + suggestions = d.suggest(word) + expected_suggestions = ["receive", "relieve", "reverie"] + assert set(expected_suggestions).issubset(set(suggestions)), f"Suggestions for {word} are incorrect. Got: {suggestions}" + + sp = SpellCorrectionModel(language="en") + sp.train(["I want to play cricket", "this is a text corpus"]) + + sentence = "i wnt to plai kricket" + correction = sp.spell_correct(sentence) + expected_correction = { + "original_text": "i wnt to plai kricket", + "spell_corrected_text": "i want to play cricket", + "correction_dict": { + "wnt": "want", + "plai": "play", + "kricket": "cricket" + } + } + assert correction == expected_correction, f"Correction for {sentence} is incorrect. Expected: {expected_correction}, but got: {correction}"'