Skip to content

Commit

Permalink
test: add tests for reverse_existence_check
Browse files Browse the repository at this point in the history
  • Loading branch information
Nytelife26 committed May 28, 2024
1 parent a0631ae commit 39b1662
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 54 deletions.
12 changes: 12 additions & 0 deletions proselint/checks/restricted/elementary.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
import proselint
from proselint.checks import CheckResult, reverse_existence_check

examples_pass = [
"A boy and his goat went to a farm.",
"I am tired.",
"Your body is made of water.",
]

examples_fail = [
"Cells make up your body.",
"I love clowns.",
"I hate cells and clowns.",
]

_CSV_PATH = "checks/restricted/elementary.csv"
with files(proselint).joinpath(_CSV_PATH).open("r") as data:
ELEMENTARY_WORDS = data.read().split()
Expand Down
12 changes: 12 additions & 0 deletions proselint/checks/restricted/top1000.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
import proselint
from proselint.checks import CheckResult, reverse_existence_check

examples_pass = [
"I am blonde.",
"I'm gonna listen to music tonight.",
"I will go to sleep because I have school.",
]

examples_fail = [
"I am tired.",
"I hate broccoli.",
"I am tired and hate broccoli.",
]

_CSV_PATH = "checks/restricted/top1000.csv"

with files(proselint).joinpath(_CSV_PATH).open("r") as data:
Expand Down
27 changes: 0 additions & 27 deletions tests/test_restricted_elementary.py

This file was deleted.

27 changes: 0 additions & 27 deletions tests/test_restricted_top1000.py

This file was deleted.

49 changes: 49 additions & 0 deletions tests/test_reverse_existence_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Test the reverse_existence_check function from proselint.checks"""
from proselint.checks import reverse_existence_check

def test_reverse_existence_check():
"""Basic smoke test to determine that reverse_existence_check is working."""
allowed = ["abc", "cab"]
err = "error message"
msg = "something else exists"
assert reverse_existence_check("abc cab abc abc", allowed, err, msg) == []
assert reverse_existence_check("easy breezy", allowed, err, msg) != []
assert err in reverse_existence_check("easy breezy", allowed, err, msg)[0]
assert msg in reverse_existence_check("easy breezy", allowed, err, msg)[0]

def test_reverse_existence_check_multiple_matches():
"""Test that multiple matches are found correctly."""
allowed = ["abc", "cab"]
err = "error message"
msg = "something exists"
assert len(reverse_existence_check("abc and abc are easy like cab", allowed, err, msg)) == 4
assert len(reverse_existence_check("ABC and abc are easy like cab CAB", allowed, err, msg, ignore_case=True)) == 4
assert len(reverse_existence_check("ABC and abc are easy like cab CAB", allowed, err, msg, ignore_case=False)) == 6
assert reverse_existence_check("abc cab abc cab", allowed, err, msg) == []

def test_reverse_existence_check_special_chars():
"""Test that matches with ' and - are found correctly."""
allowed = ["abc", "cab"]
err = "error message"
msg = "something exists"
assert len(reverse_existence_check("what's your go-to?", allowed, err, msg)) == 3
allowed = ["what's"]
assert len(reverse_existence_check("what's your go-to?", allowed, err, msg)) == 2
allowed = ["what's", "go-to"]
assert len(reverse_existence_check("what's your go-to?", allowed, err, msg)) == 1

def test_reverse_existence_check_no_digits():
"""Test that matches with digits are excluded correctly."""
allowed = ["abc", "cab"]
err = "error message"
msg = "something exists"
assert len(reverse_existence_check("abc cab 123 a5bc noway no7way", allowed, err, msg)) == 1
assert reverse_existence_check("abc cab 123 a5bc no7way", allowed, err, msg) == []

def test_reverse_existence_check_3_chars():
"""Test that matches are exclusively >=3 characters long."""
allowed = ["abc", "cab"]
err = "error message"
msg = "something exists"
assert len(reverse_existence_check("i am not me", allowed, err, msg)) == 1
assert reverse_existence_check("i am me", allowed, err, msg) == []

0 comments on commit 39b1662

Please sign in to comment.