Skip to content

Commit cd6122f

Browse files
committed
add test_has_lt_version and test_has_gt_version
1 parent 1ccf09f commit cd6122f

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

doc/api.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ Internals
6969

7070
.. automethod:: libtmux.common.has_gt_version
7171

72+
.. automethod:: libtmux.common.has_gte_version
73+
7274
.. automethod:: libtmux.common.has_lt_version
7375

76+
.. automethod:: libtmux.common.has_lte_version
77+
7478
.. automethod:: libtmux.common.has_minimum_tmux_version
7579

7680
.. automethod:: libtmux.common.handle_option_error

libtmux/common.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,31 @@ def has_gt_version(min_version):
441441
:returns: True if version above min_version
442442
:rtype: bool
443443
"""
444+
return get_version() > LooseVersion(min_version)
445+
446+
447+
def has_gte_version(min_version):
448+
"""Return True if tmux version greater or equal to minimum.
449+
450+
:param min_version: version, e.g. '1.8'
451+
:type min_version: string
452+
:returns: True if version above or equal to min_version
453+
:rtype: bool
454+
"""
444455
return get_version() >= LooseVersion(min_version)
445456

446457

458+
def has_lte_version(max_version):
459+
"""Return True if tmux version less or equal to minimum.
460+
461+
:param max_version: version, e.g. '1.8'
462+
:type max_version: string
463+
:returns: True if version below or equal to max_version
464+
:rtype: bool
465+
"""
466+
return get_version() <= LooseVersion(max_version)
467+
468+
447469
def has_lt_version(max_version):
448470
"""Return True if tmux version less than minimum.
449471
@@ -452,7 +474,7 @@ def has_lt_version(max_version):
452474
:returns: True if version below max_version
453475
:rtype: bool
454476
"""
455-
return get_version() <= LooseVersion(max_version)
477+
return get_version() < LooseVersion(max_version)
456478

457479

458480
def has_minimum_tmux_version(raises=True):

tests/test_common.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
from libtmux.common import (
1414
has_minimum_tmux_version, which, session_check_name, tmux_cmd,
15-
has_version, has_gt_version, has_lt_version, get_version
15+
has_version, has_gt_version, has_lt_version, get_version,
16+
has_gte_version, has_lte_version
1617
)
1718
from libtmux.exc import LibTmuxException, BadSessionName, TmuxCommandNotFound
1819

@@ -94,14 +95,35 @@ def test_has_version():
9495
def test_has_gt_version():
9596
assert has_gt_version('1.6')
9697
assert has_gt_version('1.6b')
98+
9799
assert not has_gt_version('4.0')
100+
assert not has_gt_version('4.0b')
101+
102+
103+
def test_has_gte_version():
104+
assert has_gte_version('1.6')
105+
assert has_gte_version('1.6b')
106+
assert has_gte_version(str(get_version()))
107+
108+
assert not has_gte_version('4.0')
109+
assert not has_gte_version('4.0b')
98110

99111

100112
def test_has_lt_version():
101113
assert has_lt_version('4.0a')
102114
assert has_lt_version('4.0')
103115

104116
assert not has_lt_version('1.7')
117+
assert not has_lt_version(str(get_version()))
118+
119+
120+
def test_has_lte_version():
121+
assert has_lte_version('4.0a')
122+
assert has_lte_version('4.0')
123+
assert has_lte_version(str(get_version()))
124+
125+
assert not has_lte_version('1.7')
126+
assert not has_lte_version('1.7b')
105127

106128

107129
def test_which_no_bin_found():

0 commit comments

Comments
 (0)