From f870a844956b65b224badd57eee4cc1515da3b05 Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Thu, 24 Jan 2019 19:53:44 -0500 Subject: [PATCH] Handle next-X.Y versions tmuxp currently crashes when used with tmux next-2.9 (the latest Homebrew release). ``` TypeError: '<' not supported between instances of 'str' and 'int' ``` This patch avoids the error by making `get_version()` strip the "next-" part of the version. closes tmux-python/tmuxp#449 --- libtmux/common.py | 2 +- tests/test_common.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libtmux/common.py b/libtmux/common.py index 98bed804c..5e0d2490f 100644 --- a/libtmux/common.py +++ b/libtmux/common.py @@ -471,7 +471,7 @@ def get_version(): if version == 'master': return LooseVersion('%s-master' % TMUX_MAX_VERSION) - version = re.sub(r'[a-z]', '', version) + version = re.sub(r'[a-z-]', '', version) return LooseVersion(version) diff --git a/tests/test_common.py b/tests/test_common.py index 123e549dc..ba022d835 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -45,6 +45,24 @@ class Hi(object): ), "Is the latest supported version with -master appended" +def test_allows_next_version(monkeypatch): + def mock_tmux_cmd(param): + class Hi(object): + stdout = ['tmux next-2.9'] + stderr = None + + return Hi() + + monkeypatch.setattr(libtmux.common, 'tmux_cmd', mock_tmux_cmd) + + assert has_minimum_version() + assert has_gte_version(TMUX_MIN_VERSION) + assert has_gt_version(TMUX_MAX_VERSION), "Greater than the max-supported version" + assert ( + '2.9' == get_version() + ) + + def test_get_version_openbsd(monkeypatch): def mock_tmux_cmd(param): class Hi(object):