Skip to content

Commit 1e31d9e

Browse files
committed
test: enhance RandomStrSequence testing coverage
- Add test_random_str_sequence_small_character_set to verify behavior with exactly 8 characters - Add test_random_str_sequence_insufficient_characters to verify proper error handling - Add test_logger_configured to verify logger configuration using caplog fixture - Improve assertion messages for better test diagnostics - Use pytest.LogCaptureFixture for proper logger testing
1 parent 1476875 commit 1e31d9e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/test/test_random.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,42 @@ def test_random_str_sequence_self_type() -> None:
266266
iter_result = iter(rng)
267267
assert isinstance(iter_result, RandomStrSequence)
268268
assert iter_result is rng
269+
270+
271+
def test_random_str_sequence_small_character_set() -> None:
272+
"""Test RandomStrSequence with a small character set."""
273+
# Using a small set forces it to use all characters
274+
small_chars = "abcdefgh" # Exactly 8 characters
275+
rng = RandomStrSequence(characters=small_chars)
276+
result = next(rng)
277+
278+
assert isinstance(result, str)
279+
assert len(result) == 8
280+
# Since it samples exactly 8 characters, all chars must be used
281+
assert sorted(result) == sorted(small_chars)
282+
283+
284+
def test_random_str_sequence_insufficient_characters() -> None:
285+
"""Test RandomStrSequence with too few characters."""
286+
# When fewer than 8 chars are provided, random.sample can't work
287+
tiny_chars = "abc" # Only 3 characters
288+
rng = RandomStrSequence(characters=tiny_chars)
289+
290+
# Should raise ValueError since random.sample(population, k)
291+
# requires k <= len(population)
292+
with pytest.raises(ValueError):
293+
next(rng)
294+
295+
296+
def test_logger_configured(caplog: pytest.LogCaptureFixture) -> None:
297+
"""Test that the logger in random.py is properly configured."""
298+
# Verify the logger is set up with the correct name
299+
assert logger.name == "libtmux.test.random"
300+
301+
# Test that the logger functions properly
302+
with caplog.at_level(logging.DEBUG):
303+
logger.debug("Test debug message")
304+
logger.info("Test info message")
305+
306+
assert "Test debug message" in caplog.text
307+
assert "Test info message" in caplog.text

0 commit comments

Comments
 (0)