Skip to content

Commit 87293f6

Browse files
committed
fix #55. where tmuxp would crash with letter version Version 0.1.7.
1 parent c8fd2b6 commit 87293f6

File tree

5 files changed

+92
-7
lines changed

5 files changed

+92
-7
lines changed

CHANGES

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ Changelog
44

55
Here you can find the recent changes to tmuxp.
66

7+
0.1.7
8+
-----
9+
10+
- [cli] [test]: Fix `Issue #55`_ where tmuxp would crash with letter
11+
numbers in version. Write tests.
12+
13+
.. _Issue #55: https://github.com/tony/tmuxp/issues/55
14+
715
0.1.6
816
-----
917

tmuxp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
__title__ = 'tmuxp'
1515
__package_name__ = 'tmuxp'
16-
__version__ = '0.1.6'
16+
__version__ = '0.1.7'
1717
__description__ = 'Manage tmux sessions thru JSON, YAML configs. Features Python API'
1818
__email__ = 'tony@git-pull.com'
1919
__author__ = 'Tony Narlock'

tmuxp/testsuite/cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
TMUXP_DIR = os.path.join(os.path.dirname(__file__), '.tmuxp')
2626

2727

28+
class CLIVersion(TestCase):
29+
30+
pass
31+
32+
2833
class StartupTest(TestCase):
2934

3035
"""test startup_cli()."""

tmuxp/testsuite/util.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# -*- coding: utf-8 -*-
2+
"""Tests for utility functions in tmux.
3+
4+
tmuxp.tests.util
5+
~~~~~~~~~~~~~~~~
6+
7+
"""
8+
9+
from __future__ import absolute_import, division, print_function, \
10+
with_statement, unicode_literals
11+
12+
import random
13+
import logging
14+
import unittest
15+
16+
from .. import exc
17+
from ..util import has_required_tmux_version
18+
19+
from .helpers import TmuxTestCase
20+
21+
logger = logging.getLogger(__name__)
22+
23+
24+
class TmuxVersionTest(TmuxTestCase):
25+
26+
"""Test the :meth:`has_required_tmux_version`."""
27+
28+
def test_no_arg_uses_tmux_version(self):
29+
result = has_required_tmux_version()
30+
self.assertRegexpMatches(result, r'[0-9]\.[0-9]')
31+
32+
def test_ignores_letter_versions(self):
33+
"""Ignore letters such as 1.8b.
34+
35+
See ticket https://github.com/tony/tmuxp/issues/55.
36+
37+
In version 0.1.7 this is adjusted to use LooseVersion, in order to
38+
allow letters.
39+
40+
"""
41+
result = has_required_tmux_version('1.9a')
42+
self.assertRegexpMatches(result, r'[0-9]\.[0-9]')
43+
44+
result = has_required_tmux_version('1.8a')
45+
self.assertEqual(result, r'1.8')
46+
47+
def test_error_version_less_1_7(self):
48+
with self.assertRaisesRegexp(exc.TmuxpException, 'tmuxp only supports'):
49+
has_required_tmux_version('1.7')
50+
51+
with self.assertRaisesRegexp(exc.TmuxpException, 'tmuxp only supports'):
52+
has_required_tmux_version('1.6a')
53+
54+
has_required_tmux_version('1.9a')
55+
56+
57+
def suite():
58+
suite = unittest.TestSuite()
59+
suite.addTest(unittest.makeSuite(TmuxVersionTest))
60+
return suite

tmuxp/util.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import unittest
1212
import collections
1313
import subprocess
14+
import re
1415
import os
1516
import sys
1617
import logging
@@ -263,14 +264,25 @@ def is_version(version):
263264
return StrictVersion(installed_version) == StrictVersion(version)
264265

265266

266-
def has_required_tmux_version():
267-
"""Return if tmux meets version requirement. Version >1.8 or above."""
268-
proc = tmux('-V')
267+
def has_required_tmux_version(version=None):
268+
"""Return if tmux meets version requirement. Version >1.8 or above.
269269
270-
if proc.stderr:
271-
raise exc.TmuxpException(proc.stderr)
270+
:versionchanged: 0.1.7
271+
Versions will now remove trailing letters per `Issue 55`_.
272+
273+
.. _Issue 55: https://github.com/tony/tmuxp/issues/55.
274+
275+
"""
276+
277+
if not version:
278+
proc = tmux('-V')
279+
280+
if proc.stderr:
281+
raise exc.TmuxpException(proc.stderr)
282+
283+
version = proc.stdout[0].split('tmux ')[1]
272284

273-
version = proc.stdout[0].split('tmux ')[1]
285+
version = re.sub(r'[a-z]', '', version)
274286

275287
if StrictVersion(version) <= StrictVersion("1.7"):
276288
raise exc.TmuxpException(

0 commit comments

Comments
 (0)