Increase coverage a bit

This commit is contained in:
stijndcl 2022-09-03 01:26:32 +02:00
parent 88bbb9773f
commit ac24688a73
5 changed files with 56 additions and 2 deletions

View file

@ -0,0 +1,15 @@
import pytest
from didier.exceptions import NoMatch, expect
def test_expect_none_raises():
"""Test that expect() raises an error if the input entity is None"""
with pytest.raises(NoMatch):
expect(None, entity_type="", argument="")
def test_expect_not_none_returns():
"""Test that expect() returns the argument if it isn't None"""
arg = "Some input string"
assert expect(arg, entity_type="", argument="") == arg

View file

@ -1,4 +1,23 @@
from didier.utils.types.string import leading
from didier.utils.types.string import abbreviate, leading, pluralize
def test_abbreviate_under_max_length():
"""Test abbreviate() when the input text is shorter than the max length"""
text = "TEST STRING"
assert abbreviate(text, max_length=len(text)) == text
assert abbreviate(text, max_length=len(text) + 1) == text
def test_abbreviate_longer():
"""Test abbreviate() when the input text is longer than the max length"""
text = "TEST STRING"
assert abbreviate(text, max_length=7) == "TEST S…"
def test_abbreviate_whitespace():
"""Test abbreviate() when the max length would end on whitespace"""
text = "TEST STRING"
assert abbreviate(text, max_length=6) == "TEST…"
def test_leading():
@ -20,3 +39,22 @@ def test_leading_no_exact():
def test_leading_no_target_length():
"""Test leading() when target_length is None"""
assert leading("0", "05", target_length=None) == "005"
def test_pluralize_singular():
"""Test pluralize() when the word is singular"""
word = "word"
assert pluralize(word, amount=1, plural_form="whatever") == word
def test_pluralize_plural_default():
"""Test pluralize() for the default plural form (+s)"""
word = "word"
assert pluralize(word, amount=2) == "words"
def test_pluralize_custom_plural():
"""Test pluralize() when a custom plural form is provided"""
word = "word"
plural = "plural"
assert pluralize(word, amount=2, plural_form=plural) == plural