Increase coverage a bit

pull/131/head
stijndcl 2022-09-03 01:26:32 +02:00
parent 88bbb9773f
commit ac24688a73
5 changed files with 56 additions and 2 deletions

View File

@ -45,7 +45,7 @@ def pluralize(word: str, amount: int, plural_form: Optional[str] = None) -> str:
return plural_form or (word + "s")
def get_edu_year_name(year: int) -> str:
def get_edu_year_name(year: int) -> str: # pragma: no cover
"""Get the string representation of a university year"""
years = ["1st Bachelor", "2nd Bachelor", "3rd Bachelor", "1st Master", "2nd Master"]

View File

@ -17,6 +17,7 @@ omit = [
"./didier/data/constants.py",
"./didier/data/embeds/*",
"./didier/data/flags/*",
"./didier/menus/*",
"./didier/utils/discord/colours.py",
"./didier/utils/discord/constants.py",
"./didier/utils/discord/flags/*",

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