Skip to content
Browse files

fix #55. where tmuxp would crash with letter version Version 0.1.7.

  • Loading branch information...
1 parent c8fd2b6 commit 87293f6d55b331baa57b98752a728ef0c25b8818 @tony committed
Showing with 92 additions and 7 deletions.
  1. +8 −0 CHANGES
  2. +1 −1 tmuxp/__init__.py
  3. +5 −0 tmuxp/testsuite/cli.py
  4. +60 −0 tmuxp/testsuite/util.py
  5. +18 −6 tmuxp/util.py
View
8 CHANGES
@@ -4,6 +4,14 @@ Changelog
Here you can find the recent changes to tmuxp.
+0.1.7
+-----
+
+- [cli] [test]: Fix `Issue #55`_ where tmuxp would crash with letter
+ numbers in version. Write tests.
+
+.. _Issue #55: https://github.com/tony/tmuxp/issues/55
+
0.1.6
-----
View
2 tmuxp/__init__.py
@@ -13,7 +13,7 @@
__title__ = 'tmuxp'
__package_name__ = 'tmuxp'
-__version__ = '0.1.6'
+__version__ = '0.1.7'
__description__ = 'Manage tmux sessions thru JSON, YAML configs. Features Python API'
__email__ = 'tony@git-pull.com'
__author__ = 'Tony Narlock'
View
5 tmuxp/testsuite/cli.py
@@ -25,6 +25,11 @@
TMUXP_DIR = os.path.join(os.path.dirname(__file__), '.tmuxp')
+class CLIVersion(TestCase):
+
+ pass
+
+
class StartupTest(TestCase):
"""test startup_cli()."""
View
60 tmuxp/testsuite/util.py
@@ -0,0 +1,60 @@
+# -*- coding: utf-8 -*-
+"""Tests for utility functions in tmux.
+
+tmuxp.tests.util
+~~~~~~~~~~~~~~~~
+
+"""
+
+from __future__ import absolute_import, division, print_function, \
+ with_statement, unicode_literals
+
+import random
+import logging
+import unittest
+
+from .. import exc
+from ..util import has_required_tmux_version
+
+from .helpers import TmuxTestCase
+
+logger = logging.getLogger(__name__)
+
+
+class TmuxVersionTest(TmuxTestCase):
+
+ """Test the :meth:`has_required_tmux_version`."""
+
+ def test_no_arg_uses_tmux_version(self):
+ result = has_required_tmux_version()
+ self.assertRegexpMatches(result, r'[0-9]\.[0-9]')
+
+ def test_ignores_letter_versions(self):
+ """Ignore letters such as 1.8b.
+
+ See ticket https://github.com/tony/tmuxp/issues/55.
+
+ In version 0.1.7 this is adjusted to use LooseVersion, in order to
+ allow letters.
+
+ """
+ result = has_required_tmux_version('1.9a')
+ self.assertRegexpMatches(result, r'[0-9]\.[0-9]')
+
+ result = has_required_tmux_version('1.8a')
+ self.assertEqual(result, r'1.8')
+
+ def test_error_version_less_1_7(self):
+ with self.assertRaisesRegexp(exc.TmuxpException, 'tmuxp only supports'):
+ has_required_tmux_version('1.7')
+
+ with self.assertRaisesRegexp(exc.TmuxpException, 'tmuxp only supports'):
+ has_required_tmux_version('1.6a')
+
+ has_required_tmux_version('1.9a')
+
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TmuxVersionTest))
+ return suite
View
24 tmuxp/util.py
@@ -11,6 +11,7 @@
import unittest
import collections
import subprocess
+import re
import os
import sys
import logging
@@ -263,14 +264,25 @@ def is_version(version):
return StrictVersion(installed_version) == StrictVersion(version)
-def has_required_tmux_version():
- """Return if tmux meets version requirement. Version >1.8 or above."""
- proc = tmux('-V')
+def has_required_tmux_version(version=None):
+ """Return if tmux meets version requirement. Version >1.8 or above.
- if proc.stderr:
- raise exc.TmuxpException(proc.stderr)
+ :versionchanged: 0.1.7
+ Versions will now remove trailing letters per `Issue 55`_.
+
+ .. _Issue 55: https://github.com/tony/tmuxp/issues/55.
+
+ """
+
+ if not version:
+ proc = tmux('-V')
+
+ if proc.stderr:
+ raise exc.TmuxpException(proc.stderr)
+
+ version = proc.stdout[0].split('tmux ')[1]
- version = proc.stdout[0].split('tmux ')[1]
+ version = re.sub(r'[a-z]', '', version)
if StrictVersion(version) <= StrictVersion("1.7"):
raise exc.TmuxpException(

0 comments on commit 87293f6

Please sign in to comment.
Something went wrong with that request. Please try again.