From 0bcec9f1f512526314a4c788a4a83cec985b7955 Mon Sep 17 00:00:00 2001 From: Aryaz Eghbali <64126826+AryazE@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:06:29 +0100 Subject: [PATCH] Fixed `ItemsCount` to raise `ValueError` (#203) --- sumy/utils.py | 2 +- tests/test_utils/test_utils.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sumy/utils.py b/sumy/utils.py index 7d0fc92..5eb8e32 100644 --- a/sumy/utils.py +++ b/sumy/utils.py @@ -97,7 +97,7 @@ def __call__(self, sequence): elif isinstance(self._value, (int, float)): return sequence[:int(self._value)] else: - ValueError("Unsuported value of items count '%s'." % self._value) + raise ValueError("Unsuported value of items count '%s'." % self._value) def __repr__(self): return to_string("" % self._value) diff --git a/tests/test_utils/test_utils.py b/tests/test_utils/test_utils.py index 9cf1966..cd30ccc 100644 --- a/tests/test_utils/test_utils.py +++ b/tests/test_utils/test_utils.py @@ -56,6 +56,13 @@ def test_unsupported_items_count(): count([]) +def test_items_count_with_unsupported_init_type(): + count = ItemsCount([]) + + with pytest.raises(ValueError): + count([]) + + def test_normalize_language_with_alpha_2_code(): assert normalize_language("fr") == "french" assert normalize_language("zh") == "chinese"