From ac24688a734c5dc8f34af1f261e336cb1b70b2d7 Mon Sep 17 00:00:00 2001 From: stijndcl Date: Sat, 3 Sep 2022 01:26:32 +0200 Subject: [PATCH] Increase coverage a bit --- didier/utils/types/string.py | 2 +- pyproject.toml | 1 + tests/test_didier/test_exceptions/__init__.py | 0 .../test_exceptions/test_no_match.py | 15 +++++++ .../test_utils/test_types/test_string.py | 40 ++++++++++++++++++- 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 tests/test_didier/test_exceptions/__init__.py create mode 100644 tests/test_didier/test_exceptions/test_no_match.py diff --git a/didier/utils/types/string.py b/didier/utils/types/string.py index 3a26658..4e02573 100644 --- a/didier/utils/types/string.py +++ b/didier/utils/types/string.py @@ -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"] diff --git a/pyproject.toml b/pyproject.toml index dcb0d24..2b40c14 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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/*", diff --git a/tests/test_didier/test_exceptions/__init__.py b/tests/test_didier/test_exceptions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_didier/test_exceptions/test_no_match.py b/tests/test_didier/test_exceptions/test_no_match.py new file mode 100644 index 0000000..dc21917 --- /dev/null +++ b/tests/test_didier/test_exceptions/test_no_match.py @@ -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 diff --git a/tests/test_didier/test_utils/test_types/test_string.py b/tests/test_didier/test_utils/test_types/test_string.py index c3826df..6dc4edd 100644 --- a/tests/test_didier/test_utils/test_types/test_string.py +++ b/tests/test_didier/test_utils/test_types/test_string.py @@ -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