Skip to content

Commit 469ff11

Browse files
committed
test: Add version checking edge case tests
Added 4 comprehensive tests to test_tmux_cmd.py covering edge cases: - test_has_minimum_version_raises_on_old_version() - Verifies exception raising - test_has_minimum_version_returns_false_without_raising() - Tests raises=False - test_version_comparison_boundary_conditions() - Tests exact boundaries - test_version_comparison_with_minimum_version() - Tests against TMUX_MIN_VERSION Uses unittest.mock.AsyncMock to simulate old tmux versions for error testing. Result: 4 passed in 0.06s
1 parent 07ab454 commit 469ff11

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/asyncio/test_tmux_cmd.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,67 @@ async def test_tmux_cmd_async_pane_operations(async_server: Server) -> None:
373373
)
374374
assert new_pane_id in result.stdout
375375
assert len(result.stdout) >= 2 # At least 2 panes now
376+
377+
378+
@pytest.mark.asyncio
379+
async def test_has_minimum_version_raises_on_old_version() -> None:
380+
"""Test has_minimum_version raises exception for old tmux version."""
381+
from libtmux import exc
382+
from libtmux._compat import LooseVersion
383+
from unittest.mock import AsyncMock, patch
384+
385+
# Mock get_version to return old version (below minimum)
386+
mock_old_version = AsyncMock(return_value=LooseVersion("1.0"))
387+
388+
with patch("libtmux.common_async.get_version", mock_old_version):
389+
# Should raise VersionTooLow exception
390+
with pytest.raises(exc.VersionTooLow, match="libtmux only supports tmux"):
391+
await has_minimum_version(raises=True)
392+
393+
394+
@pytest.mark.asyncio
395+
async def test_has_minimum_version_returns_false_without_raising() -> None:
396+
"""Test has_minimum_version returns False without raising when raises=False."""
397+
from libtmux._compat import LooseVersion
398+
from unittest.mock import AsyncMock, patch
399+
400+
# Mock get_version to return old version (below minimum)
401+
mock_old_version = AsyncMock(return_value=LooseVersion("1.0"))
402+
403+
with patch("libtmux.common_async.get_version", mock_old_version):
404+
# Should return False without raising
405+
result = await has_minimum_version(raises=False)
406+
assert result is False
407+
408+
409+
@pytest.mark.asyncio
410+
async def test_version_comparison_boundary_conditions() -> None:
411+
"""Test version comparison functions at exact boundaries."""
412+
# Get actual current version
413+
current_version = await get_version()
414+
current_version_str = str(current_version)
415+
416+
# Test exact match scenarios
417+
assert await has_version(current_version_str) is True
418+
assert await has_gte_version(current_version_str) is True
419+
assert await has_lte_version(current_version_str) is True
420+
421+
# Test false scenarios
422+
assert await has_version("999.999") is False
423+
assert await has_gt_version("999.999") is False
424+
assert await has_lt_version("0.1") is False
425+
426+
427+
@pytest.mark.asyncio
428+
async def test_version_comparison_with_minimum_version() -> None:
429+
"""Test version comparisons against TMUX_MIN_VERSION."""
430+
from libtmux.common_async import TMUX_MIN_VERSION
431+
432+
# Current version should be >= minimum
433+
assert await has_gte_version(TMUX_MIN_VERSION) is True
434+
435+
# Should not be less than minimum
436+
assert await has_lt_version(TMUX_MIN_VERSION) is False
437+
438+
# has_minimum_version should pass
439+
assert await has_minimum_version(raises=False) is True

0 commit comments

Comments
 (0)