From f02d28f671d44e0d4e86d307e290c83fba57fd0f Mon Sep 17 00:00:00 2001 From: tligui_y Date: Tue, 29 Jul 2025 23:45:30 +0200 Subject: [PATCH] Add tests/test_utils_trinary.py --- tests/test_utils_trinary.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/test_utils_trinary.py diff --git a/tests/test_utils_trinary.py b/tests/test_utils_trinary.py new file mode 100644 index 00000000..f91fe6b7 --- /dev/null +++ b/tests/test_utils_trinary.py @@ -0,0 +1,34 @@ +import pytest +import sys +import os +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) +from slic.utils.trinary import * + +def test_check_trinary_valid_values(): + # These calls should not raise any exception and return None + assert check_trinary(True) is None + assert check_trinary(False) is None + assert check_trinary(None) is None + +def test_check_trinary_invalid_value(): + # These values are not allowed and should raise ValueError + with pytest.raises(ValueError, match=r"Trinary .+ not in"): + check_trinary("yes") + + with pytest.raises(ValueError): + check_trinary(0) + + with pytest.raises(ValueError): + check_trinary(1) + + with pytest.raises(ValueError): + check_trinary([]) + +def test_check_trinary_with_custom_allowed_values(): + # Valid custom values should pass without error + assert check_trinary("maybe", allowed_values=("yes", "no", "maybe")) is None + assert check_trinary("yes", allowed_values=("yes", "no", "maybe")) is None + + # Invalid custom value should raise ValueError + with pytest.raises(ValueError): + check_trinary("never", allowed_values=("yes", "no", "maybe"))