Files
slic/tests/test_string_utils.py
T
tligui_y 2a5cca6d79
Run Pytest / tests (push) Successful in 28s
Update tests/test_string_utils.py
2025-07-21 11:00:03 +02:00

55 lines
1.5 KiB
Python

import pytest
import os
import sys
import signal
import time
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from functions.string_utils import *
import warnings
def test_uppercase_normal():
# Normal string uppercase conversion
assert uppercase("hello") == "HELLO"
def test_uppercase_type_error():
# TypeError when input is None (invalid input)
uppercase(None)
def test_reverse_string():
# Tests string reversal correctness
assert reverse("abc") == "cba"
def test_warning_emit():
# Emits a Python UserWarning
warnings.warn("Test warning", UserWarning)
def test_unicode_decode_error():
# UnicodeDecodeError when decoding invalid byte sequence
b'\xff'.decode('utf-8')
def test_unicode_decode_surrogateescape():
# UnicodeDecodeError with strict error handler on invalid byte
b"\x80".decode("utf-8", errors="strict")
def test_syntax_warning():
# Emit a SyntaxWarning (Python will usually warn about questionable syntax)
warnings.warn("This is a syntax warning", SyntaxWarning)
@pytest.mark.xfail(reason="Expected failure: uppercase does not handle digits")
def test_xfail_uppercase_digits():
# Expected fail test because uppercase won't change digits
assert uppercase("abc123") == "ABC1234"
'''
def test_sigkill():
# Kill directly the program
os.kill(os.getpid(), signal.SIGKILL)
time.sleep(1)
'''
def test_keyboard_interrupt_direct():
# Directly raise KeyboardInterrupt exception
raise KeyboardInterrupt()